aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-07-27 06:04:36 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-07-27 06:04:36 +0300
commite4930be7d0f266328586ac2b25971c21c804075e (patch)
tree58bc477a3ebc83056b0b5fe4a040315582fd8c32
parentPaid off some technical debt (diff)
downloadpomu-e4930be7d0f266328586ac2b25971c21c804075e.tar.gz
pomu-e4930be7d0f266328586ac2b25971c21c804075e.tar.bz2
pomu-e4930be7d0f266328586ac2b25971c21c804075e.zip
Multiple cli improvements
needs_repo decorator: preserve docstring reworded help messages support -h option for --help fixed patch commend properly hooked commit --single up allow to sync all the changes in the repo by the user in one commit
-rw-r--r--pomu/cli.py19
-rw-r--r--pomu/patch/patch.py28
2 files changed, 34 insertions, 13 deletions
diff --git a/pomu/cli.py b/pomu/cli.py
index bf163b9..7ccad76 100644
--- a/pomu/cli.py
+++ b/pomu/cli.py
@@ -24,6 +24,7 @@ class needs_repo():
def __init__(self, func):
self.func = func
self.__name__ = func.__name__
+ self.__doc__ = func.__doc__
def __call__(self, *args):
pomu_active_repo(g_params.no_portage, g_params.repo_path)
@@ -31,13 +32,13 @@ class needs_repo():
pass_globals = click.make_pass_decorator(GlobalVars, ensure=True)
-@click.group()
+@click.group(context_settings=dict(help_option_names=['-h', '--help']))
@click.option('--no-portage', is_flag=True,
help='Do not setup the portage repo')
@click.option('--repo-path',
help='Path to the repo directory (used with --no-portage)')
def main(no_portage, repo_path):
- """A utility to manage portage overlays"""
+ """A utility to import and manage ebuilds portage overlays"""
g_params.no_portage = no_portage
g_params.repo_path = repo_path
@@ -50,7 +51,7 @@ def main(no_portage, repo_path):
help='Path for creating new repos')
@click.argument('repo', required=False)
def init(g_params, list_repos, create, repo_dir, repo):
- """Initialise pomu for a repository"""
+ """Initialise a pomu repository"""
if list_repos:
print('Available repos:')
for prepo in portage_repos():
@@ -73,10 +74,10 @@ def status():
@main.command(name='import')
@click.argument('package', required=True)
-@click.option('--patch', nargs = -1)
+@click.option('--patch', nargs=1, multiple=True)
@needs_repo
-def list(package, patch):
- """Imports a package"""
+def import_cmd(package, patch):
+ """Import a package into a repository"""
pkg = dispatcher.get_package(package).expect()
pkg.patch(patch)
res = pomu_active_repo().merge(pkg).expect()
@@ -92,10 +93,10 @@ def patch(package):
pkg.patch(patch).expect()
@main.command()
-@click.argument('--single', is_flag=True, required=False, default=False)
+@click.option('--single', is_flag=True, required=False, default=False)
def commit(single):
repo = pomu_active_repo()
- change_map = process_changes(repo).expect()
+ change_map = process_changes(repo, single).expect()
@main.command()
@click.option('--uri', is_flag=True,
@@ -117,7 +118,7 @@ def uninstall(uri, package):
@click.option('--into', default=None,
help='Specify fetch destination')
def fetch(package, into):
- """Fetch a package into a directory"""
+ """Fetch a package into a directory (or display its contents)"""
pkg = dispatcher.get_package(package).expect()
print('Fetched package', pkg, 'at', pkg.root)
print('Contents:')
diff --git a/pomu/patch/patch.py b/pomu/patch/patch.py
index 7021d63..c874623 100644
--- a/pomu/patch/patch.py
+++ b/pomu/patch/patch.py
@@ -8,13 +8,15 @@ from git.repo import Repo
from pomu.util.pkg import cpv_split
-def process_changes(_repo):
+def process_changes(_repo, single):
# we only tackle repository changes so far
repo = Repo(_repo.root)
chans = repo.head.commit.diff(None, create_patch=True)
new_files = repo.untracked_files
all_pkgs = _repo.get_packages()
res = {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
@@ -35,7 +37,10 @@ def process_changes(_repo):
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.commit('{}/{}: imported user changes'.format(cat, name))
+ if multi:
+ repo.index.commit('{}/{}: imported user changes'.format(cat, name))
+ else:
+ chanpaks[0].append('{}/{}'.format(cat, name))
## Process patch order changes
res = {x: [] for x in all_pkgs}
@@ -58,7 +63,10 @@ def process_changes(_repo):
applied['{}/{}'.format(cat, name)].extend(pkg.patches)
pkg.apply_patches()
repo.index.add([diff.a_path, pkg.root])
- repo.index.commit('{}/{}: modified patch order'.format(cat, name))
+ if multi:
+ repo.index.commit('{}/{}: modified patch order'.format(cat, name))
+ else:
+ chanpaks[1].append('{}/{}'.format(cat, name))
## Process new patch files
@@ -78,7 +86,19 @@ def process_changes(_repo):
pkg.patch(d)
repo.index.add(diffs)
repo.index.add[path.join(cat, name)]
- repo.index.commit('{}/{}: applied patches'.format(cat, name))
+ if multi:
+ repo.index.commit('{}/{}: applied patches'.format(cat, name))
+ else:
+ chanpaks[2].append('{}/{}'.format(cat, name))
+
+ if not multi:
+ msg = 'Synced modifications:\n'
+ if chanpaks[0]:
+ msg += '\nimported user changes:\n' + '\n'.join(chanpaks[0]) + '\n'
+ if chanpaks[1]:
+ msg += '\nmodified patch order:\n' + '\n'.join(chanpaks[1]) + '\n'
+ if chanpaks[2]:
+ msg += '\napplied patches:\n' + '\n'.join(chanpaks[2]) + '\n'
def new_file_patch(repo, newf):
with open(path.join(repo.root, newf), 'r') as f: