Commit 8cd17124 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[plotters] Use raise_on_error decorator for commands

Also cleans up all the sys.exit calls.
parent 852e120a
......@@ -25,25 +25,29 @@
# #
###############################################################################
import io
import os
import sys
import click
import logging
import simplejson
import collections
from PIL import Image
from beat.cmdline.scripts.click_helper import AliasedGroup
from beat.core import plotter
from beat.core import dataformat
from . import common
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
from .decorators import raise_on_error
import logging
logger = logging.getLogger(__name__)
from . import common
from beat.core import plotter
from beat.core import dataformat
def pull_impl(webapi, prefix, names, force, indentation, format_cache):
"""Copies plotters from the server.
......@@ -106,7 +110,6 @@ def pull_impl(webapi, prefix, names, force, indentation, format_cache):
if name == df['plotter']:
plp_status = plotterparameters_pull(webapi, prefix, [df['parameter']], ['data', 'short_description', 'plotter'], force, indentation + 2)
code = status + lb_status + df_status
sys.exit(code)
return code
def plot_impl(webapi, prefix, names, show, force, need_data_sample, inputdata, outputimage, plotterparameter, indentation, format_cache):
......@@ -237,10 +240,8 @@ def plot_impl(webapi, prefix, names, show, force, need_data_sample, inputdata, o
logger.info("%ssaved image `%s'...", indent, output_name)
else:
logger.error("Error: data has not been set")
sys.exit(1)
return 1
sys.exit(0)
return 0
......@@ -257,6 +258,7 @@ def plotters(ctx):
@click.option('--remote', help='Only acts on the remote copy of the list.',
is_flag=True)
@click.pass_context
@raise_on_error
def list(ctx, remote):
'''Lists all the plotters available on the platform.
......@@ -273,6 +275,7 @@ def list(ctx, remote):
@plotters.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def path(ctx, names):
'''Displays local path of plotters files
......@@ -285,6 +288,7 @@ def path(ctx, names):
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
@raise_on_error
def edit(ctx, name):
'''Edit local plotter file
......@@ -299,6 +303,7 @@ def edit(ctx, name):
@plotters.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def check(ctx, names):
'''Checks a local plotter for validity.
......@@ -339,6 +344,7 @@ def pull(ctx, names, force):
@click.option('--output-image', help='<filename.png>')
@click.option('--plotter-parameter', help='<plotterparameter>')
@click.pass_context
@raise_on_error
def plot(ctx, names, show, force, sample_data, input_data, output_image,
plotter_parameter):
'''Plots an image.
......@@ -358,6 +364,7 @@ def plot(ctx, names, show, force, sample_data, input_data, output_image,
@plotters.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def create(ctx, names):
'''Creates a new local plotter.
......@@ -370,6 +377,7 @@ def create(ctx, names):
@plotters.command()
@click.argument('name', nargs=1)
@click.pass_context
@raise_on_error
def version(ctx, name):
'''Creates a new version of an existing plotter.
......@@ -382,6 +390,7 @@ def version(ctx, name):
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.pass_context
@raise_on_error
def fork(ctx, src, dst):
'''Forks a local plotter.
......@@ -394,6 +403,7 @@ def fork(ctx, src, dst):
@plotters.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def rm(ctx, names):
'''Deletes a local plotter.
......
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