refinements in output of sugar-control

This commit is contained in:
Simon Schampijer 2007-11-01 12:37:43 +01:00
parent a579adef44
commit 70079de872
2 changed files with 35 additions and 13 deletions

View File

@ -19,6 +19,7 @@
import sys import sys
import getopt import getopt
from gettext import gettext as _
from sugar import env from sugar import env
@ -27,18 +28,19 @@ sys.path.insert(0, env.get_shell_path())
from controlpanel import control from controlpanel import control
def cmd_help(): def cmd_help():
print 'Usage: sugar-control [ option ] key [ args ... ] \n\ print _('Usage: sugar-control-panel [ option ] key [ args ... ] \n\
Control for the sugar environment. \n\ Control for the sugar environment. \n\
Options: \n\ Options: \n\
-h, --help show this help message and exit \n\ -h show this help message and exit \n\
-l list all the available options \n\
-h key show information about this key \n\ -h key show information about this key \n\
-g key get the current value of the key \n\ -g key get the current value of the key \n\
-s key set the current value for the key \n\ -s key set the current value for the key \n\
' ')
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "h:s:g:", ["help"]) opts, args = getopt.getopt(sys.argv[1:], "h:s:g:l", [])
except getopt.GetoptError: except getopt.GetoptError:
cmd_help() cmd_help()
sys.exit(2) sys.exit(2)
@ -46,31 +48,40 @@ def main():
output = None output = None
verbose = False verbose = False
if not opts:
cmd_help()
sys.exit()
for opt, key in opts: for opt, key in opts:
if opt in ("-h"): if opt in ("-h"):
method = getattr(control, 'set_' + key, None) method = getattr(control, 'set_' + key, None)
if method is None: if method is None:
cmd_help() print _("sugar-control-panel: key=%s not an available option"% key)
sys.exit() sys.exit()
else: else:
print method.__doc__ print method.__doc__
if opt in ("-l"):
elems = dir(control)
for elem in elems:
if elem.startswith('set_'):
print elem[4:]
if opt in ("-g"): if opt in ("-g"):
method = getattr(control, 'print_' + key, None) method = getattr(control, 'print_' + key, None)
if method is None: if method is None:
cmd_help() print _("sugar-control-panel: key=%s not an available option"% key)
sys.exit() sys.exit()
else: else:
method() method()
if opt in ("-s"): if opt in ("-s"):
method = getattr(control, 'set_' + key, None) method = getattr(control, 'set_' + key, None)
if method is None: if method is None:
cmd_help() print _("sugar-control-panel: key=%s not an available option"% key)
sys.exit() sys.exit()
else: else:
try: try:
method(*args) method(*args)
except Exception, e: except Exception, e:
print "sugar-control: %s"% e print _("sugar-control-panel: %s"% e)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -236,13 +236,24 @@ def print_color():
color = get_color().to_string() color = get_color().to_string()
str = color.split(',') str = color.split(',')
stroke = None
fill = None
for color in _COLORS: for color in _COLORS:
for hue in _COLORS[color]: for hue in _COLORS[color]:
if _COLORS[color][hue] == str[0]: if _COLORS[color][hue] == str[0]:
print 'stroke: color=%s hue=%s'%(color, hue) stroke = (color, hue)
if _COLORS[color][hue] == str[1]: if _COLORS[color][hue] == str[1]:
print 'fill: color=%s hue=%s'%(color, hue) fill = (color, hue)
if stroke is not None:
print 'stroke: color=%s hue=%s'%(stroke[0], stroke[1])
else:
print 'stroke: %s'%(str[0])
if fill is not None:
print 'fill: color=%s hue=%s'%(fill[0], fill[1])
else:
print 'fill: %s'%(str[1])
def set_color(stroke, fill, modstroke='medium', modfill='medium'): def set_color(stroke, fill, modstroke='medium', modfill='medium'):
"""Set the system color by setting a fill and stroke color. """Set the system color by setting a fill and stroke color.
fill : [red, orange, yellow, blue, purple] fill : [red, orange, yellow, blue, purple]
@ -343,9 +354,9 @@ def get_timezone():
timezone = string.replace(tokens[1], '"', '') timezone = string.replace(tokens[1], '"', '')
return timezone return timezone
except Exception, e: except Exception, e:
print (_("get_timezone: %s") % e) print "get_timezone: %s"% e
except Exception, e: except Exception, e:
print (_("get_timezone: %s") % e) print "get_timezone: %s"% e
return None return None
def print_timezone(): def print_timezone():