aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-05-30 12:27:52 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-05-30 12:27:52 +0300
commitb9c1696b26875558b08148b07ec00909f3ace47c (patch)
tree59090a7a98e2e5beb8311b6bd918e6d8659bf65a
parentRefactor pomu initialization (diff)
downloadpomu-b9c1696b26875558b08148b07ec00909f3ace47c.tar.gz
pomu-b9c1696b26875558b08148b07ec00909f3ace47c.tar.bz2
pomu-b9c1696b26875558b08148b07ec00909f3ace47c.zip
Support local repos (without portage)
-rw-r--r--pomu/pomu.py118
1 files changed, 88 insertions, 30 deletions
diff --git a/pomu/pomu.py b/pomu/pomu.py
index 6ca27b8..bdaaace 100644
--- a/pomu/pomu.py
+++ b/pomu/pomu.py
@@ -6,9 +6,23 @@ from portage.os import path, makedirs
#TODO: global --repo option, (env var?)
+class GlobalVars():
+ def __init__(self):
+ self.no_portage = False
+ self.repo_path = None
+
+pass_globals = click.make_pass_decorator(GlobalVars, ensure=True)
+
@click.group()
-def main():
+@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)')
+@pass_globals
+def main(globalvars, no_portage, repo_path):
"""A utility to manage portage overlays"""
+ globalvars.no_portage = no_portage
+ globalvars.repo_path = repo_path
pass
@main.command()
@@ -16,9 +30,11 @@ def main():
help='Lists available repositories')
@click.option('--create', is_flag=True,
help='Create the repository, instead of using an existing one')
+@click.option('--repo-dir', envvar='POMU_REPO_DIR', default='/var/lib/pomu',
+ help='Path for creating new repos')
@click.argument('repo', required=False)
-@click.argument('repo-dir', envvar='POMU_REPO_DIR', required=False, default='/var/lib/pomu')
-def init(list_repos, create, repo, repo_dir):
+@pass_globals
+def init(globalvars, list_repos, create, repo_dir, repo):
"""Initialise pomu for a repository"""
rs = portage.db[portage.root]['vartree'].settings.repositories
if list_repos:
@@ -26,9 +42,40 @@ def init(list_repos, create, repo, repo_dir):
for repo in rs.prepos_order:
print('\t', repo, rs.prepos[repo].location)
return
+ if globalvars.no_portage:
+ init_plain_repo(create, globalvars.repo_path)
+ else:
+ init_portage_repo(create, repo, repo_dir)
+
+def init_plain_repo(create, repo_path):
+ """Initialize a plain repository"""
+ if not repo_path:
+ print('Error: repository path required')
+ return
+ if create:
+ if path.isdir(repo_path):
+ print('Error: this repository already exists')
+ return
+ try:
+ makedirs(repo_path)
+ except PermissionError:
+ print('Error: you do not have enough permissions to create the git repository')
+ return
+ Repo.init(repo_path)
+ if not init_pomu(repo_path):
+ rmtree(repo_path)
+ else:
+ if not path.isdir(repo_path):
+ print('Error: directory not found')
+ return
+ init_pomu(repo_path)
+
+def init_portage_repo(create, repo, repo_dir):
+ """Initialize a portage repository"""
if not repo:
print('Error: repository name required')
return
+ rs = portage.db[portage.root]['vartree'].settings.repositories
if create:
if repo in rs.prepos_order:
print('Error: a repository with such name already exists!')
@@ -47,41 +94,52 @@ def init(list_repos, create, repo, repo_dir):
print('Error: you do not have enough permissions to setup a portage repo')
rmtree(repo_path)
return
- r = Repo.init(repo_path)
- if not pomu_init(repo_path):
+ Repo.init(repo_path)
+ if not init_pomu(repo_path, repo):
rmtree(repo_path)
else:
if repo not in rs.prepos_order:
print('Error: repository not found')
return
- init_pomu(rs.prepos[repo])
+ init_pomu(rs.prepos[repo], repo)
-def init_pomu(repo_path):
- pomu_path = path.join(repo_path, 'metadata', 'pomu')
- if not path.isdir(path.join(repo_path, '.git')):
- print('Error: target repository should be a git repo')
- return False
- if path.isdir(pomu_path):
- print('Repository', repo, 'already initialized')
- return True
- r = Repo(repo_path)
- try:
- makedirs(pomu_path)
- open(path.join(pomu_path, '.sentinel'), 'w').close()
- except PermissionError:
- print('Error: you do not have enough permissions to modify the repo')
- return False
- r.index.add(pomu_path)
- r.index.commit('Initialized pomu')
- print('Initialized repository', repo, 'successfully')
+def init_pomu(repo_path, name=' '):
+ """Initialise pomu for a repository"""
+ pomu_path = path.join(repo_path, 'metadata', 'pomu')
+ if not path.isdir(path.join(repo_path, '.git')):
+ print('Error: target repository should be a git repo')
+ return False
+ if path.isdir(pomu_path):
+ print('Repository', name, 'already initialized')
return True
+ r = Repo(repo_path)
+ try:
+ makedirs(pomu_path)
+ open(path.join(pomu_path, '.sentinel'), 'w').close()
+ except PermissionError:
+ print('Error: you do not have enough permissions to modify the repo')
+ return False
+ r.index.add(pomu_path)
+ r.index.commit('Initialized pomu')
+ print('Initialized repository', name, 'successfully')
+ return True
@main.command()
-def status():
+@pass_globals
+def status(globalvars):
"""Display pomu status"""
- rs = portage.db[portage.root]['vartree'].settings.repositories
- for repo in rs.prepos_order:
- if path.isdir(path.join(rs.prepos[repo].location, 'metadata', 'pomu')):
- print('pomu is initialized for repository', repo, 'at', rs.prepos[repo].location)
+ if globalvars.no_portage:
+ if not globalvars.repo_path:
+ print('Error: repo-path required')
return
- print('pomu is not initialized')
+ if path.isdir(path.join(globalvars.repo_path, 'metadata', 'pomu')):
+ print('pomu is initialized at', globalvars.repo_path)
+ print('pomu is not initialized')
+ pass
+ else:
+ rs = portage.db[portage.root]['vartree'].settings.repositories
+ for repo in rs.prepos_order:
+ if path.isdir(path.join(rs.prepos[repo].location, 'metadata', 'pomu')):
+ print('pomu is initialized for repository', repo, 'at', rs.prepos[repo].location)
+ return
+ print('pomu is not initialized')