Beispiel #1
0
 def run(self):
     options, args = self.parser.parse_args()
     #the following so that command line options are made available
     #to the decorated function as **kwargs
     self._updatekwargs(self.parser.values.__dict__)
     logargs = (
             self.kwargs.get(OPTLOGFILE, None),
             self.kwargs.get(OPTLOGDIR, None),
             self.kwargs.get(OPTLOGPREFIX, ''),
             )
     self.kwargs[OPTLOGFILE] = logstart(*logargs)
     log.info("SCRIPT: " + sys.argv[0])
     conf = self.kwargs.get(OPTCONFIG, None)
     if conf:
         log.info("%s: %s" % (OPTCONFIG.upper(), conf.filename))
     for k,v in self.kwargs.iteritems():
         if v and k not in COMMONOPTNAMES:
             log.info("%s = %s" % (k, v))
     log.divider()
     try:
         self.func(*self.args, **self.kwargs)
     except Exception, e:
         log.exception(str(e))
         log.info("Logfile: " + self.kwargs[OPTLOGFILE])
         sys.exit(1)
Beispiel #2
0
 def inner(config, logfile, *args):
     if isinstance(config, str):
         conf_file = config
         config = ConfigParser()
         config.readfp(open(conf_file))
     logger.start(logfile=logfile)
     sourcefile = inspect.getabsfile(main)
     logger.info('*** Starting logger ***')
     logger.info('*** Running file %s ***' % sourcefile)
     try:
         main(config, logfile, *args)
     except:
         logger.exception("Unexpected Error.")
     logger.info('*** Leaving file %s ***' % sourcefile)
     logger.info('*** Stopping logger ***')
     logger.end()