diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-07 10:40:11 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-07-18 23:26:27 +0300 |
commit | 1c7929604b84d982296f082c060fcc305fd9146e (patch) | |
tree | 7bba82a909ec6596d6c9572587241a8ea9b51a89 /pomu/repo/repo.py | |
parent | Fixed a logic error in Dispatcher (diff) | |
download | pomu-1c7929604b84d982296f082c060fcc305fd9146e.tar.gz pomu-1c7929604b84d982296f082c060fcc305fd9146e.tar.bz2 pomu-1c7929604b84d982296f082c060fcc305fd9146e.zip |
Overhauled patching support
dropped patch package source module
added --patch option to the install command
added a patch command to patch an existing package
integrated patch support into the Package class
created a MergedPackage module for operations on packages already in the
pomu repo
added ways to patch an existing package
added a base package source module (template), with base classes for
package-specific metadata and the source module per se
added a list_add utility function
implemented and_, and_then, and or in util.result
Diffstat (limited to 'pomu/repo/repo.py')
-rw-r--r-- | pomu/repo/repo.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index f41e0e4..b60f6c1 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -1,7 +1,9 @@ """Subroutines with repositories""" from os import path, rmdir, makedirs +from shutil import copy2 from git import Repo +from patch import PatchSet import portage from pomu.package import Package @@ -64,6 +66,13 @@ class Repository(): f.write('{}/{}\n'.format(wd, fil)) for m in manifests: f.write('{}\n'.format(strip_prefix(m, self.root))) + if package.patches: + patch_dir = path.join(pkgdir, 'patches') + makedirs(patch_dir, exist_ok=True) + with open(path.join(pkgdir, 'PATCH_ORDER'), 'w') as f: + for patch in package.patches: + copy2(patch, patch_dir) + f.write(path.basename(patch) + '\n') if package.backend: with open(path.join(pkgdir, 'BACKEND'), 'w+') as f: f.write('{}\n'.format(package.backend.__name__)) @@ -107,7 +116,13 @@ class Repository(): version = f.readline().strip() with open(path.join(pkgdir, 'FILES'), 'r') as f: files = [x.strip() for x in f] - return Package(name, self.root, backend, category=category, version=version, slot=slot, files=files) + patches=[] + if path.isfile(path.join(pkgdir, 'PATCH_ORDER')): + with open(path.join(pkgdir, 'PATCH_ORDER'), 'r') as f: + patches = [x.strip() for x in f] + pkg = Package(name, self.root, backend, category=category, version=version, slot=slot, files=files, patches=[path.join(pkgdir, 'patches', x) for x in patches]) + pkg.__class__ = MergedPackage + return pkg def get_package(self, name, category=None, slot=None): """Get a package by name, category and slot""" @@ -161,3 +176,28 @@ def pomu_active_repo(no_portage=None, repo_path=None): if repo: return Result.Ok(Repository(portage_repo_path(repo), repo)) return Result.Err('pomu is not initialized') + +class MergedPackage(Package): + def patch(self, patch): + pkgdir = path.join(self.root, 'metadata', 'pomu', self.category, self.name) + if self.slot != '0': + pkgdir = path.join(pkgdir, self.slot) + if isinstance(patch, list): + for x in patch: + self.patch(x) + return Result.Ok() + ps = PatchSet() + ps.parse(open(patch, 'r')) + ps.apply(root=self.root) + self.add_patch(patch) + return Result.Ok() + + def add_patch(self, patch): + pkgdir = path.join(self.root, 'metadata', 'pomu', self.category, self.name) + if self.slot != '0': + pkgdir = path.join(pkgdir, self.slot) + patch_dir = path.join(pkgdir, 'patches') + makedirs(patch_dir, exist_ok=True) + copy2(patch, patch_dir) + with open(path.join(pkgdir, 'PATCH_ORDER'), 'w+') as f: + f.write(path.basename(patch) + '\n') |