Exemple #1
0
 def create_logger(self, log_type, log_file, log_level, log_format):
     log_id = 'Trac.%s' % hashlib.sha1(self.path).hexdigest()
     if log_format:
         log_format = log_format.replace('$(', '%(') \
                                .replace('%(path)s', self.path) \
                                .replace('%(basename)s', self.name) \
                                .replace('%(project)s', self.project_name)
     return log.logger_handler_factory(log_type, log_file, log_level,
                                       log_id, format=log_format)
Exemple #2
0
    def __init__(self, default_data=False, enable=None):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        """
        ComponentManager.__init__(self)
        Component.__init__(self)
        self.systeminfo = []

        import trac
        self.path = os.path.dirname(trac.__file__)
        if not os.path.isabs(self.path):
            self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')
        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')

        # -- logging
        from trac.log import logger_handler_factory
        self.log, self._log_handler = logger_handler_factory('test')

        # -- database
        self.dburi = get_dburi()
        if self.dburi.startswith('sqlite'):
            self.config.set('trac', 'database', 'sqlite::memory:')
            self.db = InMemoryDatabase()

        if default_data:
            self.reset_db(default_data)

        from trac.web.href import Href
        self.href = Href('/trac.cgi')
        self.abs_href = Href('http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(Locale and Locale('en', 'US'))
Exemple #3
0
    def __init__(self, default_data=False, enable=None):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        """
        ComponentManager.__init__(self)
        Component.__init__(self)
        self.systeminfo = []

        import trac
        self.path = os.path.dirname(trac.__file__)
        if not os.path.isabs(self.path):
            self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')
        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')

        # -- logging
        from trac.log import logger_handler_factory
        self.log, self._log_handler = logger_handler_factory('test')

        # -- database
        self.dburi = get_dburi()
        if self.dburi.startswith('sqlite'):
            self.config.set('trac', 'database', 'sqlite::memory:')
            self.db = InMemoryDatabase()

        if default_data:
            self.reset_db(default_data)

        from trac.web.href import Href
        self.href = Href('/trac.cgi')
        self.abs_href = Href('http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(Locale and Locale('en', 'US'))
Exemple #4
0
 def setup_log(self):
     """Initialize the logging sub-system."""
     format = self.log_format
     if format:
         format = format.replace('$(', '%(') \
                        .replace('%(path)s', self.path) \
                        .replace('%(basename)s', self.name) \
                        .replace('%(project)s', self.project_name)
     logid = 'Trac.%s' % hashlib.sha1(self.path).hexdigest()
     self.log = log.logger_handler_factory(
         self.log_type, self.log_file_path, self.log_level, logid,
         format=format)
     self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                   self.trac_version)
Exemple #5
0
 def setup_log(self):
     """Initialize the logging sub-system."""
     from trac.log import logger_handler_factory
     logtype = self.log_type
     logfile = self.log_file
     if logtype == 'file' and not os.path.isabs(logfile):
         logfile = os.path.join(self.get_log_dir(), logfile)
     format = self.log_format
     if format:
         format = format.replace('$(', '%(') \
                  .replace('%(path)s', self.path) \
                  .replace('%(basename)s', os.path.basename(self.path)) \
                  .replace('%(project)s', self.project_name)
     self.log, self._log_handler = logger_handler_factory(
         logtype, logfile, self.log_level, self.path, format=format)
     from trac import core, __version__ as VERSION
     self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                   get_pkginfo(core).get('version', VERSION))
Exemple #6
0
 def setup_log(self):
     """Initialize the logging sub-system."""
     logtype = self.log_type
     logfile = self.log_file
     if logtype == "file" and not os.path.isabs(logfile):
         logfile = os.path.join(self.get_log_dir(), logfile)
     format = self.log_format
     logid = "Trac.%s" % hashlib.sha1(self.path).hexdigest()
     if format:
         basename = os.path.basename(self.path)
         format = (
             format.replace("$(", "%(")
             .replace("%(path)s", self.path)
             .replace("%(basename)s", basename)
             .replace("%(project)s", self.project_name)
         )
     self.log, self._log_handler = logger_handler_factory(logtype, logfile, self.log_level, logid, format=format)
     self.log.info("-" * 32 + " environment startup [Trac %s] " + "-" * 32, self.trac_version)
