add rename command to rename storage

pull/6/head
deadc0de6 7 years ago
parent 52c74b76f3
commit 2e5424a337

@ -35,12 +35,13 @@ USAGE = """
{0}
Usage:
{1} index [--catalog=<path>] [--meta=<meta>...] [-fcuV] <name> <path>
{1} ls [--catalog=<path>] [-rV] [<path>]
{1} find [--catalog=<path>] [-sV] <term>
{1} rm [--catalog=<path>] [-fV] <storage>
{1} tree [--catalog=<path>] [-V] [<path>]
{1} graph [--catalog=<path>] [-V] [<path>]
{1} index [--catalog=<path>] [--meta=<meta>...] [-fcuV] <name> <path>
{1} ls [--catalog=<path>] [-rV] [<path>]
{1} find [--catalog=<path>] [-sV] <term>
{1} rm [--catalog=<path>] [-fV] <storage>
{1} tree [--catalog=<path>] [-V] [<path>]
{1} rename [--catalog=<path>] [-fV] <storage> <name>
{1} graph [--catalog=<path>] [-V] [<path>]
{1} help
{1} --help
{1} --version
@ -104,6 +105,7 @@ def cmd_rm(args, noder, catalog, top):
node = next(filter(lambda x: x.name == what, top.children))
node.parent = None
catalog.save(top)
Logger.info('Storage \"{}\" removed'.format(what))
else:
Logger.err('Storage named \"{}\" does not exist'.format(what))
return top
@ -130,6 +132,20 @@ def cmd_graph(args, noder, top):
Logger.info('create graph with \"{}\" (you need graphviz)'.format(cmd))
def cmd_rename(args, noder, catalog, top):
storage = args['<storage>']
new = args['<name>']
storages = list(x.name for x in top.children)
if storage in storages:
node = next(filter(lambda x: x.name == storage, top.children))
node.name = new
catalog.save(top)
Logger.info('Storage \"{}\" renamed to \"{}\"'.format(storage, new))
else:
Logger.err('Storage named \"{}\" does not exist'.format(storage))
return top
def banner():
Logger.log(BANNER)
Logger.log("")
@ -172,6 +188,8 @@ def main():
cmd_rm(args, noder, catalog, top)
elif args['graph']:
cmd_graph(args, noder, top)
elif args['rename']:
cmd_rename(args, noder, catalog, top)
return True

Loading…
Cancel
Save