本文整理汇总了Python中trac.env.Environment.get_read_db方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get_read_db方法的具体用法?Python Environment.get_read_db怎么用?Python Environment.get_read_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.env.Environment
的用法示例。
在下文中一共展示了Environment.get_read_db方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_migrate
# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_read_db [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.')