Exemple #7
0
 def setup_log(self):
     """Initialize the logging sub-system."""
     logtype = self.log_type
     logfile = self.log_file
     if logtype == 'file' and not os.path.isabs(logfile):
         logfile = os.path.join(self.get_log_dir(), logfile)
     format = self.log_format
     logid = 'Trac.%s' % hashlib.sha1(self.path).hexdigest()
     if format:
         basename = os.path.basename(self.path)
         format = format.replace('$(', '%(') \
                        .replace('%(path)s', self.path) \
                        .replace('%(basename)s', basename) \
                        .replace('%(project)s', self.project_name)
     self.log, self._log_handler = logger_handler_factory(
         logtype, logfile, self.log_level, logid, format=format)
     self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                   self.trac_version)
Exemple #8
0
Fichier : env.py Projet : t2y/trac
 def setup_log(self):
     """Initialize the logging sub-system."""
     from trac.log import logger_handler_factory
     logtype = self.log_type
     logfile = self.log_file
     if logtype == 'file' and not os.path.isabs(logfile):
         logfile = os.path.join(self.get_log_dir(), logfile)
     format = self.log_format
     logid = 'Trac.%s' % sha1(self.path).hexdigest()
     if format:
         format = format.replace('$(', '%(') \
                  .replace('%(path)s', self.path) \
                  .replace('%(basename)s', os.path.basename(self.path)) \
                  .replace('%(project)s', self.project_name)
     self.log, self._log_handler = logger_handler_factory(
         logtype, logfile, self.log_level, logid, format=format)
     from trac import core, __version__ as VERSION
     self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32,
                   get_pkginfo(core).get('version', VERSION))
Exemple #9
0
    def setup_log(self):
        """Initialize the logging sub-system."""
        from trac.log import logger_handler_factory
        logtype = self.log_type
        logfile = self.log_file
        format = self.log_format

        self.parent.log.debug("Log type '%s' for product '%s'", logtype,
                              self.product.prefix)

        # Force logger inheritance on identical configuration
        if (logtype, logfile,
                format) == (self.parent.log_type, self.parent.log_file,
                            self.parent.log_format):
            logtype = 'inherit'

        if logtype == 'inherit':
            self.log = self.parent.log
            self._log_handler = self.parent._log_handler
            self.parent.log.warning(
                "Inheriting parent logger for product '%s'",
                self.product.prefix)
        else:
            if logtype == 'file' and not os.path.isabs(logfile):
                logfile = os.path.join(self.get_log_dir(), logfile)
            logid = 'Trac.%s.%s' % \
                    (sha1(self.parent.path).hexdigest(), self.product.prefix)
            if format:
                format = format.replace('$(', '%(') \
                         .replace('%(path)s', self.path) \
                         .replace('%(basename)s', os.path.basename(self.path)) \
                         .replace('%(project)s', self.project_name)
            self.log, self._log_handler = logger_handler_factory(
                logtype, logfile, self.log_level, logid, format=format)

        from trac import core, __version__ as VERSION
        self.log.info(
            '-' * 32 + ' product %s environment startup [Trac %s] ' + '-' * 32,
            self.product.prefix,
            get_pkginfo(core).get('version', VERSION))
Exemple #10
0
    def setup_log(self):
        """Initialize the logging sub-system."""
        from trac.log import logger_handler_factory
        logtype = self.log_type
        logfile = self.log_file
        format = self.log_format

        self.parent.log.debug("Log type '%s' for product '%s'",
                logtype, self.product.prefix)

        # Force logger inheritance on identical configuration
        if (logtype, logfile, format) == (self.parent.log_type,
                self.parent.log_file, self.parent.log_format):
            logtype = 'inherit'

        if logtype == 'inherit':
            self.log = self.parent.log
            self._log_handler = self.parent._log_handler
            self.parent.log.info("Inheriting parent logger for product '%s'",
                    self.product.prefix)
        else:
            if logtype == 'file' and not os.path.isabs(logfile):
                logfile = os.path.join(self.get_log_dir(), logfile)
            logid = 'Trac.%s.%s' % \
                    (sha1(self.parent.path).hexdigest(), self.product.prefix)
            if format:
                format = format.replace('$(', '%(') \
                         .replace('%(path)s', self.path) \
                         .replace('%(basename)s', os.path.basename(self.path)) \
                         .replace('%(project)s', self.project_name)
            self.log, self._log_handler = logger_handler_factory(
                logtype, logfile, self.log_level, logid, format=format)

        from trac import core, __version__ as VERSION
        self.log.info('-' * 32 +
                        ' product %s environment startup [Trac %s] ' +
                        '-' * 32,
                      self.product.prefix,
                      get_pkginfo(core).get('version', VERSION))
