Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/commands.py
Show All 39 Lines | for commands_path, dirnames, filenames in os.walk(commands_base_path): | ||||
continue | continue | ||||
for filename in filenames: | for filename in filenames: | ||||
if filename.startswith('cmd_') and filename.endswith('.py'): | if filename.startswith('cmd_') and filename.endswith('.py'): | ||||
module_name = filename.replace('.py','') | module_name = filename.replace('.py','') | ||||
cmd_name = module_name.replace('cmd_', '') | cmd_name = module_name.replace('cmd_', '') | ||||
#print "exec(\"from %s import __init__ as %s_register\"" % (module_name,cmd_name) | #print "exec(\"from %s import __init__ as %s_register\"" % (module_name,cmd_name) | ||||
try: | try: | ||||
exec("from %s import __init__ as %s_register" % (module_name,cmd_name)) | exec("from .%s import __init__ as %s_register" % (module_name,cmd_name)) | ||||
except ImportError: | except ImportError: | ||||
pass | pass | ||||
exec("%s_register()" % (cmd_name)) | exec("%s_register()" % (cmd_name)) | ||||
for dirname in dirnames: | for dirname in dirnames: | ||||
register_group(commands_path, dirname) | register_group(commands_path, dirname) | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if 'function' not in commands[cmd_name] and \ | ||||
'group' not in commands[cmd_name]: | 'group' not in commands[cmd_name]: | ||||
log.error(_("No such command.")) | log.error(_("No such command.")) | ||||
sys.exit(1) | sys.exit(1) | ||||
if 'group' in commands[cmd_name]: | if 'group' in commands[cmd_name]: | ||||
group = commands[cmd_name]['group'] | group = commands[cmd_name]['group'] | ||||
command_name = commands[cmd_name]['cmd_name'] | command_name = commands[cmd_name]['cmd_name'] | ||||
try: | try: | ||||
exec("from %s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name)) | exec("from .%s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name)) | ||||
exec("%s_%s_cli_options()" % (group,command_name)) | exec("%s_%s_cli_options()" % (group,command_name)) | ||||
except ImportError: | except ImportError: | ||||
pass | pass | ||||
else: | else: | ||||
command_name = commands[cmd_name]['cmd_name'] | command_name = commands[cmd_name]['cmd_name'] | ||||
try: | try: | ||||
exec("from cmd_%s import cli_options as %s_cli_options" % (command_name,command_name)) | exec("from cmd_%s import cli_options as %s_cli_options" % (command_name,command_name)) | ||||
Show All 13 Lines | for commands_path, dirnames, filenames in os.walk(commands_base_path): | ||||
if not commands_path == commands_base_path: | if not commands_path == commands_base_path: | ||||
continue | continue | ||||
for filename in filenames: | for filename in filenames: | ||||
if filename.startswith('cmd_') and filename.endswith('.py'): | if filename.startswith('cmd_') and filename.endswith('.py'): | ||||
module_name = filename.replace('.py','') | module_name = filename.replace('.py','') | ||||
cmd_name = module_name.replace('cmd_', '') | cmd_name = module_name.replace('cmd_', '') | ||||
#print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,cmd_name) | #print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,cmd_name) | ||||
exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name)) | exec("from .%s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name)) | ||||
exec("%s_%s_register()" % (module,cmd_name)) | exec("%s_%s_register()" % (module,cmd_name)) | ||||
def register(cmd_name, func, group=None, description=None, aliases=[]): | def register(cmd_name, func, group=None, description=None, aliases=[]): | ||||
if not group == None: | if not group == None: | ||||
command = "%s_%s" % (group,cmd_name) | command = "%s_%s" % (group,cmd_name) | ||||
else: | else: | ||||
command = cmd_name | command = cmd_name | ||||
Show All 39 Lines |