diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-14 18:25:28 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-14 18:25:28 -0500 |
commit | 3e5823d0985a54dec37f103dc72fda604d12a948 (patch) | |
tree | 251c6f9f53522bf92991783a1f69ac350a6e9cd8 /libbe/command/base.py | |
parent | d8a698ffff676ef4a222d2dbeb5fe304901521a0 (diff) | |
download | bugseverywhere-3e5823d0985a54dec37f103dc72fda604d12a948.tar.gz |
Transitioned import_xml to Command-format
Diffstat (limited to 'libbe/command/base.py')
-rw-r--r-- | libbe/command/base.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/libbe/command/base.py b/libbe/command/base.py index e28cf33..fe29908 100644 --- a/libbe/command/base.py +++ b/libbe/command/base.py @@ -37,6 +37,21 @@ def get_command(command_name): raise UnknownCommand(command_name) return cmd +def get_command_class(module, command_name): + """Retrieves a command class from a module. + + >>> import_xml_mod = get_command('import-xml') + >>> import_xml = get_command_class(import_xml_mod, 'import-xml') + >>> repr(import_xml) + "<class 'libbe.command.import_xml.Import_XML'>" + """ + try: + cname = command_name.capitalize().replace('-', '_') + cmd = getattr(module, cname) + except ImportError, e: + raise UnknownCommand(command_name) + return cmd + def commands(): for modname in libbe.util.plugin.modnames('libbe.command'): if modname not in ['base', 'util']: @@ -76,13 +91,13 @@ class Option (CommandInput): def validate(self): if self.arg == None: - assert self.callback != None + assert self.callback != None, self.name return - assert self.callback == None, self.callback + assert self.callback == None, '%s: %s' (self.name, self.callback) assert self.arg.name == self.name, \ 'Name missmatch: %s != %s' % (self.arg.name, self.name) - assert self.arg.optional == False - assert self.arg.repeatable == False + assert self.arg.optional == False, self.name + assert self.arg.repeatable == False, self.name def __str__(self): return '--%s' % self.name |