diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-06-10 03:52:32 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-06-10 03:52:32 +0300 |
commit | 47e797b4f53a7552151e1ac90b8ddc140b97a24d (patch) | |
tree | 1074f798dd96bb9738375b79895f9b2f35f53f3a /pomu | |
parent | Numerous fixes all over the tree (diff) | |
download | pomu-47e797b4f53a7552151e1ac90b8ddc140b97a24d.tar.gz pomu-47e797b4f53a7552151e1ac90b8ddc140b97a24d.tar.bz2 pomu-47e797b4f53a7552151e1ac90b8ddc140b97a24d.zip |
cli: added fetch, install, uninstall commands
pomu repo detection refactoring
Diffstat (limited to 'pomu')
-rw-r--r-- | pomu/cli.py | 50 | ||||
-rw-r--r-- | pomu/repo/repo.py | 23 |
2 files changed, 58 insertions, 15 deletions
diff --git a/pomu/cli.py b/pomu/cli.py index 3e45f7e..25a9652 100644 --- a/pomu/cli.py +++ b/pomu/cli.py @@ -3,9 +3,11 @@ import click from pomu.repo.init import init_plain_repo, init_portage_repo from pomu.repo.repo import portage_repo_path, portage_repos, pomu_status, pomu_active_repo +from pomu.source import dispatcher from pomu.util.result import ResultException #TODO: global --repo option, (env var?) +#TODO: write a neat decorator to pass the repo class GlobalVars(): """Global state""" @@ -54,18 +56,40 @@ def init(globalvars, list_repos, create, repo_dir, repo): @pass_globals def status(globalvars): """Display pomu status""" - if globalvars.no_portage: - if not globalvars.repo_path: - print('Error: repo-path required') - return - if pomu_status(globalvars.repo_path): - print('pomu is initialized at', globalvars.repo_path) - return - print('pomu is not initialized') - else: - repo = pomu_active_repo() - if repo: - print('pomu is initialized for repository', repo, 'at', portage_repo_path(repo)) + res = pomu_active_repo_(globalvars.no_portage, globalvars.repo_path) + if res.is_ok(): + repo = res.ok() + if repo.name: + print('pomu is initialized for reporitory', repo.name, 'at', repo.root) else: - print('pomu is not initialized') + print('pomu is initialized at', repo.root) + else: + print('Error:', res.err()) + +@main.command() +@click.argument('package', required=True) +@pass_globals +def install(self): + res = dispatcher.install_package(package).expect() + print(res) +@main.command() +@click.option('--uri', is_flag=True, + help='Specify the package to remove by uri, instead of its name') +@click.argument('package', required=True) +@pass_globals +def uninstall(self): + if uri: + res = dispatcher.uninstall_package(package).expect() + print(res) + else: + repo = pomu_active_repo_(globalvars.no_portage, globalvars.repo_path).expect() + res = repo.remove_package(package).expect() + return res + +@main.command() +@click.argument('package', required=True) +@pass_globals +def fetch(self): + pkg = dispatcher.get_package(package).expect() + print('Fetched package', pkg.name, 'at', pkg.root) diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index c907db3..690869c 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -6,12 +6,14 @@ from git import Repo import portage from pomu.util.fs import remove_file +from pomu.util.result import Result class Repository(): - def __init__(self, root): + def __init__(self, root, name=None): if not pomu_status(root): raise ValueError('This path is not a valid pomu repository') self.root = root + self.name = name @property def repo(self): @@ -80,9 +82,26 @@ def pomu_status(repo_path): """Check if pomu is enabled for a repository at a given path""" return path.isdir(path.join(repo_path, 'metadata', 'pomu')) -def pomu_active_repo(): +def pomu_active_portage_repo(): """Returns a portage repo, for which pomu is enabled""" for repo in portage_repos(): if pomu_status(portage_repo_path(repo)): return repo return None + +def pomu_active_repo(): + return pomu_active_portage_repo() + +#TODO: merge with pomu_active_repo, pass the result +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'): + 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.Err('pomu is not initialized') |