Exemple #1
0
 def init_log(self, logthreshold=None, logfile=None, syslog=False):
     """init the log service"""
     if logthreshold is None:
         if self.debugmode:
             logthreshold = 'DEBUG'
         else:
             logthreshold = self['log-threshold']
     if sys.platform == 'win32':
         # no logrotate on win32, so use logging rotation facilities
         # for now, hard code weekly rotation every sunday, and 52 weeks kept
         # idea: make this configurable?
         init_log(
             self.debugmode,
             syslog,
             logthreshold,
             logfile,
             self.log_format,
             rotation_parameters={
                 'when': 'W6',  # every sunday
                 'interval': 1,
                 'backupCount': 52
             })
     else:
         init_log(self.debugmode, syslog, logthreshold, logfile,
                  self.log_format)
     # configure simpleTal logger
     logging.getLogger('simpleTAL').setLevel(logging.ERROR)
Exemple #2
0
    def run(self, args):
        """main command line access point:
        * init logging
        * handle global options (-h/--help, --version, -C/--rc-file)
        * check command
        * run command

        Terminate by :exc:`SystemExit`
        """
        init_log(
            debug=True,  # so that we use StreamHandler
            logthreshold=self.logthreshold,
            logformat="%(levelname)s: %(message)s",
        )
        try:
            arg = args.pop(0)
        except IndexError:
            self.usage_and_exit(1)
        if arg in ("-h", "--help"):
            self.usage_and_exit(0)
        if self.version is not None and arg in ("--version"):
            print(self.version)
            sys.exit(0)
        rcfile = self.rcfile
        if rcfile is not None and arg in ("-C", "--rc-file"):
            try:
                rcfile = args.pop(0)
                arg = args.pop(0)
            except IndexError:
                self.usage_and_exit(1)
        try:
            command = self.get_command(arg)
        except KeyError:
            print("ERROR: no %s command" % arg)
            print()
            self.usage_and_exit(1)
        try:
            sys.exit(command.main_run(args, rcfile))
        except KeyboardInterrupt as exc:
            print("Interrupted", end=" ")
            if str(exc):
                print(": %s" % exc, end=" ")
            print()
            sys.exit(4)
        except BadCommandUsage as err:
            print("ERROR:", err)
            print()
            print(command.help())
            sys.exit(1)
Exemple #3
0
    def run(self, args):
        """main command line access point:
        * init logging
        * handle global options (-h/--help, --version, -C/--rc-file)
        * check command
        * run command

        Terminate by :exc:`SystemExit`
        """
        init_log(debug=True, # so that we use StreamHandler
                 logthreshold=self.logthreshold,
                 logformat='%(levelname)s: %(message)s')
        try:
            arg = args.pop(0)
        except IndexError:
            self.usage_and_exit(1)
        if arg in ('-h', '--help'):
            self.usage_and_exit(0)
        if self.version is not None and arg in ('--version'):
            print(self.version)
            sys.exit(0)
        rcfile = self.rcfile
        if rcfile is not None and arg in ('-C', '--rc-file'):
            try:
                rcfile = args.pop(0)
                arg = args.pop(0)
            except IndexError:
                self.usage_and_exit(1)
        try:
            command = self.get_command(arg)
        except KeyError:
            print('ERROR: no %s command' % arg)
            print()
            self.usage_and_exit(1)
        try:
            sys.exit(command.main_run(args, rcfile))
        except KeyboardInterrupt as exc:
            print('Interrupted', end=' ')
            if str(exc):
                print(': %s' % exc, end=' ')
            print()
            sys.exit(4)
        except BadCommandUsage as err:
            print('ERROR:', err)
            print()
            print(command.help())
            sys.exit(1)
    def run(self, args):
        """main command line access point:
        * init logging
        * handle global options (-h/--help, --version, -C/--rc-file)
        * check command
        * run command

        Terminate by :exc:`SystemExit`
        """
        from logilab.common import logging_ext
        logging_ext.init_log(
            debug=True,  # so that we use StreamHandler
            logthreshold=self.logthreshold,
            logformat='%(levelname)s: %(message)s')
        try:
            arg = args.pop(0)
        except IndexError:
            self.usage_and_exit(1)
        if arg in ('-h', '--help'):
            self.usage_and_exit(0)
        if self.version is not None and arg in ('--version'):
            print self.version
            sys.exit(0)
        rcfile = self.rcfile
        if rcfile is not None and arg in ('-C', '--rc-file'):
            try:
                rcfile = args.pop(0)
            except IndexError:
                self.usage_and_exit(1)
        try:
            command = self.get_command(arg)
        except KeyError:
            print 'ERROR: no %s command' % arg
            print
            self.usage_and_exit(1)
        try:
            sys.exit(command.main_run(args, rcfile))
        except KeyboardInterrupt:
            print 'interrupted'
            sys.exit(4)
        except BadCommandUsage, err:
            print 'ERROR:', err
            print
            print command.help()
            sys.exit(1)
Exemple #5
0
    def run(self, args):
        """main command line access point:
        * init logging
        * handle global options (-h/--help, --version, -C/--rc-file)
        * check command
        * run command

        Terminate by :exc:`SystemExit`
        """
        init_log(
            debug=True,  # so that we use StreamHandler
            logthreshold=self.logthreshold,
            logformat="%(levelname)s: %(message)s",
        )
        try:
            arg = args.pop(0)
        except IndexError:
            self.usage_and_exit(1)
        if arg in ("-h", "--help"):
            self.usage_and_exit(0)
        if self.version is not None and arg in ("--version"):
            print self.version
            sys.exit(0)
        rcfile = self.rcfile
        if rcfile is not None and arg in ("-C", "--rc-file"):
            try:
                rcfile = args.pop(0)
            except IndexError:
                self.usage_and_exit(1)
        try:
            command = self.get_command(arg)
        except KeyError:
            print "ERROR: no %s command" % arg
            print
            self.usage_and_exit(1)
        try:
            sys.exit(command.main_run(args, rcfile))
        except KeyboardInterrupt, exc:
            print "Interrupted",
            if str(exc):
                print ": %s" % exc,
            print
            sys.exit(4)