summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2022-02-16 11:43:43 -0500
committerbill-auger <mr.j.spam.me@gmail.com>2022-02-16 12:11:28 -0500
commit3e75394a049ad4b300461a7ff546e7e512ea3aaf (patch)
tree36967f8e89761230b39710d30e63222a7ea9139b
parent69f176cf58cdcbe9472bb5714d556455b7935a9e (diff)
ensure that 'pkgbuilds' and 'pkgentries' are loaded before 'pkgfiles'wip-2022-02-15
-rw-r--r--parabola_repolint/repocache.py74
1 files changed, 48 insertions, 26 deletions
diff --git a/parabola_repolint/repocache.py b/parabola_repolint/repocache.py
index 09893da..911c1b4 100644
--- a/parabola_repolint/repocache.py
+++ b/parabola_repolint/repocache.py
@@ -678,51 +678,39 @@ class Repo():
def __init__(self, name, have_abs_tree=False):
''' constructor '''
- # NOTE: the order of Repo instance var initialization is critical
- # _load_pkgbuilds and _load_pkgentries must be called before _load_pkgfiles;
- # because PkgFile initialization (in _load_pkgfiles) assumes this object's
- # _pkgbuild_cache and _pkgentries_cache to be populated prior.
self._name = name
self._pkgbuild_dir = os.path.join(RepoCache.ABSLIBRE_DIR, name) if have_abs_tree else None
self._pkgentries_dir = os.path.join(RepoCache.PKGENTRIES_DIR, name)
self._pkgfiles_dir = os.path.join(RepoCache.PKGFILES_DIR, name)
self._mirror_dir = os.path.join(RepoCache.MIRROR_DIR, name)
+ # initialize pkgbuilds cache (per abslibre)
self._pkgbuilds = []
self._pkgbuild_cache = {}
- if self._pkgbuild_dir is not None:
- self._load_pkgbuilds()
- logging.info('%s pkgbuilds: %i', name, len(self._pkgbuilds))
- with open(os.path.join(self._pkgbuild_dir, '.pkgbuilds'), 'w') as out:
- out.write(json.dumps(self._pkgbuilds, indent=4, sort_keys=True, default=str))
- with open(os.path.join(self._pkgbuild_dir, '.pkgbuild_cache'), 'w') as out:
- out.write(json.dumps(self._pkgbuild_cache, indent=4, sort_keys=True, default=str))
+ self._load_pkgbuilds()
+ # initialize pkgentries cache (per found repo.db files)
self._pkgentries = []
self._pkgentries_cache = {}
self._provides_cache = {}
self._load_pkgentries()
- logging.info('%s pkgentries: %i', name, len(self._pkgentries))
- with open(os.path.join(self._pkgentries_dir, '.pkgentries'), 'w') as out:
- out.write(json.dumps(self._pkgentries, indent=4, sort_keys=True, default=str))
- with open(os.path.join(self._pkgentries_dir, '.pkgentries_cache'), 'w') as out:
- out.write(json.dumps(self._pkgentries_cache, indent=4, sort_keys=True, default=str))
- with open(os.path.join(self._pkgentries_dir, '.provides_cache'), 'w') as out:
- out.write(json.dumps(self._provides_cache, indent=4, sort_keys=True, default=str))
-
+ # initialize pkgfile cache (per found pool files)
+ # TODO: this does not actually check the pool, but the symlinks forest
+ # it is not capable of distinguishing missing symlinks from missing files,
+ # nor identifying pool files with no corresponding symlinks
+ # some files in the pool could be usedless cruft,
+ # so the latter is not the same case as a missing symlink,
+ # because the implication only holds from symlinks to files in the pool
+ # actually, the semantics of this class is more like 'PkgLinks',
+ # because it represents the symlinks forest, and not any pool files
+ # sorting/correlating them may require a new 'PoolFiles' class
+ # (and perhaps to rename this class to 'PkgLinks')
self._pkgfiles = []
self._pkgstatus = {}
self._litterfiles = []
self._load_pkgfiles()
- logging.info('%s pkgfiles: %i', name, len(self._pkgfiles))
- os.makedirs(self._pkgfiles_dir, exist_ok=True)
- with open(os.path.join(self._pkgfiles_dir, '.pkgfiles'), 'w') as out:
- out.write(json.dumps(self._pkgfiles, indent=4, sort_keys=True, default=str))
- with open(os.path.join(self._pkgfiles_dir, '.litterfiles'), 'w') as out:
- out.write(json.dumps(self._litterfiles, indent=4, sort_keys=True, default=str))
-
@property
def name(self):
''' produce the name of the repo '''
@@ -765,6 +753,9 @@ class Repo():
def _load_pkgbuilds(self):
''' load the pkgbuilds from abslibre '''
+ if self._pkgbuild_dir is None:
+ return
+
i = 0
for root, _, files in os.walk(self._pkgbuild_dir):
if 'PKGBUILD' in files:
@@ -788,6 +779,13 @@ class Repo():
self._pkgbuild_cache[arch][pkgname] = []
self._pkgbuild_cache[arch][pkgname].append(pkgbuild)
+ # cache results
+ logging.info('%s pkgbuilds: %i', name, len(self._pkgbuilds))
+ with open(os.path.join(self._pkgbuild_dir, '.pkgbuilds'), 'w') as out:
+ out.write(json.dumps(self._pkgbuilds, indent=4, sort_keys=True, default=str))
+ with open(os.path.join(self._pkgbuild_dir, '.pkgbuild_cache'), 'w') as out:
+ out.write(json.dumps(self._pkgbuild_cache, indent=4, sort_keys=True, default=str))
+
def _load_pkgentries(self):
''' extract and then load the entries in the db.tar.xz '''
arches_dir = os.path.join(self._mirror_dir, 'os')
@@ -847,8 +845,24 @@ class Repo():
self._provides_cache[pkgentry.arch][provides] = []
self._provides_cache[pkgentry.arch][provides].append(pkgentry)
+ # cache results
+ logging.info('%s pkgentries: %i', name, len(self._pkgentries))
+ with open(os.path.join(self._pkgentries_dir, '.pkgentries'), 'w') as out:
+ out.write(json.dumps(self._pkgentries, indent=4, sort_keys=True, default=str))
+ with open(os.path.join(self._pkgentries_dir, '.pkgentries_cache'), 'w') as out:
+ out.write(json.dumps(self._pkgentries_cache, indent=4, sort_keys=True, default=str))
+ with open(os.path.join(self._pkgentries_dir, '.provides_cache'), 'w') as out:
+ out.write(json.dumps(self._provides_cache, indent=4, sort_keys=True, default=str))
+
def _load_pkgfiles(self):
''' load the pkg.tar.xz files from the repo '''
+ # NOTE: the order of Repo instance var initialization is critical
+ # _load_pkgbuilds and _load_pkgentries must be called before _load_pkgfiles;
+ # because PkgFile initialization (in _load_pkgfiles) assumes this object's
+ # _pkgbuild_cache and _pkgentries_cache to be populated prior.
+ if not self._pkgbuilds: _load_pkgbuilds(self)
+ if not self._pkgentries: _load_pkgentries(self)
+
i = 0
arches_dir = os.path.join(self._mirror_dir, 'os')
arch_dirs = sorted(os.scandir(arches_dir), key=lambda arch: arch.name)
@@ -884,6 +898,14 @@ class Repo():
sys.stdout.write(' %s pkgfiles: %i\r' % (self._name, i))
sys.stdout.flush()
+ # cache results
+ logging.info('%s pkgfiles: %i', name, len(self._pkgfiles))
+ os.makedirs(self._pkgfiles_dir, exist_ok=True)
+ with open(os.path.join(self._pkgfiles_dir, '.pkgfiles'), 'w') as out:
+ out.write(json.dumps(self._pkgfiles, indent=4, sort_keys=True, default=str))
+ with open(os.path.join(self._pkgfiles_dir, '.litterfiles'), 'w') as out:
+ out.write(json.dumps(self._litterfiles, indent=4, sort_keys=True, default=str))
+
def __repr__(self):
''' produce a string representation of the repo '''