本文整理汇总了Python中trac.env.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: EnvironmentTestCase
class EnvironmentTestCase(unittest.TestCase):
def setUp(self):
env_path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
self.env = Environment(env_path, create=True)
self.db = self.env.get_db_cnx()
def tearDown(self):
self.db.close()
self.env.shutdown() # really closes the db connections
shutil.rmtree(self.env.path)
def test_get_version(self):
"""Testing env.get_version"""
assert self.env.get_version() == db_default.db_version
def test_get_known_users(self):
"""Testing env.get_known_users"""
cursor = self.db.cursor()
cursor.executemany("INSERT INTO session VALUES (%s,%s,0)",
[('123', 0),('tom', 1), ('joe', 1), ('jane', 1)])
cursor.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
[('123', 0, 'email', '[email protected]'),
('tom', 1, 'name', 'Tom'),
('tom', 1, 'email', '[email protected]'),
('joe', 1, 'email', '[email protected]'),
('jane', 1, 'name', 'Jane')])
users = {}
for username,name,email in self.env.get_known_users(self.db):
users[username] = (name, email)
assert not users.has_key('anonymous')
self.assertEqual(('Tom', '[email protected]'), users['tom'])
self.assertEqual((None, '[email protected]'), users['joe'])
self.assertEqual(('Jane', None), users['jane'])
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:35,代码来源:env.py
示例2: rename_user
def rename_user(envpath, oldname, newname):
"""Deletes all watchlist DB entries => Uninstaller"""
from trac.env import Environment
try:
env = Environment(envpath)
except:
print "Given path '%s' seems not to be a Trac environment." % envpath
sys.exit(3)
db = env.get_db_cnx()
cursor = db.cursor()
try:
cursor.execute("""
UPDATE watchlist
SET wluser=%s
WHERE wluser=%s
""", (newname,oldname))
cursor.execute("""
UPDATE watchlist_settings
SET wluser=%s
WHERE wluser=%s
""", (newname,oldname))
print "Renamed user '%s' to '%s'." % (oldname,newname)
db.commit()
except Exception as e:
db.rollback()
print "Could not rename user: " + unicode(e)
print "Does the new user already exists?"
sys.exit(3)
db.commit()
print "Finished."
开发者ID:gaod,项目名称:trac-watchlistplugin,代码行数:33,代码来源:rename_user.py
示例3: fetchRecipes
def fetchRecipes(trac_env):
env = Environment(trac_env)
db = env.get_db_cnx()
cursor = db.cursor()
cursor.execute("SELECT path,active,recipe,min_rev,max_rev,label,description,name FROM bitten_config")
for row in cursor:
(path, active, recipe, min_rev, max_rev, label, description, name) = row
writeFile(trac_env, name, (path, active, recipe, min_rev, max_rev, label, description))
开发者ID:lkraav,项目名称:trachacks,代码行数:8,代码来源:recipe_get.py
示例4: _do_migrate
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,代码行数:58,代码来源:admin.py
示例5: Main
def Main(opts):
""" Cross your fingers and pray """
env = Environment(opts.envpath)
from tractags.api import TagSystem
tlist = opts.tags or split_tags(env.config.get('blog', 'default_tag',
'blog'))
tags = TagSystem(env)
req = Mock(perm=MockPerm())
blog = tags.query(req, ' '.join(tlist + ['realm:wiki']))
cnx = env.get_db_cnx()
for resource, page_tags in list(blog):
try:
page = WikiPage(env, version=1, name=resource.id)
_, publish_time, author, _, _ = page.get_history().next()
if opts.deleteonly:
page.delete()
continue
categories = ' '.join([t for t in page_tags if t not in tlist])
page = WikiPage(env, name=resource.id)
for version, version_time, version_author, version_comment, \
_ in page.get_history():
# Currently the basename of the post url is used due to
# http://trac-hacks.org/ticket/2956
#name = resource.id.replace('/', '_')
name = resource.id
# extract title from text:
fulltext = page.text
match = _title_split_match(fulltext)
if match:
title = match.group(1)
fulltext = match.group(2)
else:
title = name
body = fulltext
print "Adding post %s, v%s: %s" % (name, version, title)
insert_blog_post(cnx, name, version, title, body,
publish_time, version_time,
version_comment, version_author, author,
categories)
reparent_blog_attachments(env, resource.id, name)
continue
cnx.commit()
if opts.delete:
page.delete()
continue
except:
env.log.debug("Error loading wiki page %s" % resource.id,
exc_info=True)
print "Failed to add post %s, v%s: %s" % (name, version, title)
cnx.rollback()
cnx.close()
return 1
cnx.close()
return 0
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:56,代码来源:migrate-tracblog.py
示例6: get_trac_user
def get_trac_user(path, username):
from trac.env import Environment
env = Environment(path)
db = env.get_db_cnx()
cursor = db.cursor()
cursor.execute(
"SELECT name, value" " FROM session_attribute" " WHERE sid='%s'" " AND (name='email' OR name='name')" % username
)
return dict((name, value) for name, value in cursor)
开发者ID:itota,项目名称:django-trac-auth,代码行数:10,代码来源:backends.py
示例7: globally_execute_command
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,代码行数:55,代码来源:console.py
示例8: TicketTemplateTestCase
class TicketTemplateTestCase(unittest.TestCase):
def setUp(self):
# self.env = EnvironmentStub()
env_path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
self.env = Environment(env_path, create=True)
self.db = self.env.db_transaction
self.db.__enter__()
self.compmgr = ComponentManager()
# init TicketTemplateModule
self.tt = ttadmin.TicketTemplateModule(self.compmgr)
setattr(self.tt, "env", self.env)
def tearDown(self):
self.db.__exit__(None, None, None)
self.env.shutdown() # really closes the db connections
shutil.rmtree(self.env.path)
def test_get_active_navigation_item(self):
req = Mock(path_info='/tickettemplate')
self.assertEqual('tickettemplate', self.tt.get_active_navigation_item(req))
req = Mock(path_info='/something')
self.assertNotEqual('tickettemplate', self.tt.match_request(req))
def test_get_navigation_items(self):
req = Mock(href=Mock(tickettemplate=lambda:"/trac-tempenv/tickettemplate"))
a, b, c= self.tt.get_navigation_items(req).next()
self.assertEqual('mainnav', a)
self.assertEqual('tickettemplate', b)
def test_match_request(self):
req = Mock(path_info='/tickettemplate')
self.assertEqual(True, self.tt.match_request(req))
req = Mock(path_info='/something')
self.assertEqual(False, self.tt.match_request(req))
def test_getTicketTypeNames(self):
options = self.tt._getTicketTypeNames()
self.assertEqual(["default", "defect", "enhancement", "task"], options)
def test_loadSaveTemplateText(self):
for tt_name, tt_text in [("default", "default text"),
("defect", "defect text"),
("enhancement", "enhancement text"),
("task", "task text"),
]:
self.tt._saveTemplateText(tt_name, tt_text)
self.assertEqual(tt_name + " text", self.tt._loadTemplateText(tt_name))
开发者ID:SpamExperts,项目名称:trac-tickettemplateplugin,代码行数:53,代码来源:test_tt.py
示例9: do_purge
def do_purge(self, req, path, users):
"""Purge obsolete data - i.e. environment data (sessions, preferences,
permissions) from users no longer existing
@param req
@param path path to the trac env to purge
@param users users to keep
@return boolean success
@return msg info
"""
self.env.log.debug('+ Purging obsolete data')
dryrun = self.env.config.getbool('user_sync','dryrun',True)
sql = []
envpath, tracenv = os.path.split(path)
try:
env = Environment(path)
except IOError:
self.env.log.debug('Could not initialize environment at %s' % (path,))
return False, 'Could not initialize environment at %s' % (path,)
perm = PermissionSystem(env)
if not 'TRAC_ADMIN' in perm.get_user_permissions(req.perm.username):
raise PermissionError
excludes = self.get_perm_groups(path)+users
protect = "'"+"','".join(excludes)+"'"
self.env.log.debug("Excluding from purge: %s" % (protect,))
db = env.get_db_cnx()
cursor = db.cursor()
if not dryrun:
self.env.log.debug('Updating database for %s' % (tracenv,))
cursor.execute('DELETE FROM auth_cookie WHERE name NOT IN (%s)' % (protect,))
cursor.execute('DELETE FROM session WHERE sid NOT IN (%s)' % (protect,))
cursor.execute('DELETE FROM session_attribute WHERE sid NOT IN (%s)' % (protect,))
cursor.execute('DELETE FROM permission WHERE username NOT IN (%s)' % (protect,))
db.commit()
sql_file_path = self.env.config.get('user_sync','sql_file_path') or os.path.join(self.env.path,'log')
if sql_file_path.lower() == 'none':
self.env.log.debug('SQLFile disabled (sql_file_path is "none")')
else:
sqlfile = '%s.sql' % (tracenv,)
sqlfile = os.path.join(sql_file_path,sqlfile)
self.env.log.debug('Writing SQL to %s' % (sqlfile,))
try:
f = open(sqlfile,'a')
f.write('\n--- SQL for purging Trac environment %s\n' % (tracenv,));
f.write('DELETE FROM auth_cookie WHERE name NOT IN (%s);\n' % (protect,))
f.write('DELETE FROM session WHERE sid NOT IN (%s);\n' % (protect,))
f.write('DELETE FROM session_attribute WHERE sid NOT IN (%s);\n' % (protect,))
f.write('DELETE FROM permission WHERE username NOT IN (%s);\n' % (protect,))
except IOError:
self.env.log.debug('Could not write SQL file %s!' % (sqlfile,))
return False, 'Could not write SQL file %s!' % (sqlfile,)
return True, 'Successfully purged environment %s' % (tracenv,)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:53,代码来源:api.py
示例10: _setup
def _setup(self, configuration = None):
configuration = configuration or '[ticket-custom]\nmycustomfield = text\nmycustomfield.label = My Custom Field\nmycustomfield.order = 1'
instancedir = os.path.join(tempfile.gettempdir(), 'test-importer._preview')
if os.path.exists(instancedir):
shutil.rmtree(instancedir, False)
env = Environment(instancedir, create=True)
open(os.path.join(os.path.join(instancedir, 'conf'), 'trac.ini'), 'a').write('\n' + configuration + '\n')
db = env.get_db_cnx()
_exec(db.cursor(), "INSERT INTO permission VALUES ('anonymous', 'REPORT_ADMIN') ")
_exec(db.cursor(), "INSERT INTO permission VALUES ('anonymous', 'IMPORT_EXECUTE') ")
db.commit()
ImporterTestCase.TICKET_TIME = 1190909220
return Environment(instancedir)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:14,代码来源:test.py
示例11: get_number_of_tickets_per_cr
def get_number_of_tickets_per_cr(self, project):
settings = get_current_registry().settings
if not settings:
return
tracenvs = settings.get('penelope.trac.envs')
for trac in project.tracs:
env = Environment('%s/%s' % (tracenvs, trac.trac_name))
db = env.get_db_cnx()
cursor = db.cursor()
cursor.execute("""SELECT c.value as cr, count(t.id) AS number FROM ticket t INNER JOIN ticket_custom c ON (t.id = c.ticket AND c.name = 'customerrequest') group by cr;""")
tickets = cursor.fetchall()
db.rollback()
return dict(tickets)
开发者ID:getpenelope,项目名称:penelope.core,代码行数:15,代码来源:tickets.py
示例12: _create_env
def _create_env(self, path, dburi):
env = Environment(path, True,
[('trac', 'database', dburi),
('trac', 'base_url', 'http://localhost/'),
('project', 'name', u'Pŕójéćŧ Ńáḿé')])
@env.with_transaction()
def fn(db):
cursor = db.cursor()
cursor.execute("UPDATE system SET value='21' "
"WHERE name='initial_database_version'")
pages_dir = resource_filename('trac.wiki', 'default-pages')
WikiAdmin(env).load_pages(pages_dir)
att = Attachment(env, 'wiki', 'WikiStart')
att.insert('filename.txt', StringIO('test'), 4)
env.shutdown()
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:15,代码来源:admin.py
示例13: __init__
def __init__(self, path, append):
self.append = _append
self.env = Environment(path)
self._db = self.env.get_db_cnx()
self._db.autocommit = False
self.loginNameCache = {}
self.fieldNameCache = {}
开发者ID:Aeon,项目名称:mantis2trac,代码行数:7,代码来源:mantis2trac.py
示例14: get_perm_groups
def get_perm_groups(self,path):
"""Get array of permission groups (e.g. anonymous,authenticated) defined in the given environment.
These 'users' should e.g. never be purged on cleanup
"""
users = []
env = Environment(path)
sids = []
self.env.log.debug('Get users to keep from environment path %s' % (path,))
db = env.get_db_cnx()
cursor = db.cursor()
cursor.execute('SELECT DISTINCT username FROM permission WHERE username NOT IN (SELECT DISTINCT sid FROM session_attribute UNION SELECT DISTINCT sid FROM session UNION SELECT DISTINCT name FROM auth_cookie)')
for row in cursor: users.append(row[0])
self.env.log.debug('Permission groups for %s: %s' % (path,','.join(users)))
for user in env.config.getlist('user_sync','users_keep'):
if not user in users: users.append(user)
return users
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:16,代码来源:api.py
示例15: __init__
def __init__(self, project_name, path, db, host, user, password, append):
self.env = Environment(path)
self._append = append
self._tracdb = self.env.get_db_cnx()
self._tracdb.autocommit = False
self._trac_cursor = self._tracdb.cursor()
self._mantis_con = MySQLdb.connect(host=host,
user=user, passwd=password, db=db, compress=1,
cursorclass=MySQLdb.cursors.DictCursor, use_unicode=1)
self._mantis_cursor = self._mantis_con.cursor()
sql = "SELECT id FROM mantis_project_table WHERE name = %s" % (project_name)
print sql
self.mantisCursor().execute("SELECT id FROM mantis_project_table WHERE name = %s", (project_name))
result = self.mantisCursor().fetchall()
if len(result) > 1:
raise Exception("Ambiguous project name %s" % project_name)
elif len(result) == 0:
sql = """INSERT INTO mantis_project_table (name) VALUES (%s)""" % (project_name)
print sql
self.mantisCursor().execute("""INSERT INTO mantis_project_table (name) VALUES (%s)""" , (project_name))
self.mantisCommit()
self._project_id = int(self.mantisCursor().lastrowid)
else:
self._project_id = int(result[0]['id'])
self._bug_map = {}
self._user_map = {}
self._category_map = {}
开发者ID:Aeon,项目名称:mantis2trac,代码行数:30,代码来源:trac2mantis.py
示例16: __init__
def __init__(self, path):
self.env = Environment(path)
self.loginNameCache = {}
self.fieldNameCache = {}
from trac.db.api import DatabaseManager
self.using_postgres = \
DatabaseManager(self.env).connection_uri.startswith("postgres:")
开发者ID:reasonedpenguin,项目名称:fit2trac,代码行数:7,代码来源:fit2trac.py
示例17: getMySQLEnvironment
def getMySQLEnvironment(opts):
dburi = opts.mysql_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()
# if env.needs_upgrade():
# env.upgrade()
return env
开发者ID:rovangju,项目名称:sysadmin-toolkit,代码行数:17,代码来源:sqlite2mysql.py
示例18: __init__
def __init__(self, path):
self.env = Environment(path)
self._db = self.env.get_db_cnx()
self._db.autocommit = False
self.loginNameCache = {}
self.fieldNameCache = {}
from trac.db.api import DatabaseManager
self.using_postgres = DatabaseManager(self.env).connection_uri.startswith("postgres:")
开发者ID:zjj,项目名称:trac_hack,代码行数:8,代码来源:bugzilla2trac.py
示例19: get_tracenv_users
def get_tracenv_users(self, path, userlist=''):
"""Get array of users defined in the specified environment having data assigned
@param path path to the environment
@param userlist comma separated list of users to restrict the result to (e.g. the users from the password file), each user enclosed in single quotes (for SQL)
@return array [0..n] of string users
"""
env = Environment(path)
sids = []
self.env.log.debug('Get users from %s' % (path,))
db = env.get_db_cnx()
cursor = db.cursor()
if userlist:
cursor.execute("SELECT DISTINCT sid FROM session_attribute WHERE sid IN (%s) AND name != 'enabled'" % (userlist,))
else:
cursor.execute("SELECT DISTINCT sid FROM session_attribute WHERE name != 'enabled'")
for row in cursor:
sids.append(row[0])
return sids
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:18,代码来源:api.py
示例20: test_migrate_to_sqlite_inplace
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)
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:18,代码来源:admin.py
注:本文中的trac.env.Environment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论