diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-06-26 05:25:18 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-06-26 05:25:18 +0300 |
commit | 41cb884b2681e4204ed72602722d0648b3531c31 (patch) | |
tree | 24e0a42cfbbde453edf3e94be41f361dcfb407c9 /pomu | |
parent | Integrate metadata with the module interface/repo (diff) | |
download | pomu-41cb884b2681e4204ed72602722d0648b3531c31.tar.gz pomu-41cb884b2681e4204ed72602722d0648b3531c31.tar.bz2 pomu-41cb884b2681e4204ed72602722d0648b3531c31.zip |
A show command to display installed package meta
Diffstat (limited to 'pomu')
-rw-r--r-- | pomu/cli.py | 19 | ||||
-rw-r--r-- | pomu/package.py | 2 | ||||
-rw-r--r-- | pomu/repo/repo.py | 27 |
3 files changed, 35 insertions, 13 deletions
diff --git a/pomu/cli.py b/pomu/cli.py index 4b09000..65dfa15 100644 --- a/pomu/cli.py +++ b/pomu/cli.py @@ -73,6 +73,7 @@ def status(): @click.argument('package', required=True) @needs_repo def install(package): + """Install a package""" res = dispatcher.install_package(package).expect() print(res) @@ -82,6 +83,7 @@ def install(package): @click.argument('package', required=True) @needs_repo def uninstall(uri, package): + """Uninstall a package""" if uri: res = dispatcher.uninstall_package(package).expect() print(res) @@ -95,6 +97,7 @@ def uninstall(uri, package): @click.option('--into', default=None, help='Specify fetch destination') def fetch(package, into): + """Fetch a package into a directory""" pkg = dispatcher.get_package(package).expect() print('Fetched package', pkg, 'at', pkg.root) print('Contents:') @@ -104,6 +107,22 @@ def fetch(package, into): pkg.merge_into(into).expect() print('Copied to', into, 'successfully') +@main.command() +@click.argument('package', required=True) +@needs_repo +def show(package): + """Display installed package info""" + repo = pomu_active_repo() + category, _, name = package.rpartition('/') + name, _, slot = name.partition(':') + pkg = repo.get_package(name, category, slot).expect() + print('Package', pkg, 'version', pkg.version) + print('Merged into repository', repo.name, 'at', repo.root) + for f in pkg.files: + print(' ', path.join(*f)) + print('Backend:', pkg.backend.__name__) + print('Backend detailes:', pkg.backend) + def main_(): try: main.main(standalone_mode=False) diff --git a/pomu/package.py b/pomu/package.py index f7bcb93..4a07cbe 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -14,7 +14,7 @@ from pomu.util.fs import strip_prefix from pomu.util.result import Result class Package(): - def __init__(self, backend, source, name, root, category=None, version=None, slot='0', d_path=None, files=None): + def __init__(self, backend, name, root, category=None, version=None, slot='0', d_path=None, files=None): """ Parameters: backend - specific source module object/class diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index 9b02edb..4318d3e 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -86,16 +86,8 @@ class Repository(): r.commit('Removed package ' + name + ' successfully') return Result.Ok('Removed package ' + name + ' successfully') - def get_package(self, category, name, slot='0'): - """Get a package by name""" - with open(path.join(self.pomu_dir, 'world'), 'r') as f: - lines = [x.strip() for x in f] - if slot == '0': - spec = '{}/{}'.format(category, name) - else: - spec = '{}/{}:{}'.format(category, name, slot) - if not lines.has(spec): - return Result.Err('Package not found') + def _get_package(self, category, name, slot='0'): + """Get an existing package""" if slot == '0': pkgdir = path.join(self.pomu_dir, category, name) else: @@ -109,6 +101,17 @@ class Repository(): files = [x.strip() for x in f] return Package(backend, name, self.root, category=category, version=version, slot=slot, files=files) + def get_package(self, name, category=None, slot=None): + """Get a package by name""" + with open(path.join(self.pomu_dir, 'world'), 'r') as f: + for spec in f: + 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.Err('Package not found') + def portage_repos(): """Yield the repositories configured for portage""" @@ -142,11 +145,11 @@ def pomu_active_repo(no_portage=None, repo_path=None): if no_portage: if not repo_path: return Result.Err('repo-path required') - if pomu_status('repo_path'): + if pomu_status(repo_path): return Result.Ok(Repository(repo_path)) return Result.Err('pomu is not initialized') else: repo = pomu_active_portage_repo() if repo: - return Result.Ok(portage_repo_path(repo), repo) + return Result.Ok(Repository(repo)) return Result.Err('pomu is not initialized') |