Package mrv :: Package cmd :: Module spcmd
[hide private]
[frames] | no frames]

Source Code for Module mrv.cmd.spcmd

 1  #!/usr/bin/env python 
 2  __docformat__ = "restructuredtext" 
 3  import sys 
 4   
 5   
6 -def main(args):
7 """Run the spawned command 8 :param args: arguments excluding the executable path""" 9 if len(args) < 1: 10 raise Exception("Invalid Arguments, call command as follows:\nspcmd package.module.ServerClassName [additional options for execute method]") 11 12 # needs that order as paths will be adjusted here 13 try: 14 tokens = args[0].split('.') 15 args = args[1:] # remaining args 16 module, classname = ".".join(tokens[:-1]), tokens[-1] 17 module = __import__(module, globals(), locals(), [module]) 18 cmdtype = getattr(module, classname) 19 20 cmdinstance = cmdtype(_spawned=True) 21 22 # EXECUTE FUNCTION 23 found = False 24 try: 25 func = getattr(cmdinstance, '_execute') 26 found = True 27 func(*args) 28 except AttributeError,e: 29 raise 30 except Exception, e: 31 import logging 32 # all other exceptions should result in some red blinking light 33 logging.critical("Unhandled Exception", exc_info=True) 34 raise
35 36 # END main 37 38 if __name__ == '__main__': 39 main(sys.argv[1:]) 40