aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command/base.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-14 18:25:28 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-14 18:25:28 -0500
commit3e5823d0985a54dec37f103dc72fda604d12a948 (patch)
tree251c6f9f53522bf92991783a1f69ac350a6e9cd8 /libbe/command/base.py
parentd8a698ffff676ef4a222d2dbeb5fe304901521a0 (diff)
downloadbugseverywhere-3e5823d0985a54dec37f103dc72fda604d12a948.tar.gz
Transitioned import_xml to Command-format
Diffstat (limited to 'libbe/command/base.py')
-rw-r--r--libbe/command/base.py23
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