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


Python Environment.upgrade方法代码示例

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


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

示例1: _do_migrate

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import upgrade [as 别名]
    def _do_migrate(self, env_path, dburl):
        options = [('trac', 'database', dburl)]
        options.extend((section, name, value)
                       for section in self.config.sections()
                       for name, value in self.config.options(section)
                       if section != 'trac' or name != 'database')
        src_db = self.env.get_read_db()
        src_cursor = src_db.cursor()
        src_tables = set(self._get_tables(self.config.get('trac', 'database'),
                                          src_cursor))
        env = Environment(env_path, create=True, options=options)
        env.upgrade()
        env.config.save() # remove comments

        db = env.get_read_db()
        cursor = db.cursor()
        tables = set(self._get_tables(dburl, cursor))
        tables = sorted(tables & src_tables)
        sequences = set(self._get_sequences(dburl, cursor, tables))
        directories = self._get_directories(src_db)

        printout('Copying tables:')
        for table in tables:
            if table == 'system':
                continue

            @env.with_transaction()
            def copy(db):
                cursor = db.cursor()
                printout('  %s table... ' % table, newline=False)
                src_cursor.execute('SELECT * FROM ' + src_db.quote(table))
                columns = get_column_names(src_cursor)
                query = 'INSERT INTO ' + db.quote(table) + \
                        ' (' + ','.join(db.quote(c) for c in columns) + ')' + \
                        ' VALUES (' + ','.join(['%s'] * len(columns)) + ')'
                cursor.execute('DELETE FROM ' + db.quote(table))
                count = 0
                while True:
                    rows = src_cursor.fetchmany(100)
                    if not rows:
                        break
                    cursor.executemany(query, rows)
                    count += len(rows)
                printout('%d records.' % count)

            if table in sequences:
                db.update_sequence(cursor, table)

        printout('Copying directories:')
        for name in directories:
            printout('  %s directory... ' % name, newline=False)
            src = os.path.join(self.env.path, name)
            dst = os.path.join(env.path, name)
            if os.path.isdir(dst):
                shutil.rmtree(dst)
            if os.path.isdir(src):
                shutil.copytree(src, dst)
            printout('done.')
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:60,代码来源:admin.py

示例2: getPostgreSQLEnvironment

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import 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 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: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import 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

示例5: create_project

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import 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.upgrade方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。