Beispiel #1
0
    def test_regression_bh_539(self):
        tracadmin = AdminCommandManager(self.env)

        self.assertTrue(self.env[self.component_class] is None,
                        "Expected component disabled")
        self.assertFalse(
            any(
                isinstance(c, self.component_class)
                for c in tracadmin.providers),
            "Component erroneously listed in admin cmd providers")
        self.assertEqual([], tracadmin.get_command_help(args=['fail']))

        # Enable component in both global and product context
        cmd_args = ['config', 'set', 'components', __name__ + '.*', 'enabled']
        AdminCommandManager(self.global_env).execute_command(*cmd_args)
        tracadmin.execute_command(*cmd_args)

        self.assertTrue(self.env[self.component_class] is not None,
                        "Expected component enabled")
        self.assertTrue(
            any(
                isinstance(c, self.component_class)
                for c in tracadmin.providers),
            "Component not listed in admin cmd providers")
        self.assertEqual(1, len(tracadmin.get_command_help(args=['fail'])))
Beispiel #2
0
 def product_admincmd_mgr(self, prefix):
     try:
         product_env = ProductEnvironment.lookup_env(self.env, prefix)
     except LookupError:
         raise AdminCommandError('Unknown product %s' % (prefix, ))
     else:
         return AdminCommandManager(product_env)
Beispiel #3
0
 def _init_env(self):
     self.__env = env = Environment(self.envname)
     negotiated = None
     # fixup language according to env settings
     if has_babel:
         negotiated = get_console_locale(env)
         if negotiated:
             translation.activate(negotiated)
     self.cmd_mgr = AdminCommandManager(env)
Beispiel #4
0
 def expand_macro(self, formatter, name, content):
     if content:
         arg = content.strip().split()
         doc = getattr(TracAdmin, "_help_" + arg[0], None)
         if doc is None:
             cmd_mgr = AdminCommandManager(self.env)
             doc = cmd_mgr.get_command_help(arg)
         if not doc:
             raise TracError('Unknown trac-admin command "%s"' % content)
     else:
         doc = TracAdmin.all_docs(self.env)
     buf = StringIO.StringIO()
     TracAdmin.print_doc(doc, buf, long=True)
     return html.PRE(buf.getvalue().decode('utf-8'), class_='wiki')
Beispiel #5
0
 def expand_macro(self, formatter, name, content, args=None):
     if content:
         arg = content.strip().split()
         doc = getattr(TracAdmin, "_help_" + arg[0], None)
         if doc is None:
             cmd_mgr = AdminCommandManager(self.env)
             doc = cmd_mgr.get_command_help(arg)
         if not doc:
             raise MacroError(_('Unknown trac-admin command '
                                '"%(command)s"', command=content))
     else:
         doc = TracAdmin.all_docs(self.env)
     buf = io.StringIO()
     TracAdmin.print_doc(doc, buf, long=True)
     return html.pre(buf.getvalue(), class_='wiki')
Beispiel #6
0
 def all_docs(cls, env=None):
     docs = (cls._help_help + cls._help_initenv)
     if env is not None:
         docs.extend(AdminCommandManager(env).get_command_help())
     return docs
Beispiel #7
0
 def cmd_mgr(self):
     return AdminCommandManager(self.env)
Beispiel #8
0
    def test_regression_bh_539_concurrent(self):
        try:
            # It is necessary to load another environment object to work around
            # ProductEnvironment class' parametric singleton constraint
            old_env = self.env
            # In-memory DB has to be shared
            self.global_env.__class__.global_databasemanager = \
                self.env.global_databasemanager
            new_global_env = self._setup_test_env(create_folder=True,
                                                  path=self.global_env.path)
            self.env = old_env
            self._setup_test_log(new_global_env)

            # FIXME: EnvironmentStub config is not bound to a real file
            # ... so let's reuse one config for both envs to simulate that they
            # are in sync, a condition verified in another test case
            new_global_env.config = self.global_env.config

            new_env = ProductEnvironment(new_global_env, self.default_product)

            self.assertTrue(new_global_env is not self.global_env)
            self.assertTrue(new_env is not self.env)
            self.assertEqual(self.env.path, new_env.path)
            self.assertEqual(self.env.config._lock_path,
                             new_env.config._lock_path)

            tracadmin = AdminCommandManager(self.env)
            new_tracadmin = AdminCommandManager(new_env)

            # Assertions for self.env
            self.assertTrue(self.env[self.component_class] is None,
                            "Expected component disabled")
            self.assertFalse(
                any(
                    isinstance(c, self.component_class)
                    for c in tracadmin.providers),
                "Component erroneously listed in admin cmd "
                "providers")
            self.assertEqual([], tracadmin.get_command_help(args=['fail']))

            # Repeat assertions for new_env
            self.assertTrue(new_env[self.component_class] is None,
                            "Expected component disabled")
            self.assertFalse(
                any(
                    isinstance(c, self.component_class)
                    for c in new_tracadmin.providers),
                "Component erroneously listed in admin cmd "
                "providers")
            self.assertEqual([], new_tracadmin.get_command_help(args=['fail']))

            # Enable component in both self.global_env and self.env contexts
            cmd_args = [
                'config', 'set', 'components', __name__ + '.*', 'enabled'
            ]
            AdminCommandManager(self.global_env).execute_command(*cmd_args)
            tracadmin.execute_command(*cmd_args)

            # Assert that changes are auto-magically reflected in new_env
            self.assertTrue(new_env[self.component_class] is not None,
                            "Expected component enabled")
            self.assertTrue(
                any(
                    isinstance(c, self.component_class)
                    for c in new_tracadmin.providers),
                "Component not listed in admin cmd providers")
            self.assertEqual(
                1, len(new_tracadmin.get_command_help(args=['fail'])))
        finally:
            self.global_env.__class__.global_databasemanager = None
            new_global_env = new_env = None
Beispiel #9
0
 def _execute_command(self, *args):
     env = self.get_trac_environment()
     AdminCommandManager(env).execute_command(*args)
Beispiel #10
0
 def env_set(self, envname, env=None):
     self.envname = envname
     self.prompt = "Trac [%s]> " % self.envname
     if env is not None:
         self.__env = env
         self.cmd_mgr = AdminCommandManager(env)