Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/commands.py
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | def list_commands(*args, **kw): | ||||
for _command in _commands: | for _command in _commands: | ||||
if __commands[_command].has_key('group'): | if __commands[_command].has_key('group'): | ||||
continue | continue | ||||
if __commands[_command].has_key('function'): | if __commands[_command].has_key('function'): | ||||
# This is a top-level command | # This is a top-level command | ||||
if not __commands[_command]['description'] == None: | if not __commands[_command]['description'] == None: | ||||
print "%-25s - %s" % (_command.replace('_','-'),__commands[_command]['description']) | print("%-25s - %s" % (_command.replace('_','-'),__commands[_command]['description'])) | ||||
else: | else: | ||||
print "%-25s" % (_command.replace('_','-')) | print("%-25s" % (_command.replace('_','-'))) | ||||
for _command in _commands: | for _command in _commands: | ||||
if not __commands[_command].has_key('function'): | if not __commands[_command].has_key('function'): | ||||
# This is a nested command | # This is a nested command | ||||
print "\n" + _("Command Group: %s") % (_command) + "\n" | print("\n" + _("Command Group: %s") % (_command) + "\n") | ||||
___commands = __commands[_command].keys() | ___commands = __commands[_command].keys() | ||||
___commands.sort() | ___commands.sort() | ||||
for __command in ___commands: | for __command in ___commands: | ||||
if not __commands[_command][__command]['description'] == None: | if not __commands[_command][__command]['description'] == None: | ||||
print "%-4s%-21s - %s" % ('',__command.replace('_','-'),__commands[_command][__command]['description']) | print("%-4s%-21s - %s" % ('',__command.replace('_','-'),__commands[_command][__command]['description'])) | ||||
else: | else: | ||||
print "%-4s%-21s" % ('',__command.replace('_','-')) | print("%-4s%-21s" % ('',__command.replace('_','-'))) | ||||
def execute(cmd_name, *args, **kw): | def execute(cmd_name, *args, **kw): | ||||
if cmd_name == "": | if cmd_name == "": | ||||
execute("help") | execute("help") | ||||
sys.exit(0) | sys.exit(0) | ||||
if not commands.has_key(cmd_name): | if not commands.has_key(cmd_name): | ||||
log.error(_("No such command.")) | log.error(_("No such command.")) | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | if callable(func): | ||||
'description': _("Alias for %s") % (cmd_name.replace('_','-')) | 'description': _("Alias for %s") % (cmd_name.replace('_','-')) | ||||
} | } | ||||
## | ## | ||||
## Commands not yet implemented | ## Commands not yet implemented | ||||
## | ## | ||||
def not_yet_implemented(*args, **kw): | def not_yet_implemented(*args, **kw): | ||||
print _("Not yet implemented") | print(_("Not yet implemented")) | ||||
sys.exit(1) | sys.exit(1) |