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): | ||||
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, errmsg: | 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) | ||||
register('help', list_commands) | register('help', list_commands) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if not commands[cmd_name].has_key('function') and \ | ||||
sys.exit(1) | sys.exit(1) | ||||
if commands[cmd_name].has_key('group'): | if commands[cmd_name].has_key('group'): | ||||
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, e: | 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)) | ||||
exec("%s_cli_options()" % (command_name)) | exec("%s_cli_options()" % (command_name)) | ||||
except ImportError, errmsg: | except ImportError: | ||||
pass | pass | ||||
conf.finalize_conf() | conf.finalize_conf() | ||||
commands[cmd_name]['function'](conf.cli_args, kw) | commands[cmd_name]['function'](conf.cli_args, kw) | ||||
def register_group(dirname, module): | def register_group(dirname, module): | ||||
commands_base_path = os.path.join(os.path.dirname(__file__), module) | commands_base_path = os.path.join(os.path.dirname(__file__), module) | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |