当前位置: 首页>>代码示例>>Python>>正文


Python Environment.needs_upgrade方法代码示例

本文整理汇总了Python中trac.env.Environment.needs_upgrade方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.needs_upgrade方法的具体用法?Python Environment.needs_upgrade怎么用?Python Environment.needs_upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.env.Environment的用法示例。


在下文中一共展示了Environment.needs_upgrade方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: globally_execute_command

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]
    def globally_execute_command(self, *args):
        offset = 0
        max_index = -1
        if args and args[0].isdigit():
            offset = int(args[0])
            if len(args) > 1 and args[1].isdigit():
                limit = int(args[1])
                max_index = limit + offset
                args = args[2:]
            else:
                args = args[1:]
        upgrade_check = False
        env_list = False
        if args and args[0] == 'upgrade-check':
            upgrade_check = True
        elif args and args[0] == 'list-env':
            env_list = True

        sys_home_project_name = self.config.get('multiproject', 'sys_home_project_name')
        for index, row in enumerate(self.projects_iterator(['env_name'], batch_size=10)):
            env_name, = row
            if index < offset:
                continue
            if max_index != -1 and index >= max_index:
                break
            if env_name == sys_home_project_name:
                continue
            if env_list:
                printout("{0:4} env:'{1}'".format(index, env_name))
                continue
            env = None
            try:
                env_path = safe_path(self.config.get('multiproject', 'sys_projects_root'),
                    env_name)
                env = Environment(env_path)
            except TracError as e:
                printout(_('ERROR: Opening environment %(env_name)s failed', env_name=env_name))
                continue

            if upgrade_check:
                if env.needs_upgrade():
                    printout("[+] {0:4} env:'{1}'".format(index, env_name))
                else:
                    printout("[ ] {0:4} env:'{1}'".format(index, env_name))
                continue
            # To setup MultiProject specific things like 'project_identifier'
            MultiProjectEnvironmentInit(env).environment_needs_upgrade(None)

            try:
                command_manager = AdminCommandManager(env)
                printout(_("{0:4} Run in env:'{1}'".format(index, env_name)))
                command_manager.execute_command(*args)
            except AdminCommandError as e:
                printout(_('ERROR: Executing command in environment %(env_name)s failed: ',
                    env_name=env_name) + str(e))
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:57,代码来源:console.py

示例2: getPostgreSQLEnvironment

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]
def getPostgreSQLEnvironment(opts):
    """ Create an Environment connected to the PostgreSQL database """

    dburi = opts.pg_uri
    env = Environment(opts.tracenv)
    env.config.set('trac', 'database', dburi)
    try:
        cnx = env.get_db_cnx()
        cur = cnx.cursor()
        cur.execute("select value from system where name = 'database_version'");
    except ProgrammingError:
        cnx.rollback()
        DatabaseManager(env).init_db()
        DatabaseManager(env).shutdown()
        for x in filter(None, [env.compmgr[cls] for cls in 
                        ComponentMeta._registry.get(
                        IEnvironmentSetupParticipant, [])]):
            if isinstance(x, EnvironmentSetup):
                x.environment_created()        
    if env.needs_upgrade():
        env.upgrade()
    return env
开发者ID:djangsters,项目名称:agilo,代码行数:24,代码来源:agilo_sqlite2pg.py

