Beispiel #1
0
class Application (BaseObject):

    app_name = "UnnamedApp"
    app_version = "0"

    short_cmdline_args = None
    long_cmdline_args = None

    options = { 'exception_hook' : _except_hook,
              }

    def __init__ (self, **kw):
        """constructor"""
        super(Application, self).__init__()
        self._parse_options(Application.options, kw)

        if hasattr(self, 'config_files'):
            self.app_config = self.config_files
        elif hasattr(self, 'config_file'):
            self.app_config = str(self.config_file)
        else:
            self.app_config = "%s.conf" % self.app_name

        global _app_inst, _app_name, _app_version
        _app_inst = self
        _app_name = self.app_name
        _app_version = self.app_version

        if self.exception_hook is not None:
            sys.excepthook = self.exception_hook

    def start (self):
        try:
            self.config = Config(self.app_config, sys.argv,
                                 short_arguments=self.short_cmdline_args,
                                 long_arguments=self.long_cmdline_args,
                                 command_line_handler=self.cmdline_handler)

            # Default logging setup, if there is a 'logging' section in
            # the configuration file. Otherwise you are on your own to
            # setup the logging subsystem
            if 'logging' in self.config.get_sections():
                configurelog(self.config)

            self.setup()
            self.run()
            self.cleanup()
            return

        except KeyboardInterrupt:
            self.abort('Aborted by user (keyboard interrupt)', errorcode=0)

        except ConfigError, o:
            self.abort('Configuration error: %s' % (o), errorcode=2)

        except OperationError, o:
            self.abort('Error: %s' % (o), errorcode=3)
Beispiel #2
0
    def start (self):
        try:
            self.config = Config(self.app_config, sys.argv,
                                 short_arguments=self.short_cmdline_args,
                                 long_arguments=self.long_cmdline_args,
                                 command_line_handler=self.cmdline_handler)

            # Default logging setup, if there is a 'logging' section in
            # the configuration file. Otherwise you are on your own to
            # setup the logging subsystem
            if 'logging' in self.config.get_sections():
                configurelog(self.config)

            self.setup()
            self.run()
            self.cleanup()
            return

        except KeyboardInterrupt:
            self.abort('Aborted by user (keyboard interrupt)', errorcode=0)

        except ConfigError, o:
            self.abort('Configuration error: %s' % (o), errorcode=2)