Commit 9d5dd648 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

[plotters] Click implementation of plotters commands

Reimplement plotters existing
commands using  plugin-based command line mechanism (Click).
parent c2af4714
......@@ -85,8 +85,8 @@ def pull_impl(webapi, prefix, names, force, indentation, format_cache, lib_cache
"""
from .dataformats import pull as dataformats_pull
from .libraries import pull as libraries_pull
from .dataformats import pull_impl as dataformats_pull
from .libraries import pull_impl as libraries_pull
status, names = common.pull(webapi, prefix, 'algorithm', names,
['declaration', 'code', 'description'], force, indentation)
......
......@@ -25,48 +25,14 @@
# #
###############################################################################
"""Usage:
%(prog)s plotters list [--remote]
%(prog)s plotters path [<name>]...
%(prog)s plotters edit <name>...
%(prog)s plotters check [<name>]...
%(prog)s plotters pull [--force] [<name>]...
%(prog)s plotters plot [--show] [--force] [--sample_data] [--inputdata=<filename.json>] [--outputimage=<filename.png>] [--plotterparameter=<plotterparameter>] [<name>]...
%(prog)s plotters create <name>...
%(prog)s plotters version <name>
%(prog)s plotters fork <src> <dst>
%(prog)s plotters rm <name>...
%(prog)s plotters --help
Commands:
list Lists all the plotters available locally
path Displays local path of plotters files
edit Edit local plotter file
check Checks a local plotter for validity
pull Downloads the specified plotters from the server
plot Plots an image
create Creates a new local plotter
version Creates a new version of an existing plotter
fork Forks a local plotter
rm Deletes a local plotter
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 os
import sys
import click
import simplejson
import collections
from .dataformats import pull as dataformats_pull
from .plotterparameters import pull as plotterparameters_pull
from .libraries import pull as libraries_pull
from .dataformats import pull_impl as dataformats_pull
from .plotterparameters import pull_impl as plotterparameters_pull
from .libraries import pull_impl as libraries_pull
from PIL import Image
import io
......@@ -78,7 +44,7 @@ from beat.core import plotter
from beat.core import dataformat
def pull(webapi, prefix, names, force, indentation, format_cache):
def pull_impl(webapi, prefix, names, force, indentation, format_cache):
"""Copies plotters from the server.
Parameters:
......@@ -141,7 +107,7 @@ def pull(webapi, prefix, names, force, indentation, format_cache):
return status + lb_status + df_status
def plot(webapi, prefix, names, show, force, need_data_sample, inputdata, outputimage, plotterparameter, indentation, format_cache):
def plot_impl(webapi, prefix, names, show, force, need_data_sample, inputdata, outputimage, plotterparameter, indentation, format_cache):
"""plot sample plot from the server.
Parameters:
......@@ -273,51 +239,159 @@ def plot(webapi, prefix, names, show, force, need_data_sample, inputdata, output
return 0
def process(args):
if args['list']:
if args['--remote']:
with common.make_webapi(args['config']) as webapi:
return common.display_remote_list(webapi, 'plotter')
else:
return common.display_local_list(args['config'].path, 'plotter')
elif args['path']:
return common.display_local_path(args['config'].path, 'plotter', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, args['config'].editor, 'plotter', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'plotter', args['<name>'])
elif args['pull']:
with common.make_webapi(args['config']) as webapi:
args['<name>'] = common.make_up_remote_list(webapi, 'plotter',
args['<name>'])
if args['<name>'] is None: return 1 #error
return pull(webapi, args['config'].path, args['<name>'],
args['--force'], 0, {})
@click.group()
@click.pass_context
def plotters(ctx):
"""Plotters commands"""
pass
elif args['plot']:
with common.make_webapi(args['config']) as webapi:
return plot(webapi, args['config'].path, args['<name>'], args['--show'],
args['--force'], args['--sample_data'], args['--inputdata'],
args['--outputimage'], args['--plotterparameter'],
0, {})
elif args['create']:
return common.create(args['config'].path, 'plotter', args['<name>'])
elif args['version']:
return common.new_version(args['config'].path, 'plotter',
args['<name>'][0])
@plotters.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 plotters available on the platform.
elif args['fork']:
return common.fork(args['config'].path, 'plotter', args['<src>'],
args['<dst>'])
To list all existing plotters on your local prefix:
elif args['rm']:
return common.delete_local(args['config'].path, 'plotter', args['<name>'])
return 1
$ beat plotters list
'''
if remote:
with common.make_webapi(ctx.meta['config']) as webapi:
return common.display_remote_list(webapi, 'plotter')
else:
return common.display_local_list(ctx.meta['config'].path, 'plotter')
@plotters.command()
@click.argument('names', nargs=-1)
@click.pass_context
def path(ctx, names):
'''Displays local path of plotters files
Example:
$ beat plotters path xxx
'''
return common.display_local_path(ctx.meta['config'].path, 'plotter', names)
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def edit(ctx, name):
'''Edit local plotter file
Example:
$ beat plotters edit xxx
'''
return common.edit_local_file(ctx.meta['config'].path,
ctx.meta['config'].editor, 'plotter',
name)
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def check(ctx, name):
'''Checks a local plotter for validity.
$ beat plotters check xxx
'''
return common.check(ctx.meta['config'].path, 'plotter', name)
@plotters.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 plotters from the server.
$ beat plotters pull xxx.
'''
with common.make_webapi(ctx.meta['config']) as webapi:
name = common.make_up_remote_list(webapi, 'plotter', name)
if name is None:
return 1 #error
return pull_impl(webapi, ctx.meta['config'].path, name, force, 0, {})
@plotters.command()
@click.argument('name', nargs=1)
@click.option('--show', help='Show...',
is_flag=True)
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.option('--sample-data', help='Sample data...',
is_flag=True)
@click.option('--input-data', help='<filename.json>',
type=click.Path(exists=True))
@click.option('--output-image', help='<filename.png>',
type=click.Path(exists=True))
@click.option('--plotter-parameter', help='<plotterparameter>')
@click.pass_context
def plot(ctx, name, show, force, sample_data, input_data, output_image,
plotter_parameter):
'''Plots an image.
$ beat plotters plot [--show] [--force] [--sample_data] [--inputdata=<filename.json>] [--outputimage=<filename.png>] [--plotterparameter=<plotterparameter>] [<name>]...
'''
with common.make_webapi(ctx.meta['config']) as webapi:
return plot_impl(
webapi, ctx.meta['config'].path, name, show, force, sample_data,
input_data, output_image, plotter_parameter, 0, {}
)
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def create(ctx, name):
'''Creates a new local plotter.
$ beat plotters create xxx
'''
return common.create(ctx.meta['config'].path, 'plotter', [name])
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def version(ctx, name):
'''Creates a new version of an existing plotter.
$ beat plotters version xxx
'''
return common.new_version(ctx.meta['config'].path, 'plotter', name)
@plotters.command()
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.pass_context
def fork(ctx, src, dst):
'''Forks a local plotter.
$ beat plotters fork xxx yyy
'''
return common.fork(ctx.meta['config'].path, 'plotter', src, dst)
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
def rm(ctx, name):
'''Deletes a local plotter.
$ beat plotters rm xxx
'''
return common.delete_local(ctx.meta['config'].path, 'plotter', 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