Commit 125d911f authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[libraries] pre-commit cleanup

parent d5d67929
......@@ -88,7 +88,7 @@ logger = logging.getLogger(__name__)
def pull_impl(webapi, prefix, names, force, indentation, cache):
"""Copies libraries (and dependent libraries) from the server.
"""Copies libraries (and dependent libraries) from the server.
Parameters:
......@@ -122,35 +122,45 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
"""
libraries = oset.oset(names) #what is being request
download = libraries - oset.oset(cache.keys()) #what we actually need
libraries = oset.oset(names) # what is being request
download = libraries - oset.oset(cache.keys()) # what we actually need
if not download: return 0
if not download:
return 0
status, downloaded = common.pull(webapi, prefix, 'library', download,
['declaration', 'code', 'description'], force, indentation)
if indentation == 0:
indentation = 4
if status != 0: return status
status, downloaded = common.pull(
webapi,
prefix,
"library",
download,
["declaration", "code", "description"],
force,
indentation,
)
indent = indentation * ' '
if status != 0:
return status
# see what else one needs to pull
for name in downloaded:
try:
obj = library.Library(prefix, name)
cache[name] = obj
if not obj.valid:
cache[name] = None
# see what else one needs to pull
for name in downloaded:
try:
obj = library.Library(prefix, name)
cache[name] = obj
if not obj.valid:
cache[name] = None
# downloads any dependencies
libraries |= obj.libraries.keys()
# downloads any dependencies
libraries |= obj.libraries.keys()
except Exception as e:
logger.error("loading `%s': %s...", name, str(e))
cache[name] = None
except Exception as e:
logger.error("loading `%s': %s...", name, str(e))
cache[name] = None
# recurse until done
return pull_impl(webapi, prefix, libraries, force, 2+indentation, cache)
# recurse until done
return pull_impl(webapi, prefix, libraries, force, indentation, cache)
@click.group(cls=AliasedGroup)
......@@ -161,181 +171,202 @@ def libraries(ctx):
@libraries.command()
@click.option('--remote', help='Only acts on the remote copy of the library',
is_flag=True)
@click.option(
"--remote", help="Only acts on the remote copy of the library", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
'''Lists all the libraries available on the platform
"""Lists all the libraries available on the platform
Example:
$ beat libraries list --remote
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.display_remote_list(webapi, 'library')
else:
return common.display_local_list(ctx.meta['config'].path, 'library')
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "library")
else:
return common.display_local_list(ctx.meta["config"].path, "library")
@libraries.command()
@click.argument('names', nargs=-1)
@click.argument("names", nargs=-1)
@click.pass_context
@raise_on_error
def path(ctx, names):
'''Displays local path of libraries files
"""Displays local path of libraries files
Example:
$ beat libraries path xxx
'''
return common.display_local_path(ctx.meta['config'].path, 'library', names)
"""
return common.display_local_path(ctx.meta["config"].path, "library", names)
@libraries.command()
@click.argument('name', nargs=1)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def edit(ctx, name):
'''Edit local library file
"""Edit local library file
Example:
$ beat libraries edit xxx
'''
return common.edit_local_file(ctx.meta['config'].path,
ctx.meta['config'].editor, 'library',
name)
"""
return common.edit_local_file(
ctx.meta["config"].path, ctx.meta["config"].editor, "library", name
)
@libraries.command()
@click.argument('name', nargs=1)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def check(ctx, names):
'''Checks a local library for validity
"""Checks a local library for validity
Example:
$ beat libraries check xxx
'''
return common.check(ctx.meta['config'].path, 'library', names)
"""
return common.check(ctx.meta["config"].path, "library", names)
@libraries.command()
@click.argument('names', nargs=-1)
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.argument("names", nargs=-1)
@click.option(
"--force", help="Performs operation regardless of conflicts", is_flag=True
)
@click.pass_context
@raise_on_error
def pull(ctx, names, force):
'''Downloads the specified libraries from the server
"""Downloads the specified libraries from the server
Example:
$ beat libraries pull --force yyy
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return pull_impl(webapi, ctx.meta['config'].path, names, force, 0, {})
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return pull_impl(webapi, ctx.meta["config"].path, names, force, 0, {})
@libraries.command()
@click.argument('names', nargs=-1)
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.option('--dry-run', help="Doesn't really perform the task, just "
"comments what would do", is_flag=True)
@click.argument("names", nargs=-1)
@click.option(
"--force", help="Performs operation regardless of conflicts", is_flag=True
)
@click.option(
"--dry-run",
help="Doesn't really perform the task, just " "comments what would do",
is_flag=True,
)
@click.pass_context
@raise_on_error
def push(ctx, names, force, dry_run):
'''Uploads libraries to the server
"""Uploads libraries to the server
Example:
$ beat libraries push --dry-run yyy
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.push(webapi, ctx.meta['config'].path, 'library',
name, ['names', 'declaration', 'code', 'description'],
{}, force, dry_run, 0)
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.push(
webapi,
ctx.meta["config"].path,
"library",
names,
["names", "declaration", "code", "description"],
{},
force,
dry_run,
0,
)
@libraries.command()
@click.argument('name', nargs=1)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
'''Shows changes between the local library and the remote version
"""Shows changes between the local library and the remote version
Example:
$ beat libraries diff xxx
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.diff(webapi, ctx.meta['config'].path, 'library',
name, ['declaration', 'code', 'description'])
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.diff(
webapi,
ctx.meta["config"].path,
"library",
name,
["declaration", "code", "description"],
)
@libraries.command()
@click.pass_context
@raise_on_error
def status(ctx):
'''Shows (editing) status for all available libraries
"""Shows (editing) status for all available libraries
Example:
$ beat libraries status
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.status(webapi, ctx.meta['config'].path, 'library')[0]
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.status(webapi, ctx.meta["config"].path, "library")[0]
@libraries.command()
@click.argument('names', nargs=-1)
@click.argument("names", nargs=-1)
@click.pass_context
@raise_on_error
def create(ctx, names):
'''Creates a new local library
"""Creates a new local library
Example:
$ beat libraries create xxx
'''
return common.create(ctx.meta['config'].path, 'library', name)
"""
return common.create(ctx.meta["config"].path, "library", names)
@libraries.command()
@click.argument('name', nargs=1)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def version(ctx, name):
'''Creates a new version of an existing library
"""Creates a new version of an existing library
Example:
$ beat libraries version xxx
'''
return common.new_version(ctx.meta['config'].path, 'library', name)
"""
return common.new_version(ctx.meta["config"].path, "library", name)
@libraries.command()
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.argument("src", nargs=1)
@click.argument("dst", nargs=1)
@click.pass_context
@raise_on_error
def fork(ctx, src, dst):
'''Forks a local library
"""Forks a local library
Example:
$ beat libraries fork xxx yyy
'''
return common.fork(ctx.meta['config'].path, 'library', src, dst)
"""
return common.fork(ctx.meta["config"].path, "library", src, dst)
@libraries.command()
@click.argument('names', nargs=1)
@click.option('--remote', help='Only acts on the remote copy of the library',
is_flag=True)
@click.argument("names", nargs=1)
@click.option(
"--remote", help="Only acts on the remote copy of the library", is_flag=True
)
@click.pass_context
@raise_on_error
def rm(ctx, names, remote):
'''Deletes a local library (unless --remote is specified)
"""Deletes a local library (unless --remote is specified)
Example:
$ beat libraries rm xxx
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.delete_remote(webapi, 'library', names)
else:
return common.delete_local(ctx.meta['config'].path, 'library', names)
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.delete_remote(webapi, "library", names)
else:
return common.delete_local(ctx.meta["config"].path, "library", names)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment