Commit 54b35572 authored by Samuel GAIST's avatar Samuel GAIST

[databases] Use raise_on_error decorator for commands

This also cleans up all the sys.exit calls.
parent e6846460
......@@ -26,7 +26,6 @@
###############################################################################
import os
import sys
import click
import glob
import random
......@@ -42,12 +41,13 @@ from beat.core.hash import toPath
from beat.core.hash import hashDataset
from beat.core.utils import NumpyJSONEncoder
from beat.core.database import Database
from beat.core.data import load_data_index, RemoteDataSource
from beat.core.data import RemoteDataSource
from beat.core import dock
from beat.core import inputs
from beat.core import utils
from . import common
from .decorators import raise_on_error
logger = logging.getLogger(__name__)
......@@ -466,7 +466,6 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
# Load the infos about the database set
(db_name, database, sets) = load_database_sets(configuration, dataset_name)
if (database is None) or (len(sets) != 1):
sys.exit(1)
return 1
(protocol_name, set_name, db_set) = sets[0]
......@@ -480,7 +479,6 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
view = database.view(protocol_name, set_name)
if view is None:
sys.exit(1)
return 1
dataset_hash = hashDataset(db_name, protocol_name, set_name)
......@@ -560,10 +558,8 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
except Exception as e:
logger.error("Failed to retrieve the next data: %s", e)
sys.exit(1)
return 1
sys.exit(0)
return 0
......@@ -581,6 +577,7 @@ def databases(ctx):
@click.option('--remote', help='Only acts on the remote copy of the database.',
is_flag=True)
@click.pass_context
@raise_on_error
def list(ctx, remote):
'''Lists all the databases available on the platform.
......@@ -599,6 +596,7 @@ def list(ctx, remote):
@databases.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def path(ctx, names):
'''Displays local path of databases files
......@@ -611,6 +609,7 @@ def path(ctx, names):
@databases.command()
@click.argument('name', nargs=1)
@click.pass_context
@raise_on_error
def edit(ctx, name):
'''Edit local database file
......@@ -626,6 +625,7 @@ def edit(ctx, name):
@databases.command()
@click.argument('db_names', nargs=-1)
@click.pass_context
@raise_on_error
def check(ctx, db_names):
'''Checks a local database for validity.
......@@ -642,6 +642,7 @@ def check(ctx, db_names):
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.pass_context
@raise_on_error
def pull(ctx, db_names, force):
'''Downloads the specified databases from the server.
......@@ -662,6 +663,7 @@ def pull(ctx, db_names, force):
@click.option('--dry-run', help='Dry run',
is_flag=True)
@click.pass_context
@raise_on_error
def push(ctx, db_names, force, dry_run):
'''Uploads databases to the server (must provide a valid admin token).
......@@ -682,6 +684,7 @@ def push(ctx, db_names, force, dry_run):
@databases.command()
@click.argument('db_names', nargs=-1)
@click.pass_context
@raise_on_error
def diff(ctx, db_names):
'''Shows changes between the local database and the remote version.
......@@ -701,6 +704,7 @@ def diff(ctx, db_names):
@databases.command()
@click.pass_context
@raise_on_error
def status(ctx):
'''Shows (editing) status for all available databases'''
configuration = ctx.meta['config']
......@@ -711,6 +715,7 @@ def status(ctx):
@databases.command()
@click.argument('db_names', nargs=-1)
@click.pass_context
@raise_on_error
def version(ctx, db_names):
'''Creates a new version of an existing database.
......@@ -739,6 +744,7 @@ def version(ctx, db_names):
@click.option('--db-root', help="Database root")
@click.option('--docker', is_flag=True)
@click.pass_context
@raise_on_error
def index(ctx, db_names, list, delete, checksum, uid, db_root, docker):
'''Indexes all outputs (of all sets) of a database.
......@@ -763,7 +769,6 @@ def index(ctx, db_names, list, delete, checksum, uid, db_root, docker):
elif checksum:
code = index_outputs(configuration, db_names, uid=uid,
db_root=db_root, docker=docker)
sys.exit(code)
return code
@databases.command()
......@@ -774,6 +779,7 @@ def index(ctx, db_names, list, delete, checksum, uid, db_root, docker):
@click.option('--db-root', help="Database root")
@click.option('--docker', is_flag=True)
@click.pass_context
@raise_on_error
def view(ctx, set_name, exclude, uid, db_root, docker):
'''View the data of the specified dataset.
......
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