Exemple #11
0
    def __init__(self, default_data=False, enable=None, disable=None,
                 path=None, destroying=False):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        :param disable: A list of component classes or name globs to
                        deactivate in the stub environment.
        :param path: The location of the environment in the file system.
                     No files or directories are created when specifying
                     this parameter.
        :param destroying: If True, the database will not be reset. This is
                           useful for cases when the object is being
                           constructed in order to call `destroy_db`.
        """
        if enable is not None and not isinstance(enable, (list, tuple)):
            raise TypeError('Keyword argument "enable" must be a list')
        if disable is not None and not isinstance(disable, (list, tuple)):
            raise TypeError('Keyword argument "disable" must be a list')

        ComponentManager.__init__(self)

        self.systeminfo = []

        import trac
        self.path = path
        if self.path is None:
            self.path = os.path.dirname(trac.__file__)
            if not os.path.isabs(self.path):
                self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')
        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        else:
            self.config.set('components', 'tracopt.versioncontrol.*',
                            'enabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'disabled')

        # -- logging
        from trac.log import logger_handler_factory
        self.log, self._log_handler = logger_handler_factory('test')

        # -- database
        self.config.set('components', 'trac.db.*', 'enabled')
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = self.global_databasemanager
        else:
            self.config.set('trac', 'database', self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set('trac', 'debug_sql', True)
            init_global = not destroying

        if default_data or init_global:
            self.reset_db(default_data)

        self.config.set('trac', 'base_url', 'http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(locale_en)
Exemple #12
0
    def __init__(self,
                 default_data=False,
                 enable=None,
                 disable=None,
                 path=None,
                 destroying=False):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        :param disable: A list of component classes or name globs to
                        deactivate in the stub environment.
        :param path: The location of the environment in the file system.
                     No files or directories are created when specifying
                     this parameter.
        :param destroying: If True, the database will not be reset. This is
                           useful for cases when the object is being
                           constructed in order to call `destroy_db`.
        """
        if enable is not None and not isinstance(enable, (list, tuple)):
            raise TypeError('Keyword argument "enable" must be a list')
        if disable is not None and not isinstance(disable, (list, tuple)):
            raise TypeError('Keyword argument "disable" must be a list')

        ComponentManager.__init__(self)
        Component.__init__(self)

        self.systeminfo = []

        import trac
        self.path = path
        if self.path is None:
            self.path = os.path.dirname(trac.__file__)
            if not os.path.isabs(self.path):
                self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')
        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        else:
            self.config.set('components', 'tracopt.versioncontrol.*',
                            'enabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'disabled')

        # -- logging
        from trac.log import logger_handler_factory
        self.log, self._log_handler = logger_handler_factory('test')

        # -- database
        self.config.set('components', 'trac.db.*', 'enabled')
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = self.global_databasemanager
        else:
            self.config.set('trac', 'database', self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set('trac', 'debug_sql', True)
            self.config.set('logging', 'log_type', 'stderr')
            self.config.set('logging', 'log_level', 'DEBUG')
            init_global = not destroying

        if default_data or init_global:
            self.reset_db(default_data)

        from trac.web.href import Href
        self.href = Href('/trac.cgi')
        self.abs_href = Href('http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(locale_en)
Exemple #13
0
    def __init__(self, default_data=False, enable=None, disable=None, path=None, destroying=False):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        """
        ComponentManager.__init__(self)
        Component.__init__(self)

        self.systeminfo = []

        import trac

        self.path = path
        if self.path is None:
            self.path = os.path.dirname(trac.__file__)
            if not os.path.isabs(self.path):
                self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, "basic-workflow.ini")
        self.config.set("logging", "log_level", "DEBUG")
        self.config.set("logging", "log_type", "stderr")
        if enable is not None:
            self.config.set("components", "trac.*", "disabled")
        else:
            self.config.set("components", "tracopt.versioncontrol.*", "enabled")
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set("components", config_key, "enabled")
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set("components", config_key, "disabled")

        # -- logging
        from trac.log import logger_handler_factory

        self.log, self._log_handler = logger_handler_factory("test")

        # -- database
        self.config.set("components", "trac.db.*", "enabled")
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = global_databasemanager
        else:
            self.config.set("trac", "database", self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set("trac", "debug_sql", True)
            self.config.set("logging", "log_type", "stderr")
            self.config.set("logging", "log_level", "DEBUG")
            init_global = not destroying

        if default_data or init_global:
            self.reset_db(default_data)

        from trac.web.href import Href

        self.href = Href("/trac.cgi")
        self.abs_href = Href("http://example.org/trac.cgi")

        self.known_users = []
        translation.activate(locale_en)