示例3: MigrationTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(src_options, dst_options)

    def test_migrate_to_sqlite_env(self):
        dburi = get_dburi()
        if dburi == 'sqlite::memory:':
            dburi = 'sqlite:db/trac.db'
        self._create_env(self.src_path, dburi)

        self.src_env = Environment(self.src_path)
        src_options = self._get_options(self.src_env)
        src_records = self._get_all_records(self.src_env)
        self._migrate(self.src_env, self.dst_path, 'sqlite:db/trac.db')
        self.dst_env = Environment(self.dst_path)
        dst_options = self._get_options(self.dst_env)
        dst_records = self._get_all_records(self.dst_env)
        self.assertEqual({'name': 'initial_database_version', 'value': '21'},
                         dst_records['system']['initial_database_version'])
        self._compare_records(src_records, dst_records)
        self.assertEqual(src_options, dst_options)
        att = Attachment(self.dst_env, 'wiki', 'WikiStart', 'filename.txt')
        self.assertEqual('test', read_file(att.path))

    def test_migrate_to_sqlite_inplace(self):
        dburi = get_dburi()
        if dburi in ('sqlite::memory:', 'sqlite:db/trac.db'):
            dburi = 'sqlite:db/trac-migrate.db'
        self._create_env(self.src_path, dburi)

        self.src_env = Environment(self.src_path)
        src_options = self._get_options(self.src_env)
        src_records = self._get_all_records(self.src_env)
        self._migrate_inplace(self.src_env, 'sqlite:db/trac.db')
        self.src_env.shutdown()
        self.src_env = Environment(self.src_path)
        dst_options = self._get_options(self.src_env)
        dst_records = self._get_all_records(self.src_env)
        self.assertEqual({'name': 'initial_database_version', 'value': '21'},
                         dst_records['system']['initial_database_version'])
        self._compare_records(src_records, dst_records)
        self.assertEqual(src_options, dst_options)

    def _test_migrate_with_plugin_to_sqlite_env(self):
        self.src_env = Environment(self.src_path)
        self.assertTrue(self.src_env.needs_upgrade())
        self.src_env.upgrade()
        self.assertFalse(self.src_env.needs_upgrade())
        src_options = self._get_options(self.src_env)
        src_records = self._get_all_records(self.src_env)

        self._migrate(self.src_env, self.dst_path, 'sqlite:db/trac.db')
        self.dst_env = Environment(self.dst_path)
        self.assertFalse(self.dst_env.needs_upgrade())
        self.assertFalse(os.path.exists(os.path.join(self.dst_path, 'log',
                                                     'created')))
        self.assertTrue(os.path.exists(os.path.join(self.dst_path, 'log',
                                                    'upgraded')))
        dst_options = self._get_options(self.dst_env)
        dst_records = self._get_all_records(self.dst_env)
        self.assertEqual({'name': 'initial_database_version', 'value': '21'},
                         dst_records['system']['initial_database_version'])
        self._compare_records(src_records, dst_records)
        self.assertEqual(src_options, dst_options)
        att = Attachment(self.dst_env, 'wiki', 'WikiStart', 'filename.txt')
        self.assertEqual('test', read_file(att.path))

    def test_migrate_with_plugin_py_to_sqlite_env(self):
        dburi = get_dburi()
        if dburi == 'sqlite::memory:':
            dburi = 'sqlite:db/trac.db'
        self._create_env(self.src_path, dburi)
        plugin_name = self._generate_module_name() + '.py'
        create_file(os.path.join(self.src_path, 'plugins', plugin_name),
                    _plugin_py)
        self._test_migrate_with_plugin_to_sqlite_env()

    def _extract_zipfile(self, zipfile, destdir):
        z = ZipFile(zipfile)
        try:
            for entry in z.namelist():
                if entry.endswith('/'):  # is a directory
                    continue
                names = entry.split('/')
                content = z.read(entry)
                filename = os.path.join(destdir, *names)
                dirname = os.path.dirname(filename)
                if not os.path.isdir(dirname):
                    os.makedirs(dirname)
                create_file(filename, content, 'wb')
        finally:
            z.close()

    def test_migrate_with_plugin_egg_to_sqlite_env(self):
        dburi = get_dburi()
        if dburi == 'sqlite::memory:':
            dburi = 'sqlite:db/trac.db'
        self._create_env(self.src_path, dburi)
        self._extract_zipfile(self._build_egg_file(),
                              os.path.join(self.src_path, 'plugins',
                                           'tracmigratetest.egg'))
        self._test_migrate_with_plugin_to_sqlite_env()
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:104,代码来源:admin.py

示例4: main

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]

def main(args):
    if len(args) != 3:
        print >>sys.stderr, _usage()
        return 127
    if args[0] in ("-i", "--in-place"):
        dest, source, dburi = args
    else:
        source, dest, dburi = args

    try:
        from trac.env import Environment
        from tracmigrate.admin import TracMigrationCommand
    except ImportError, e:
        print >>sys.stderr, "Requires trac and tracmigrateplugin: %s" % unicode(e)
        return 126

    env = Environment(source)
    if env.needs_upgrade():
        print >>sys.stderr, '''\
The Trac Environment needs to be upgraded.

Run "trac-admin %s upgrade"''' % source
        return 2
    return TracMigrationCommand(env)._do_migrate(dest, dburi)


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]) or 0)
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:31,代码来源:trac-migrate.py

