Skip to content
Snippets Groups Projects
Commit cd52efdf authored by Seblu's avatar Seblu
Browse files

tagdisplay command

parent 4948c191
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ settings = {
"timeout": "30",
"hsize": "100",
"alias": "%s/alias"%BaseDirectory.save_config_path(cccli.canonical_name),
"tag": "%s/tag"%BaseDirectory.save_config_path(cccli.canonical_name),
"tagdisplay": "%s/tagdisplay"%BaseDirectory.save_config_path(cccli.canonical_name),
"history": "%s/history"%BaseDirectory.save_data_path(cccli.canonical_name),
"expert": "%s/expert"%BaseDirectory.save_data_path(cccli.canonical_name),
}
......
......@@ -62,7 +62,7 @@ class Cli(object):
self.alias.load(self.settings.get("alias", ""))
self.printer.debug("Loaded aliases: %d"%len(self.alias))
# load tagdisplay
self.tagdisplay.load(self.settings.get("tag", ""))
self.tagdisplay.load(self.settings.get("tagdisplay", ""))
# connecting
self._connect()
# auth
......
......@@ -19,3 +19,4 @@ from cccli.command.vm import *
from cccli.command.list import Command_list
from cccli.command.expert import Command_expert
from cccli.command.server import Command_server
from cccli.command.tagdisplay import Command_tagdisplay
......@@ -14,6 +14,9 @@ class Command(object):
self.printer = self.cli.printer
self.name = argv0
def __call__(self, argv):
raise NotImplementedError
def usage(self):
return "Usage: %s"%self.name
......@@ -27,6 +30,9 @@ class OptionCommand(Command):
Command.__init__(self, cli, argv0)
self.option = OptionParser(prog=argv0)
def __call__(self, argv):
raise NotImplementedError
def usage(self):
return self.option.format_help().strip()
......
......@@ -25,7 +25,6 @@ class Command_server(OptionCommand):
(options, args) = self.option.parse_args(argv[1:])
except SystemExit:
return
print dir(options)
if len(args) > 0 or (not options.cache and not options.commands):
self.printer.out(self.usage())
return
......
#!/usr/bin/env python
#coding=utf8
'''
CloudControl tagdisplay command
'''
from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import OptionCommand
class Command_tagdisplay(OptionCommand):
'''Tagdisplay tool'''
def __init__(self, cli, argv0):
OptionCommand.__init__(self, cli, argv0)
self.option.set_usage("%prog [options] [tag] ...")
self.option.add_option("-c", action="store", dest="setcolor",
help="Set color SETCOLOR to tags")
self.option.add_option("-t", action="store", dest="settype",
help="Set type SETTYPE to tags")
self.option.add_option("-C", action="store_true", dest="delcolor",
help="Remove custom tags color")
self.option.add_option("-T", action="store_true", dest="deltype",
help="Remove custom tags type")
self.option.add_option("--list-colors", action="store_true", dest="listcolor",
help="List allowed color")
self.option.add_option("--list-types", action="store_true", dest="listtype",
help="List allowed types")
def __call__(self, argv):
try:
(options, args) = self.option.parse_args(argv[1:])
except SystemExit:
return
if options.listcolor:
self.list("color")
elif options.listtype:
self.list("type")
elif len(args) > 0 and options.setcolor:
self.set("color", args, options.setcolor)
elif len(args) > 0 and options.delcolor:
self.set("color", args, None)
elif len(args) > 0 and options.settype:
self.set("type", args, options.settype)
elif len(args) > 0 and options.deltype:
self.set("type", args, None)
elif len(args) == 0:
self.list("my")
else:
self.printer.out(self.usage())
def list(self, what):
'''List displaytag information'''
if what == "color":
self.printer.out("%sTag allowed colors:%s"%(color["lblue"], color["reset"]))
for c in color.keys():
if c.isalpha():
self.printer.out(c)
elif what == "type":
self.printer.out("%sTag allowed types:%s"%(color["lblue"], color["reset"]))
for t in self.cli.tagdisplay.types:
self.printer.out(t)
elif what == "my":
self.printer.out("%sMy tagdisplay colors:%s"%(color["lblue"], color["reset"]))
for (u,v) in self.cli.tagdisplay.tagcolor.items():
self.printer.out("%s: %s"%(u,v))
self.printer.out("%sMy tagdisplay types:%s"%(color["lblue"], color["reset"]))
for (u,v) in self.cli.tagdisplay.tagtype.items():
self.printer.out("%s: %s"%(u,v))
else:
raise AttributeError
def set(self, what, tags, value):
'''Set displaytag info'''
# crazy gard
if not len(tags) > 0:
return
# set appropriate database
if what == "color":
db = self.cli.tagdisplay.tagcolor
vdb = [ c for c in color.keys() if c.isalpha() ]
elif what == "type":
db = self.cli.tagdisplay.tagtype
vdb = self.cli.tagdisplay.types
else:
raise AttributeError
# check attribute
if value is not None and value not in vdb:
self.printer.error("Invalid value: %s"%value)
return
# update db
for tagname in tags:
if value is None:
if tagname in db:
del db[tagname]
else:
db[tagname] = value
self.cli.tagdisplay.save(self.cli.settings.get("tagdisplay", ""))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment