Commit c9ca1c80 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[all_packages/common] adding --edit option

parent 5a4a06a3
......@@ -30,6 +30,7 @@
%(prog)s algorithms list [--remote]
%(prog)s algorithms check [<name>]...
%(prog)s algorithms path [<name>]...
%(prog)s algorithms edit <name>...
%(prog)s algorithms pull [--force] [<name>]...
%(prog)s algorithms push [--force] [--dry-run] [<name>]...
%(prog)s algorithms diff <name>
......@@ -46,6 +47,7 @@
Commands:
list Lists all the algorithms available on the platform
path Displays local path of algorithm files
edit Edit local algorithm file
check Checks a local algorithm for validity
pull Downloads the specified algorithms from the server
push Uploads algorithms to the server
......@@ -356,6 +358,9 @@ def process(args):
elif args['path']:
return common.display_local_path(args['config'].path, 'algorithm', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, 'algorithm', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'algorithm', args['<name>'])
......
......@@ -526,6 +526,73 @@ def display_local_path(prefix, type, names):
return 0
def edit_local_file(prefix, type, name):
'''Implements the local "path" command
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
'''
selected_type = None
if type not in NOSTORAGE:
try:
selected_type = TYPE_PLURAL[type]
except:
logger.error("Selected type is not valid: %s"%type)
return 1
else:
selected_type = TYPE_NOSTORAGE[type]
python_objects = ["database", "library", "algorithm", "plotter"]
json_objects = ["dataformat", "toolchain", "experiment", "plotterparameter"]
ext = None
if type in python_objects:
ext = ".py"
elif type in json_objects:
ext = ".json"
else:
logger.error("Selected type is not valid: %s"%type)
root = os.path.join(prefix, selected_type)
object_path = os.path.join(root, name + ext)
try:
if os.path.isfile(object_path):
# check if editor set
if len(os.environ['VISUAL']) > 0:
editor = os.environ['VISUAL']
elif len(os.environ['EDITOR']) > 0:
editor = os.environ['EDITOR']
else:
logger.error("No default editor set in your environment variable")
return 1
logger.info("Editing object of type '%s' and name '%s':", selected_type, name)
cmd = "%s %s"%(editor, object_path)
os.system(cmd)
else:
logger.error("Not a valid file: %s"%object_path)
return 1
except:
logger.error("File does not exist: %s"%object_path)
return 1
return 0
def make_webapi(c):
'''Instantiates an usable web-api proxy using the command-line configuration
......
......@@ -29,6 +29,7 @@
"""Usage:
%(prog)s databases list [--remote]
%(prog)s databases path [<name>]...
%(prog)s databases edit <name>...
%(prog)s databases check [<name>]...
%(prog)s databases pull [--force] [<name>]...
%(prog)s databases push [--force] [--dry-run] [<name>]...
......@@ -48,6 +49,7 @@ Arguments:
Commands:
list Lists all the databases available on the platform
path Displays local path of databases files
edit Edit local database file
check Checks a local database for validity
pull Downloads the specified databases from the server
push Uploads databases to the server (must provide a valid admin token)
......@@ -645,6 +647,9 @@ def process(args):
elif args['path']:
return common.display_local_path(configuration.path, 'database', db_names)
elif args['edit']:
return common.edit_local_file(configuration.path, 'database', db_names[0])
elif args['check']:
return common.check(configuration.path, 'database', db_names)
......
......@@ -29,6 +29,7 @@
"""Usage:
%(prog)s dataformats list [--remote]
%(prog)s dataformats path [<name>]...
%(prog)s dataformats edit <name>...
%(prog)s dataformats check [<name>]...
%(prog)s dataformats pull [--force] [<name>]...
%(prog)s dataformats push [--force] [--dry-run] [<name>]...
......@@ -44,6 +45,7 @@
Commands:
list Lists all the dataformats available on the platform
path Displays local path of dataformats files
edit Edit local dataformat file
check Checks a local dataformat for validity
pull Downloads the specified dataformats from the server
push Uploads dataformats to the server
......@@ -156,6 +158,9 @@ def process(args):
elif args['path']:
return common.display_local_path(args['config'].path, 'dataformat', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, 'dataformat', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'dataformat', args['<name>'])
......
......@@ -32,6 +32,7 @@
%(prog)s experiments list [--remote]
%(prog)s experiments check [<name>]...
%(prog)s experiments path [<name>]...
%(prog)s experiments edit <name>...
%(prog)s experiments pull [--force] [<name>]...
%(prog)s experiments push [--force] [--dry-run] [<name>]...
%(prog)s experiments diff <name>
......@@ -48,6 +49,7 @@ Commands:
caches Lists all cache files used by this experiment
list Lists all the experiments available on the platform
path Displays local path of experiments files
edit Edit local experiment file
check Checks a local experiment for validity
pull Downloads the specified experiments from the server
push Uploads experiments to the server
......@@ -603,6 +605,9 @@ def process(args):
elif args['path']:
return common.display_local_path(config.path, 'experiment', names)
elif args['edit']:
return common.edit_local_file(config.path, 'experiment', names[0])
elif args['check']:
return common.check(config.path, 'experiment', names)
......
......@@ -29,6 +29,7 @@
"""Usage:
%(prog)s libraries list [--remote]
%(prog)s libraries path [<name>]...
%(prog)s libraries edit <name>...
%(prog)s libraries check [<name>]...
%(prog)s libraries pull [--force] [<name>]...
%(prog)s libraries push [--force] [--dry-run] [<name>]...
......@@ -44,6 +45,7 @@
Commands:
list Lists all the libraries available on the platform
path Displays local path of libraries files
edit Edit local library file
check Checks a local library for validity
pull Downloads the specified libraries from the server
push Uploads libraries to the server
......@@ -151,6 +153,9 @@ def process(args):
elif args['path']:
return common.display_local_path(args['config'].path, 'library', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, 'library', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'library', args['<name>'])
......
......@@ -29,6 +29,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>...
......@@ -41,6 +42,7 @@
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
......@@ -118,6 +120,9 @@ def process(args):
elif args['path']:
return common.display_local_path(args['config'].path, 'plotterparameter', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, 'plotterparameter', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'plotterparameter', args['<name>'])
......
......@@ -29,6 +29,7 @@
"""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>]...
......@@ -42,6 +43,7 @@
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
......@@ -283,6 +285,9 @@ def process(args):
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, 'plotter', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'plotter', args['<name>'])
......
......@@ -29,6 +29,7 @@
"""Usage:
%(prog)s toolchains list [--remote]
%(prog)s toolchains path [<name>]...
%(prog)s toolchains edit <name>...
%(prog)s toolchains check [<name>]...
%(prog)s toolchains pull [--force] [<name>]...
%(prog)s toolchains push [--force] [--dry-run] [<name>]...
......@@ -45,6 +46,7 @@
Commands:
list Lists all the toolchains available on the platform
path Displays local path of toolchains files
edit Edit local toolchain file
check Checks a local toolchain for validity
pull Downloads the specified toolchains from the server
push Uploads toolchains to the server
......@@ -81,6 +83,9 @@ def process(args):
elif args['path']:
return common.display_local_path(args['config'].path, 'toolchain', args['<name>'])
elif args['edit']:
return common.edit_local_file(args['config'].path, 'toolchain', args['<name>'][0])
elif args['check']:
return common.check(args['config'].path, 'toolchain', args['<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