示例5: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_db_exc(self):
        db_exc = self.env.db_exc
        self.assertTrue(hasattr(db_exc, 'IntegrityError'))
        self.assertIs(db_exc, self.env.db_exc)

    def test_abs_href(self):
        abs_href = self.env.abs_href
        self.assertEqual('http://trac.edgewall.org/some/path', abs_href())
        self.assertIs(abs_href, self.env.abs_href)

    def test_href(self):
        href = self.env.href
        self.assertEqual('/some/path', href())
        self.assertIs(href, self.env.href)

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())
        self.assertEqual(db_default.db_version, self.env.database_version)
        self.assertEqual(db_default.db_version, self.env.database_initial_version)

    def test_is_component_enabled(self):
        self.assertEqual(True, Environment.required)
        self.assertEqual(True, self.env.is_component_enabled(Environment))
        self.assertEqual(False, EnvironmentStub.required)
        self.assertEqual(None, self.env.is_component_enabled(EnvironmentStub))

    def test_dumped_values_in_tracini(self):
        parser = RawConfigParser()
        filename = self.env.config.filename
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))

    def test_dumped_values_in_tracini_sample(self):
        parser = RawConfigParser()
        filename = self.env.config.filename + '.sample'
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))
        self.assertTrue(parser.has_option('logging', 'log_format'))
        self.assertEqual('', parser.get('logging', 'log_format'))

    def test_needs_upgrade_legacy_participant(self):
        """For backward compatibility with plugin, environment_needs_upgrade
        with a `db` argument is deprecated but still allowed."""
        participants = self.env.setup_participants
        needs_upgrade = self.env.needs_upgrade()

        class LegacyParticipant(Component):
            implements(IEnvironmentSetupParticipant)
            def environment_created(self):
                pass
            def environment_needs_upgrade(self, db):
                return True
            def upgrade_environment(self, db):
                pass

        self.env.enable_component(LegacyParticipant)

        self.assertFalse(needs_upgrade)
        self.assertEqual(len(participants) + 1,
                         len(self.env.setup_participants))
        self.assertTrue(self.env.needs_upgrade())

    def test_upgrade_legacy_participant(self):
        """For backward compatibility with plugin, upgrade with a `db`
        argument is deprecated but still allowed."""
        participants = self.env.setup_participants

        class LegacyParticipant(Component):
            implements(IEnvironmentSetupParticipant)
            def environment_created(self):
                pass
            def environment_needs_upgrade(self, db):
                return True
            def upgrade_environment(self, db):
                pass

        self.env.enable_component(LegacyParticipant)

        self.assertEqual(len(participants) + 1,
                         len(self.env.setup_participants))
        self.assertTrue(self.env.needs_upgrade())
        self.assertTrue(self.env.upgrade())
#.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:trac,代码行数:103,代码来源:env.py

示例6: create_project

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import needs_upgrade [as 别名]

#.........这里部分代码省略.........

        command = create_distro_command(interactive=self.interactive)
        
        # check for missing variables
        missing = templates.missing(vars)
        missing.update(set(optdict.keys()).difference(vars.keys()))
        if return_missing:
            return missing
        if missing:

            # use default repo fields if they are missing
            for field in repo_fields:
                if field in missing:
                    vars[field] = repo_fields[field]
                    missing.remove(field)

            # add missing variables to the optdict
            for missed in missing:
                if missed not in optdict:
                    optdict[missed] = var(missed, '')

            if missing:
                paste_template = Template(project)
                paste_template._read_vars = dict2vars(optdict) # XXX bad touch
                paste_template.check_vars(vars, command)

        # run the pre method of the pastescript templates
        # XXX should this be done here?
        command.interactive = False
        for paste_template in templates.pastescript_templates:
            paste_template.pre(command, dirname, vars)

        ### create the database
        if database:
            database.setup(**vars)
        
        ### create the trac environment
        options = templates.options_tuples(vars)
        options.append(('project', 'name', project)) # XXX needed?
        if self.inherit:
            options.append(('inherit', 'file', self.inherit))
        env = Environment(dirname, create=True, options=options)

        ### repository setup
        if repository:
            repository.setup(**vars)
            try:
                repos = env.get_repository()
                repos.sync()
            except TracError:
                pass

        ### read the generated configuration 
        _conf_file = os.path.join(dirname, 'conf', 'trac.ini')
        fp = file(_conf_file)
        _conf = fp.read()
        fp.close()

        ### run pastescript templates
        for paste_template in templates.pastescript_templates:
            paste_template.write_files(command, dirname, vars)
            paste_template.post(command, dirname, vars)

            # read permissions
            for agent, perm in paste_template.permissions.items():
                permissions.setdefault(agent, []).extend(perm)

            # read wiki directories
            wiki_dir = paste_template.wiki_dir()
            if wiki_dir is not None:
                wiki.append(wiki_dir)

        # write back munged configuration 
        munger = ConfigMunger(_conf, options)
        fp = file(_conf_file, 'w')
        munger.write(fp)
        fp.close()

        # TODO: update the inherited file:
        # * intertrac

        # trac-admin upgrade the project
        env = Environment(dirname)
        if env.needs_upgrade():
            env.upgrade()

        ### trac-admin operations
        admin = TracLegosAdmin(dirname)

        # remove the default items
        admin.delete_all()

        # load wiki pages
        admin.load_pages() # default wiki pages
        for page_dir in wiki:
            admin.load_pages(page_dir)

        # add permissions
        if permissions:
            admin.add_permissions(permissions)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:104,代码来源:legos.py


注:本文中的trac.env.Environment.needs_upgrade方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。