diff options
-rw-r--r-- | pomu/package.py | 5 | ||||
-rw-r--r-- | pomu/repo/repo.py | 25 | ||||
-rw-r--r-- | pomu/source/portage.py | 39 |
3 files changed, 50 insertions, 19 deletions
diff --git a/pomu/package.py b/pomu/package.py index 803320b..f7bcb93 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -2,6 +2,7 @@ A package is a set of files, situated in a root directory. A package can be installed into a repository. A package is supposed to be created by a package source from a set of files. +A package is supposed to know, where it came from. """ from os import path, walk, makedirs @@ -13,9 +14,10 @@ from pomu.util.fs import strip_prefix from pomu.util.result import Result class Package(): - def __init__(self, name, root, category=None, version=None, slot='0', d_path=None, files=None): + def __init__(self, backend, source, name, root, category=None, version=None, slot='0', d_path=None, files=None): """ Parameters: + backend - specific source module object/class name - name of the package root - root path of the repository (if applicable) d_path - a subdirectory of the root path, which would be sourced recursively. @@ -23,6 +25,7 @@ class Package(): files - a set of files to build a package from category, version, slot - self-descriptive """ + self.backend = backend self.name = name self.root = root self.category = category diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index f66e5f8..7987c15 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -36,20 +36,26 @@ class Repository(): manifests = package.gen_manifests(self.root).expect() for m in manifests: r.index.add(m) - with open(path.join(pkgdir, 'FILES'), 'w') as f: - for w, f in package.files: - f.write('{}/{}'.format(w, f)) - for m in manifests: - f.write(strip_prefix(m, self.root)) - with open(path.join(pkgdir, 'VERSION')) as f: - f.write(package.version) + self.write_meta(pkgdir, package, manifests) with open(path.join(self.pomu_dir, 'world'), 'a+') as f: f.write(package.category, '/', package.name) + f.write('\n' if package.slot == '0' else ':{}\n'.format(package.slot)) r.index.add(path.join(self.pomu_dir, package.name)) r.index.add(self.pomu_dir) r.index.commit('Merged package ' + package.name) return Result.Ok('Merged package ' + package.name + ' successfully') + def write_meta(self, pkgdir, package, manifests): + with open(path.join(pkgdir, 'FILES'), 'w') as f: + for w, f in package.files: + f.write('{}/{}\n'.format(w, f)) + for m in manifests: + f.write('{}\n'.format(strip_prefix(m, self.root))) + if package.backend: + package.backend.write_meta(pkgdir) + with open(path.join(pkgdir, 'VERSION')) as f: + f.write(package.version) + def unmerge(self, package): """Remove a package (by contents) from the repository""" r = self.repo @@ -68,18 +74,17 @@ class Repository(): def remove_package(self, name): """Remove a package (by name) from the repository""" r = self.repo - pf = path.join(self.pomu_dir, name) + pf = path.join(self.pomu_dir, name, 'FILES') if not path.isfile(pf): return Result.Err('Package not found') with open(pf, 'w') as f: for insf in f: remove_file(path.join(self.root, insf)) - remove_file(pf) + remove_file(path.join(self.pomu_dir, name)) r.commit('Removed package ' + name + ' successfully') return Result.Ok('Removed package ' + name + ' successfully') - def portage_repos(): """Yield the repositories configured for portage""" rsets = portage.db[portage.root]['vartree'].settings.repositories diff --git a/pomu/source/portage.py b/pomu/source/portage.py index fe0f4ce..2dcef72 100644 --- a/pomu/source/portage.py +++ b/pomu/source/portage.py @@ -25,11 +25,33 @@ class PortagePackage(): self.slot = slot def fetch(self): - return Package(self.name, portage_repo_path(self.repo), + return Package(self, self.name, portage_repo_path(self.repo), category=self.category, version=self.version, slot=self.slot, files=[path.join(self.category, self.name, 'metadata.xml'), path.join(self.category, self.name, self.name + '-' + self.version + '.ebuild')]) + def write_meta(self, pkgdir): + with open(path.join(pkgdir, 'PORTAGE_DATA'), 'w') as f: + f.write(self.repo + '\n') + f.write(self.category + '\n') + f.write(self.name + '\n') + f.write(self.version + '\n') + f.write(self.slot + '\n') + + @staticmethod + def from_data_file(path): + try: + lines = [x.strip() for x in open(path, 'r')] + except: + return Result.Err('Could not read data file') + if len(lines) < 5: + return Result.Err('Invalid data provided') + res = PortagePackage() + res.repo, res.category, res.name, res.version, res.slot, *_ = lines + if sanity_check(res.repo, res.category, res.name, None, None, None, res.slot, ver=res.version): + return Result.Ok(res) + return Result.Err('Package {} not found'.format(res)) + def __str__(self): return '{}/{}-{}{}::{}'.format(self.category, self.name, self.version, '' if self.slot == '0' else ':' + self.slot, self.repo) @@ -78,7 +100,7 @@ class PortageSource(): return pkg.fetch() -def sanity_check(repo, category, name, vernum, suff, rev, slot): +def sanity_check(repo, category, name, vernum, suff, rev, slot, ver=None): """ Checks whether a package descriptor is valid and corresponds to a package in a configured portage repository @@ -87,12 +109,13 @@ def sanity_check(repo, category, name, vernum, suff, rev, slot): return False if repo and repo not in list(portage_repos()): return False - if (rev or suff) and not vernum: - return False - if vernum: - ver = ver_str(vernum, suff, rev) - else: - ver = None + if not ver: + if (rev or suff) and not vernum: + return False + if vernum: + ver = ver_str(vernum, suff, rev) + else: + ver = None pkgs = repo_pkgs(repo, category, name, ver, slot) if not pkgs: return False |