Commit 85b35556 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[dataformats] pre-commit cleanup

parent 8c1c935f
......@@ -50,7 +50,7 @@ logger = logging.getLogger(__name__)
def pull_impl(webapi, prefix, names, force, indentation, cache):
"""Copies dataformats (recursively) from the server.
"""Copies dataformats (recursively) from the server.
Data formats are particularly tricky to download because of their recursive
nature. This requires a specialized recursive technique to download base and
......@@ -89,35 +89,46 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
"""
dataformats = oset.oset(names) #what is being request
download = dataformats - oset.oset(cache.keys()) #what we actually need
dataformats = oset.oset(names) # what is being request
download = dataformats - oset.oset(cache.keys()) # what we actually need
if not download: return 0
if not download:
return 0
status, downloaded = common.pull(webapi, prefix, 'dataformat', download,
['declaration', 'description'], force, indentation)
status, downloaded = common.pull(
webapi,
prefix,
"dataformat",
download,
["declaration", "description"],
force,
indentation,
)
if status != 0:
return status
if status != 0: return status
if indentation == 0:
indentation = 4
indent = indentation * ' '
# see what else one needs to pull
for name in downloaded:
try:
obj = dataformat.DataFormat(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 = dataformat.DataFormat(prefix, name)
cache[name] = obj
if not obj.valid:
cache[name] = None
# downloads any dependencies
dataformats |= obj.referenced.keys()
# downloads any dependencies
dataformats |= obj.referenced.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, dataformats, force, 2 + indentation, cache)
# recurse until done
return pull_impl(webapi, prefix, dataformats, force, 2+indentation, cache)
@click.group(cls=AliasedGroup)
@click.pass_context
......@@ -127,187 +138,205 @@ def dataformats(ctx):
@dataformats.command()
@click.option('--remote', help='Only acts on the remote copy of the dataformat',
is_flag=True)
@click.option(
"--remote", help="Only acts on the remote copy of the dataformat", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
'''Lists all the dataformats available on the platform
"""Lists all the dataformats available on the platform
Example:
$ beat dataformats list --remote
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.display_remote_list(webapi, 'dataformat')
else:
return common.display_local_list(ctx.meta['config'].path, 'dataformat')
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "dataformat")
else:
return common.display_local_list(ctx.meta["config"].path, "dataformat")
@dataformats.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 dataformats files
"""Displays local path of dataformats files
Example:
$ beat dataformats path xxx
'''
return common.display_local_path(ctx.meta['config'].path, 'dataformat', names)
"""
return common.display_local_path(ctx.meta["config"].path, "dataformat", names)
@dataformats.command()
@click.argument('name', nargs=1)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def edit(ctx, name):
'''Edit local dataformat file
"""Edit local dataformat file
Example:
$ beat df edit xxx
'''
return common.edit_local_file(ctx.meta['config'].path,
ctx.meta['config'].editor, 'dataformat',
name)
"""
return common.edit_local_file(
ctx.meta["config"].path, ctx.meta["config"].editor, "dataformat", name
)
@dataformats.command()
@click.argument('names', nargs=-1)
@click.argument("names", nargs=-1)
@click.pass_context
@raise_on_error
def check(ctx, names):
'''Checks a local dataformat for validity
"""Checks a local dataformat for validity
Example:
$ beat dataformats check xxx
'''
return common.check(ctx.meta['config'].path, 'dataformat', names)
"""
return common.check(ctx.meta["config"].path, "dataformat", names)
@dataformats.command()
@click.argument('name', nargs=-1)
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.argument("name", nargs=-1)
@click.option(
"--force", help="Performs operation regardless of conflicts", is_flag=True
)
@click.pass_context
@raise_on_error
def pull(ctx, name, force):
'''Downloads the specified dataformats from the server
"""Downloads the specified dataformats from the server
Example:
$ beat dataformats pull --force yyy
'''
with common.make_webapi(ctx.meta['config']) as webapi:
name = common.make_up_remote_list(webapi, 'dataformat', name)
if name is None:
return 1 #error
return pull_impl(webapi, ctx.meta['config'].path, name,force, 0, {})
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
name = common.make_up_remote_list(webapi, "dataformat", name)
if name is None:
return 1 # error
return pull_impl(webapi, ctx.meta["config"].path, name, force, 0, {})
@dataformats.command()
@click.argument('name', 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("name", 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, name, force, dry_run):
'''Uploads dataformats to the server
"""Uploads dataformats to the server
Example:
$ beat dataformats push --dry-run yyy
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.push(
webapi, ctx.meta['config'].path, 'dataformat',
name, ['name', 'declaration', 'description'], {},
force, dry_run, 0
)
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.push(
webapi,
ctx.meta["config"].path,
"dataformat",
name,
["name", "declaration", "description"],
{},
force,
dry_run,
0,
)
@dataformats.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 dataformat and the remote version
"""Shows changes between the local dataformat and the remote version
Example:
$ beat dataformats diff xxx
'''
with common.make_webapi(ctx.meta.get('config')) as webapi:
return common.diff(webapi, ctx.meta.get('config').path, 'dataformat',
name, ['declaration', 'description'])
"""
with common.make_webapi(ctx.meta.get("config")) as webapi:
return common.diff(
webapi,
ctx.meta.get("config").path,
"dataformat",
name,
["declaration", "description"],
)
@dataformats.command()
@click.pass_context
@raise_on_error
def status(ctx):
'''Shows (editing) status for all available dataformats
"""Shows (editing) status for all available dataformats
Example:
$ beat dataformats status
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return common.status(webapi, ctx.meta['config'].path, 'dataformat')[0]
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.status(webapi, ctx.meta["config"].path, "dataformat")[0]
@dataformats.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 dataformat
"""Creates a new local dataformat
Example:
$ beat dataformats create xxx
'''
return common.create(ctx.meta['config'].path, 'dataformat', names)
"""
return common.create(ctx.meta["config"].path, "dataformat", names)
@dataformats.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 dataformat
"""Creates a new version of an existing dataformat
Example:
$ beat dataformats version xxx
'''
return common.new_version(ctx.meta['config'].path, 'dataformat', name)
"""
return common.new_version(ctx.meta["config"].path, "dataformat", name)
@dataformats.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 dataformat
"""Forks a local dataformat
Example:
$ beat dataformats fork xxx yyy
'''
return common.fork(ctx.meta['config'].path, 'dataformat', src, dst)
"""
return common.fork(ctx.meta["config"].path, "dataformat", src, dst)
@dataformats.command()
@click.argument('name', nargs=-1)
@click.option('--remote', help='Only acts on the remote copy of the dataformat',
is_flag=True)
@click.argument("name", nargs=-1)
@click.option(
"--remote", help="Only acts on the remote copy of the dataformat", is_flag=True
)
@click.pass_context
@raise_on_error
def rm(ctx, name, remote):
'''Deletes a local dataformat (unless --remote is specified)
"""Deletes a local dataformat (unless --remote is specified)
Example:
$ beat dataformats rm xxx
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.delete_remote(webapi, 'dataformat', name)
else:
return common.delete_local(ctx.meta['config'].path, 'dataformat', name)
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.delete_remote(webapi, "dataformat", name)
else:
return common.delete_local(ctx.meta["config"].path, "dataformat", name)
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