|
37 | 37 | import logging
|
38 | 38 | import re
|
39 | 39 | import json
|
| 40 | +from os.path import expanduser |
| 41 | + |
| 42 | +logger = logging.getLogger(__name__) |
| 43 | + |
| 44 | +__defaultBaseDirs = [ expanduser('~') + '/.config/apt-repos', expanduser('~') + '/.apt-repos', '/etc/apt-repos' ] |
| 45 | +__defaultCacheDir = expanduser('~') + '/.cache/apt-repos' |
| 46 | +__aptConf = __defaultCacheDir + "/apt.conf" |
| 47 | +if not os.path.isdir(__defaultCacheDir): |
| 48 | + os.makedirs(__defaultCacheDir, exist_ok=True) |
| 49 | + with open(__aptConf, "w") as fh: |
| 50 | + print('Dir "{}";'.format(__defaultCacheDir), file=fh) |
| 51 | +os.environ["APT_CONFIG"] = __aptConf |
| 52 | +__baseDirs = __defaultBaseDirs |
| 53 | +__cacheDir = __defaultCacheDir |
40 | 54 |
|
41 | 55 | import apt_pkg
|
42 | 56 | import apt.progress
|
43 | 57 | import functools
|
44 | 58 |
|
45 |
| -from os.path import expanduser |
46 | 59 | from enum import Enum
|
47 | 60 |
|
48 | 61 | from apt_repos.RepoSuite import RepoSuite
|
49 | 62 | from apt_repos.PackageField import PackageField
|
50 | 63 | from apt_repos.QueryResult import QueryResult
|
51 | 64 | from apt_repos.Repository import Repository
|
52 | 65 |
|
53 |
| -logger = logging.getLogger(__name__) |
54 |
| - |
55 |
| -__baseDirs = [ expanduser('~') + '/.config/apt-repos', expanduser('~') + '/.apt-repos', '/etc/apt-repos' ] |
56 |
| -__cacheDir = __baseDirs[0] + '/.apt-repos_cache' |
57 |
| - |
58 | 66 |
|
59 | 67 | import contextlib
|
60 | 68 | @contextlib.contextmanager
|
@@ -124,14 +132,22 @@ def setAptReposBaseDir(dir):
|
124 | 132 | files and for the apt-repos cache that will be created in this directory
|
125 | 133 | named <dir>/.apt-repos_cache.
|
126 | 134 | '''
|
| 135 | + global __defaultBaseDirs |
| 136 | + global __defaultCacheDir |
127 | 137 | global __baseDirs
|
128 | 138 | global __cacheDir
|
129 | 139 | if(os.path.isdir(dir)):
|
130 |
| - logger.info("Using basedir '{}'".format(os.path.relpath(dir))) |
131 |
| - __baseDirs = [ os.path.realpath(dir) ] |
132 |
| - __cacheDir = __baseDirs[0] + '/.apt-repos_cache' |
| 140 | + realDir = os.path.relpath(dir) |
| 141 | + logger.info("Using basedir '{}'".format(realDir)) |
| 142 | + __baseDirs = [ realDir ] |
| 143 | + if realDir in __defaultBaseDirs: |
| 144 | + __cacheDir = __defaultCacheDir |
| 145 | + else: |
| 146 | + __cacheDir = realDir + '/.apt-repos_cache' |
133 | 147 | else:
|
134 | 148 | raise Exception("base-directory doesn't exist: " + dir)
|
| 149 | + if not os.path.isdir(__cacheDir): |
| 150 | + os.makedirs(__cacheDir, exist_ok=True) |
135 | 151 |
|
136 | 152 |
|
137 | 153 | def __filenameWithoutPrefix(item):
|
|
0 commit comments