Skip to content
Snippets Groups Projects
Commit 0ff7b561 authored by Konstantin Baierer's avatar Konstantin Baierer
Browse files

CLI for cloning and updating repos

parent e5f124e5
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,14 @@ from .repo import Repo ...@@ -9,6 +9,14 @@ from .repo import Repo
LOG = getLogger('kwalitee.cli') LOG = getLogger('kwalitee.cli')
def _check_cloned(ctx):
uncloned = []
for repo in ctx.repos:
if not repo.is_cloned():
uncloned.append(repo)
if uncloned:
raise Exception("Some repos not yet cloned: %s" % [str(r) for r in uncloned])
class CliCtx(): class CliCtx():
def __init__(self, config_file): def __init__(self, config_file):
with open(config_file, 'r') as f_config_file: with open(config_file, 'r') as f_config_file:
...@@ -23,6 +31,31 @@ pass_ctx = click.make_pass_decorator(CliCtx) ...@@ -23,6 +31,31 @@ pass_ctx = click.make_pass_decorator(CliCtx)
def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument
ctx.obj = CliCtx(config_file) ctx.obj = CliCtx(config_file)
@cli.command('clone', help='''
Clone all repos
''')
@pass_ctx
def clone_all(ctx):
for repo in ctx.repos:
if repo.is_cloned():
LOG.info("Already cloned %s" % repo)
else:
LOG.info("Cloning %s" % repo)
repo.clone()
@cli.command('pull', help='''
Pull all repos
''')
@pass_ctx
def pull_all(ctx):
_check_cloned(ctx)
for repo in ctx.repos:
LOG.info("Pulling %s" % repo)
repo.pull()
@cli.command('json', help=''' @cli.command('json', help='''
Generate JSON Generate JSON
...@@ -38,6 +71,7 @@ def generate_json(ctx, full, **kwargs): ...@@ -38,6 +71,7 @@ def generate_json(ctx, full, **kwargs):
if full: if full:
for k in kwargs: for k in kwargs:
kwargs[k] = True kwargs[k] = True
_check_cloned(ctx)
for repo in ctx.repos: for repo in ctx.repos:
LOG.info("# Assessing %s" % repo.name) LOG.info("# Assessing %s" % repo.name)
repo.clone() repo.clone()
......
...@@ -15,8 +15,18 @@ class Repo(): ...@@ -15,8 +15,18 @@ class Repo():
self.name = Path(url).name self.name = Path(url).name
self.path = Path(self.config['repodir'], self.name) self.path = Path(self.config['repodir'], self.name)
def __str__(self):
return '<Repo %s @ %s>' % (self.url, self.path)
def is_cloned(self):
return self.path.is_dir()
def pull(self):
with pushd_popd(self.path):
self._run('git pull origin master')
def clone(self): def clone(self):
if self.path.is_dir(): if self.is_cloned():
LOG.debug("Already cloned: %s" % self.path) LOG.debug("Already cloned: %s" % self.path)
return return
with pushd_popd(self.config['repodir']): with pushd_popd(self.config['repodir']):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment