Commit 97d8fe73 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

[plotterparameters] Click implementation of plotters commands

Reimplement plotterparameters existing
commands using  plugin-based command line mechanism (Click).
parent 913d2e86
......@@ -26,38 +26,7 @@
###############################################################################
"""Usage:
%(prog)s plotterparameters list [--remote]
%(prog)s plotterparameters path [<name>]...
%(prog)s plotterparameters edit <name>...
%(prog)s plotterparameters check [<name>]...
%(prog)s plotterparameters pull [--force] [<name>]...
%(prog)s plotterparameters create <name>...
%(prog)s plotterparameters version <name>
%(prog)s plotterparameters fork <src> <dst>
%(prog)s plotterparameters rm <name>...
%(prog)s plotterparameters --help
Commands:
list Lists all the plotterparameters available locally
path Displays local path of plotterparameters files
edit Edit local plotterparameter file
check Checks a local plotterparameter for validity
pull Downloads the specified plotterparameters from the server
create Creates a new local plotterparameter
version Creates a new version of an existing plotterparameter
fork Forks a local plotterparameter
rm Deletes a local plotterparameter
Options:
--force Performs operation regardless of conflicts
--dry-run Doesn't really perform the task, just comments what would do
--help Display this screen
"""
import click
import simplejson
import collections
from .dataformats import pull as dataformats_pull
......@@ -68,7 +37,7 @@ logger = logging.getLogger(__name__)
from . import common
def pull(webapi, prefix, names, force, indentation, format_cache):
def pull_impl(webapi, prefix, names, force, indentation, format_cache):
"""Copies plotterparameters from the server.
Parameters:
......@@ -105,47 +74,134 @@ def pull(webapi, prefix, names, force, indentation, format_cache):
status, names = common.pull(webapi, prefix, 'plotterparameter', names,
['data', 'short_description', 'plotter'], force,
indentation)
return status
def process(args):
if args['list']:
if args['--remote']:
with common.make_webapi(args['config']) as webapi:
return common.display_remote_list(webapi, 'plotterparameter')
@click.group()
@click.pass_context
def plotterparameters(ctx):
"""Plotterparameters commands"""
pass
@plotterparameters.command()
@click.option('--remote', help='Only acts on the remote copy of the list.',
is_flag=True)
@click.pass_context
def list(ctx, remote):
'''Lists all the plotterparameters available on the platform.
To list all existing plotterparameters on your local prefix:
$ beat plotterparameters list
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.display_remote_list(webapi, 'plotterparameter')
else:
return common.display_local_list(args['config'].path, 'plotterparameter')
return common.display_local_list(ctx.meta['config'].path, 'plotterparameter')
@plotterparameter.command()
@click.argument('names', nargs=-1)
@click.pass_context
def path(ctx, names):
'''Displays local path of plotterparameter files
Example:
$ beat plotterparameters path xxx
'''
return common.display_local_path(ctx.meta['config'].path, 'plotterparameter', names)
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.pass_context
def edit(ctx, name):
'''Edit local plotterparameter file
Example:
$ beat plotterparameter edit xxx
'''
return common.edit_local_file(ctx.meta['config'].path,
ctx.meta['config'].editor, 'plotterparameter',
name)
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.pass_context
def check(ctx, name):
'''Checks a local plotter for validity.
$ beat plotterparameters check xxx
'''
return common.check(ctx.meta['config'].path, 'plotterparameter', name)
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.option('--force', help='Force',
is_flag=True)
@click.pass_context
def pull(ctx, name, force):
'''Downloads the specified plotterparameters from the server.
$ beat plotterparameters pull xxx.
'''
with common.make_webapi(ctx.meta['config']) as webapi:
name = common.make_up_remote_list(webapi, 'plotterparameter', name)
if name is None:
return 1 #error
return pull_impl(webapi, ctx.meta['config'].path, name, force, 0, {})
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.pass_context
def create(ctx, name):
'''Creates a new local plotter.
$ beat plotterparameters create xxx
'''
return common.create(ctx.meta['config'].path, 'plotterparameter', [name])
elif args['path']:
return common.display_local_path(args['config'].path, 'plotterparameter', args['<name>'])
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.pass_context
def version(ctx, name):
'''Creates a new version of an existing plotter.
elif args['edit']:
return common.edit_local_file(args['config'].path, args['config'].editor, 'plotterparameter', args['<name>'][0])
$ beat plotterparameters version xxx
'''
return common.new_version(ctx.meta['config'].path, 'plotterparameter', name)
elif args['check']:
return common.check(args['config'].path, 'plotterparameter', args['<name>'])
elif args['pull']:
with common.make_webapi(args['config']) as webapi:
args['<name>'] = common.make_up_remote_list(webapi, 'plotterparameter',
args['<name>'])
if args['<name>'] is None: return 1 #error
return pull(webapi, args['config'].path, args['<name>'],
args['--force'], 0, {})
@plotterparameters.command()
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.pass_context
def fork(ctx, src, dst):
'''Forks a local plotter.
elif args['create']:
return common.create(args['config'].path, 'plotterparameter', args['<name>'])
$ beat plotterparameters fork xxx yyy
'''
return common.fork(ctx.meta['config'].path, 'plotterparameter', src, dst)
elif args['version']:
return common.new_version(args['config'].path, 'plotterparameter',
args['<name>'][0])
elif args['fork']:
return common.fork(args['config'].path, 'plotterparameter', args['<src>'],
args['<dst>'])
elif args['rm']:
return common.delete_local(args['config'].path, 'plotterparameter', args['<name>'])
@plotterparameters.command()
@click.argument('name', nargs=1)
@click.pass_context
def rm(ctx, name):
'''Deletes a local plotter.
return 1
$ beat plotterparameters rm xxx
'''
return common.delete_local(ctx.meta['config'].path, 'plotterparameter', 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