diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2019-06-09 00:35:54 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2019-06-09 00:35:54 +0300 |
commit | 75b70897ff9ce7dcd6db66ee8e4d5118822a6f66 (patch) | |
tree | 86bab3286956988605a5a8633fed1fe818b8c275 | |
parent | Disabled standalone mode (diff) | |
download | pomu-75b70897ff9ce7dcd6db66ee8e4d5118822a6f66.tar.gz pomu-75b70897ff9ce7dcd6db66ee8e4d5118822a6f66.tar.bz2 pomu-75b70897ff9ce7dcd6db66ee8e4d5118822a6f66.zip |
cli: argument passing fixes
sources: fix custom names
fixed version string generation and version search
ensure import -> change -> commit workflow works
-rw-r--r-- | pomu/cli.py | 8 | ||||
-rw-r--r-- | pomu/package.py | 3 | ||||
-rw-r--r-- | pomu/patch/patch.py | 42 | ||||
-rw-r--r-- | pomu/repo/repo.py | 5 | ||||
-rw-r--r-- | pomu/source/base.py | 4 | ||||
-rw-r--r-- | pomu/source/bugz.py | 6 | ||||
-rw-r--r-- | pomu/source/file.py | 4 | ||||
-rw-r--r-- | pomu/source/manager.py | 2 | ||||
-rw-r--r-- | pomu/source/portage.py | 6 | ||||
-rw-r--r-- | pomu/source/url.py | 4 | ||||
-rw-r--r-- | pomu/util/fs.py | 4 | ||||
-rw-r--r-- | pomu/util/pkg.py | 2 | ||||
-rw-r--r-- | pomu/util/portage.py | 2 |
13 files changed, 60 insertions, 32 deletions
diff --git a/pomu/cli.py b/pomu/cli.py index 862042f..f9b40f0 100644 --- a/pomu/cli.py +++ b/pomu/cli.py @@ -28,9 +28,9 @@ class needs_repo(): self.__name__ = func.__name__ self.__doc__ = func.__doc__ - def __call__(self, *args): + def __call__(self, *args, **kwargs): pomu_active_repo(g_params.no_portage, g_params.repo_path) - self.func(*args) + self.func(*args, **kwargs) pass_globals = click.make_pass_decorator(GlobalVars, ensure=True) @@ -52,7 +52,7 @@ def main(no_portage, repo_path): @click.option('--repo-dir', envvar='POMU_REPO_DIR', default='/var/lib/pomu', help='Path for creating new repos') @click.argument('repo', required=False) -def init(g_params, list_repos, create, repo_dir, repo): +def init(list_repos, create, repo_dir, repo): """Initialise a pomu repository""" if list_repos: print('Available repos:') @@ -145,7 +145,7 @@ def show(package): for f in pkg.files: print(' ', path.join(*f)) if pkg.backend: - print('Backend:', pkg.backend.__name__) + print('Backend:', pkg.backend.__cname__) print('Backend detailes:', pkg.backend) @main.command() diff --git a/pomu/package.py b/pomu/package.py index e145b88..4b2ee5f 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -95,7 +95,8 @@ class Package(): return Result.Ok().and_(self.apply_patches()) def patch(self, patch): - list_add(self.patches, patch) + if patch: + list_add(self.patches, patch) def apply_patches(self, revert=False): """Applies a sequence of patches at the root (after merging)""" diff --git a/pomu/patch/patch.py b/pomu/patch/patch.py index c874623..40a97c6 100644 --- a/pomu/patch/patch.py +++ b/pomu/patch/patch.py @@ -7,6 +7,7 @@ from time import time from git.repo import Repo from pomu.util.pkg import cpv_split +from pomu.util.result import Result def process_changes(_repo, single): # we only tackle repository changes so far @@ -15,28 +16,35 @@ def process_changes(_repo, single): new_files = repo.untracked_files all_pkgs = _repo.get_packages() res = {x: [] for x in all_pkgs} + paths = {x: [] for x in all_pkgs} multi = not single chanpaks = ([],[],[]) # import, order, apply ## Process user-made changes to package files for f in new_files: # process untracked files - pkpref = path.dirname(f).split('/')[0:1].join('/') + pkpref = '/'.join(path.dirname(f).split('/')[0:2]) if pkpref in res: + paths[pkpref].append(f) res[pkpref].append(new_file_patch(f)) for diff in chans: # changes in tracked files - pkpref = path.dirname(diff.a_path).split('/')[0:1].join('/') + pkpref = '/'.join(path.dirname(diff.a_path).split('/')[0:2]) if pkpref in res: - res[pkpref].append(diff_header(diff.a_path, diff.b_path).join('\n') + + paths[pkpref].append(diff.a_path) + res[pkpref].append('\n'.join(diff_header(diff.a_path, diff.b_path)) + diff.diff.decode('utf-8')) res = {x: res[x] for x in res if res[x]} + paths = {x: paths[x] for x in paths if res[x]} for _pkg, diffs in res.items(): # add each change as its own patch cat, name, *_ = cpv_split(_pkg) - patch_contents = diffs.join('\n') - pkg = _repo.get_package(cat, name) - patch_name = '{}-user_changes.patch'.format(int(time.time())) + patch_contents = '\n'.join(diffs) + pkg = _repo.get_package(name, cat).expect() + patch_name = '{}-user_changes.patch'.format(int(time())) + had_order = path.exists(path.join(pkg.pkgdir, 'patches', 'PATCH_ORDER')) pkg.add_patch(patch_contents, patch_name) - repo.index.add([x.a_path for x in diffs]) - repo.index.add([path.join('metadata', cat, name, patch_name)]) + repo.index.add([p for ps in paths for p in paths[ps]]) + repo.index.add([path.join(pkg.pkgdir, 'patches', patch_name)]) + if not had_order: + repo.index.add([path.join(pkg.pkgdir, 'PATCH_ORDER')]) if multi: repo.index.commit('{}/{}: imported user changes'.format(cat, name)) else: @@ -49,16 +57,16 @@ def process_changes(_repo, single): if not len(diff.a_path.split('/')) == 4: continue _, cat, name, __ = diff.a_path.split('/') - if _ != 'metadata' or __ != 'PATCH_ORDER': + if _ != 'metadata' and __ != 'PATCH_ORDER': continue if '/'.join([cat, name]) not in res: continue orig = repo.odb.stream(diff.a_blob.binsha).read().decode('utf-8') - pkg = _repo.get_package(cat, name) + pkg = _repo.get_package(name, cat) orig_lines = [path.join(pkg.pkgdir, x.strip()) for x in orig.split('\n') if x.strip() != ''] pkg.patches = orig_lines pkg.apply_patches(revert=True) - pkg = _repo.get_package(cat, name) + pkg = _repo.get_package(name, cat) pkg.patches = pkg.patch_list applied['{}/{}'.format(cat, name)].extend(pkg.patches) pkg.apply_patches() @@ -72,20 +80,20 @@ def process_changes(_repo, single): ## Process new patch files res = {x: [] for x in all_pkgs} for f in new_files: - if not f.startswith('metadata/'): + if not f.startswith('metadata/') or f.split('/')[-1] == 'PATCH_ORDER': continue - pkpref = path.dirname(f).split('/')[1:2].join('/') + pkpref = '/'.join(path.dirname(f).split('/')[2:4]) if f.split('/')[-1] in applied[pkpref]: #skip, we've added the patch in the previous step continue if pkpref in res: res[pkpref].append(f) for _pkg, diffs in res.items(): # apply each newly added patch - pkg = _repo.get_package(cat, name) cat, name, *_ = cpv_split(_pkg) + pkg = _repo.get_package(name, cat).expect() for d in diffs: pkg.patch(d) repo.index.add(diffs) - repo.index.add[path.join(cat, name)] + repo.index.add([path.join(cat, name)]) if multi: repo.index.commit('{}/{}: applied patches'.format(cat, name)) else: @@ -100,11 +108,13 @@ def process_changes(_repo, single): if chanpaks[2]: msg += '\napplied patches:\n' + '\n'.join(chanpaks[2]) + '\n' + return Result.Ok() + def new_file_patch(repo, newf): with open(path.join(repo.root, newf), 'r') as f: lines = ['+' + x.strip('\n') for x in f.readlines()] head = diff_header('/dev/null', newf, len(lines)) - return (head + lines).join('\n') + '\n' + return '\n'.join(head + lines) + '\n' def diff_header(a_path, b_path, lines=None): header = ['--- ' + a_path, '+++ ' + 'b/' + b_path] diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index 8dfe2d8..98ed4ae 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -86,7 +86,7 @@ class Repository(): 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__)) + f.write('{}\n'.format(package.backend.__cname__)) package.backend.write_meta(pkgdir) with open(path.join(pkgdir, 'VERSION'), 'w+') as f: f.write(package.version) @@ -145,11 +145,12 @@ class Repository(): """Get a package by name, category and slot""" with open(path.join(self.pomu_dir, 'world'), 'r') as f: for spec in f: + spec = spec.strip() cat, _, nam = spec.partition('/') nam, _, slo = nam.partition(':') if (not category or category == cat) and nam == name: if not slot or (slot == '0' and not slo) or slot == slo: - return self._get_package(category, name, slot) + return Result.Ok(self._get_package(category, name, slot or '0')) return Result.Err('Package not found') def get_packages(self): diff --git a/pomu/source/base.py b/pomu/source/base.py index 712f2e6..2cf35e4 100644 --- a/pomu/source/base.py +++ b/pomu/source/base.py @@ -21,7 +21,7 @@ class PackageBase(): """ """The implementation shall provide a name for the package type""" - __name__ = None + __cname__ = None def __init__(self, category, name, version, slot='0'): """ @@ -85,6 +85,8 @@ class BaseSource: It shall provide a method to instantiate a package of this type from the metadata directory. """ + __cname__ = None + @dispatcher.handler() def parse_full(uri): """ diff --git a/pomu/source/bugz.py b/pomu/source/bugz.py index bd0d887..5ecace5 100644 --- a/pomu/source/bugz.py +++ b/pomu/source/bugz.py @@ -15,8 +15,8 @@ from pomu.util.query import query, QueryContext from pomu.util.result import Result class BzEbuild(PackageBase): - """A class to represent a local ebuild""" - __name__ = 'fs' + """A class to represent an ebuild from bugzilla""" + __cname__ = 'bugzilla' def __init__(self, bug_id, filemap, category, name, version, slot='0'): super().__init__(category, name, version, slot) @@ -50,6 +50,8 @@ CLIENT_BASE = 'https://bugs.gentoo.org/xmlrpc.cgi' @dispatcher.source class BugzillaSource(BaseSource): """The source module responsible for importing ebuilds and patches from bugzilla tickets""" + __cname__ = 'bugzilla' + @dispatcher.handler(priority=1) def parse_bug(uri): if not uri.isdigit(): diff --git a/pomu/source/file.py b/pomu/source/file.py index a573cda..9f74d6c 100644 --- a/pomu/source/file.py +++ b/pomu/source/file.py @@ -13,7 +13,7 @@ from pomu.util.result import Result class LocalEbuild(PackageBase): """A class to represent a local ebuild""" - __name__ = 'fs' + __cname__ = 'fs' def __init__(self, path, category, name, version, slot='0'): super().__init__(category, name, version, slot) @@ -50,6 +50,8 @@ class LocalEbuild(PackageBase): @dispatcher.source class LocalEbuildSource(BaseSource): """The source module responsible for importing local ebuilds""" + __cname__ = 'fs' + @dispatcher.handler(priority=5) def parse_ebuild_path(uri): if not path.isfile(uri) or not path.endswith('.ebuild'): diff --git a/pomu/source/manager.py b/pomu/source/manager.py index 61ed9be..c4a0077 100644 --- a/pomu/source/manager.py +++ b/pomu/source/manager.py @@ -48,7 +48,7 @@ class PackageDispatcher(): return cls if cls == BaseSource: return cls - self.backends[cls.__name__] = cls + self.backends[cls.__cname__] = cls for m, obj in inspect.getmembers(cls): if isinstance(obj, self.handler._handler): self.register_package_handler(cls, obj.handler, obj.priority) diff --git a/pomu/source/portage.py b/pomu/source/portage.py index 39336ee..a832ff1 100644 --- a/pomu/source/portage.py +++ b/pomu/source/portage.py @@ -16,7 +16,7 @@ from pomu.util.result import Result class PortagePackage(PackageBase): """A class to represent a portage package""" - __name__ = 'portage' + __cname__ = 'portage' def __init__(self, repo, category, name, version, slot='0'): super().__init__(category, name, version, slot) @@ -53,6 +53,8 @@ class PortagePackage(PackageBase): @dispatcher.source class PortageSource(BaseSource): """The source module responsible for fetching portage packages""" + __cname__ = 'portage' + @dispatcher.handler(priority=5) def parse_spec(uri, repo=None): # dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo @@ -118,7 +120,7 @@ class PortageSource(BaseSource): @classmethod def from_meta_dir(cls, metadir): - return PortagePackage.from_data_dir(cls, metadir) + return PortagePackage.from_data_dir(metadir) def sanity_check(repo, category, name, vernum, suff, rev, slot, ver=None): diff --git a/pomu/source/url.py b/pomu/source/url.py index 0759e5c..8f0366c 100644 --- a/pomu/source/url.py +++ b/pomu/source/url.py @@ -14,7 +14,7 @@ from pomu.util.result import Result class URLEbuild(PackageBase): """A class to represent an ebuild fetched from a url""" - __name__ = 'fs' + __cname__ = 'url' def __init__(self, url, contents, category, name, version, slot): self.url = url @@ -64,6 +64,8 @@ class URLGrabberSource(BaseSource): The source module responsible for grabbing modules from URLs, including pastebins """ + __cname__ = 'url' + @dispatcher.handler(priority=5) def parse_link(uri): if not (uri.startswith('http://') or uri.startswith('https://')): diff --git a/pomu/util/fs.py b/pomu/util/fs.py index 7016717..66716a7 100644 --- a/pomu/util/fs.py +++ b/pomu/util/fs.py @@ -5,6 +5,10 @@ import os def strip_prefix(string, prefix): """Returns a string, stripped from its prefix""" + if not prefix.endswith('/'): + aprefix = prefix + '/' + if string.startswith(aprefix): + return string[len(aprefix):] if string.startswith(prefix): return string[len(prefix):] else: diff --git a/pomu/util/pkg.py b/pomu/util/pkg.py index ac7c55a..a4ee991 100644 --- a/pomu/util/pkg.py +++ b/pomu/util/pkg.py @@ -12,7 +12,7 @@ suffixes = [x[0] for x in sorted(suffix_value.items(), key=lambda x:x[1])] def ver_str(vernum, suff, rev): """Gets the string representation of the version (specified by number, suffix and rev)""" - return vernum + (suff if suff else '') + (rev if rev else '') + return vernum + (suff if suff else '') + ('-' + rev if rev else '') def cpv_split(pkg, unified_ver=False): """ diff --git a/pomu/util/portage.py b/pomu/util/portage.py index 3491dfa..98946d9 100644 --- a/pomu/util/portage.py +++ b/pomu/util/portage.py @@ -21,6 +21,8 @@ def best_ver(repo, category, name, ver=None): ebuilds = [category + '/' + name + x[len(name):-7] for x in os.listdir(path.join(portage_repo_path(repo), category, name)) if x.endswith('.ebuild')] + if not ebuilds: + return None cat, name, vernum, suff, rev = cpv_split(best(ebuilds)) return ver_str(vernum, suff, rev) |