本文整理汇总了Python中trac.wiki.model.WikiPage类的典型用法代码示例。如果您正苦于以下问题:Python WikiPage类的具体用法?Python WikiPage怎么用?Python WikiPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WikiPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_agilo
def initialize_agilo(self, project_name, db_url, svn_repo, demo=False):
try:
self.do_initenv('%s %s %s %s' % (project_name,
db_url, 'svn',
svn_repo or 'somewhere'))
# Now add agilo and the template path
env = Environment(self.envname)
ac = AgiloConfig(env)
if not svn_repo:
# remove the fake from the config
ac.change_option('repository_dir', '', 'trac')
# sets the restric_owner option
ac.change_option('restrict_owner',
'true',
'ticket')
# this is also saving the config
ac.enable_agilo()
# update wiki
wiki = WikiPage(env, name='WikiStart')
wiki.text = agilo_wiki
wiki.save('admin', 'Updated to Agilo', '127.0.0.1')
# reset the env
self.env_set(envname=self.envname, env=env)
# Now initialize Agilo
self.do_upgrade('upgrade --no-backup')
# Now create the demo if needed
if demo:
try:
from create_demo_data import _create_demo_data
_create_demo_data(env)
except ImportError, e:
env.log.error(exception_to_unicode(e))
except:
pass
示例2: main
def main():
options, args = parse_args()
names = sorted(name for name in resource_listdir('trac.wiki',
'default-pages')
if not name.startswith('.'))
if args:
args = sorted(set(names) & set(map(os.path.basename, args)))
else:
args = names
if options.download:
download_default_pages(args, options.prefix)
env = EnvironmentStub()
load_components(env)
with env.db_transaction:
for name in names:
wiki = WikiPage(env, name)
wiki.text = resource_string('trac.wiki', 'default-pages/' +
name).decode('utf-8')
if wiki.text:
wiki.save('trac', '')
else:
printout('%s: Skipped empty page' % name)
req = Mock(href=Href('/'), abs_href=Href('http://localhost/'),
perm=MockPerm())
for name in args:
wiki = WikiPage(env, name)
if not wiki.exists:
continue
context = web_context(req, wiki.resource)
out = DummyIO()
DefaultWikiChecker(env, context, name).format(wiki.text, out)
示例3: add_pages
def add_pages(tc, names):
now = datetime.now(utc)
for name in names:
w = WikiPage(tc.env)
w.name = name
w.text = "--"
w.save("joe", "the page " + name, "::1", now)
示例4: copy_wiki_page
def copy_wiki_page(source_env, dest_env, name, dest_db=None):
# In case a string gets passed in
if not isinstance(source_env, Environment):
source_env = _open_environment(source_env)
if not isinstance(dest_env, Environment):
dest_env = _open_environment(dest_env)
# Log message
source_env.log.info('DatamoverPlugin: Moving page %s to the environment at %s', name, dest_env.path)
dest_env.log.info('DatamoverPlugin: Moving page %s from the environment at %s', name, source_env.path)
# Open databases
source_db = source_env.get_db_cnx()
source_cursor = source_db.cursor()
handle_commit = True
if not dest_db:
dest_db, handle_commit = dest_env.get_db_cnx(), False
dest_cursor = dest_db.cursor()
# Remove the page from the destination
dest_page = WikiPage(dest_env, name, db=dest_db)
if dest_page.exists:
dest_page.delete(db=dest_db)
# Copy each entry in the wiki table
source_cursor.execute('SELECT * FROM wiki WHERE name=%s',(name,))
for row in source_cursor:
wiki_data = dict(zip([d[0] for d in source_cursor.description], row))
q = make_query(wiki_data, 'wiki')
dest_cursor.execute(*q)
if handle_commit:
dest_db.commit()
示例5: get_default_version
def get_default_version(self, name):
"""Return default viewable version number for the named page.
Called when the wiki UI is rendering a page with no 'version='
in the HTTP request arguments.
In this method, you'd normally do db lookups and so on to
determine what the default viewable version of the named page
is, and then return it; for this example, we're just going to
pick a random page version instead.
"""
db = self.env.get_db_cnx()
page = WikiPage(self.env, name, 1)
history = page.get_history(all_versions=1)
try:
# get highest version number
(version,time,author,comment,ipnr) = history.next()
# here's a twist; we can enable Wikipedia-style talk
# pages which are *not* under workflow control
if name.endswith("/Talk"):
return version
# make some debug noise
import random, sys
print >>sys.stderr, "highest version", version
# randomize the version number
version = random.randint(1,version)
print >>sys.stderr, "random version", version
return version
except:
# returning None means that the default wiki "last edit
# wins" behavior will be used instead
return None
示例6: set_password
def set_password(self, user, password):
import re
if len(user) < 3:
raise TracError("user name must be at least 3 characters long")
if not re.match(r"^\w+$", user):
raise TracError("user name must consist only of alpha-numeric characters")
if user not in self.get_users():
from trac.wiki.model import WikiPage
db = self.env.get_db_cnx()
page = WikiPage(self.env, user, db=db)
# User creation with existing page
if page.exists:
raise TracError('wiki page "%s" already exists' % user)
else:
from tractags.api import TagEngine
tagspace = TagEngine(self.env).tagspace.wiki
tagspace.add_tags(None, user, ["user"])
page.text = """= %(user)s =\n\n[[ListTagged(%(user)s)]]\n\n[[TagIt(user)]]""" % {"user": user}
page.save(user, "New user %s registered" % user, None)
self.env.log.debug("New user %s registered" % user)
HtPasswdStore.set_password(self, user, password)
示例7: do_upgrade_environment
def do_upgrade_environment(db):
for realm in self.SCHEMA:
realm_schema = self.SCHEMA[realm]
if need_db_create_for_realm(self.env, realm, realm_schema, db):
create_db_for_realm(self.env, realm, realm_schema, db)
elif need_db_upgrade_for_realm(self.env, realm, realm_schema, db):
upgrade_db_for_realm(self.env, 'testmanager.upgrades', realm, realm_schema, db)
# Create default values for configuration properties and initialize counters
db_insert_or_ignore(self.env, 'testconfig', 'NEXT_CATALOG_ID', '0', db)
db_insert_or_ignore(self.env, 'testconfig', 'NEXT_TESTCASE_ID', '0', db)
db_insert_or_ignore(self.env, 'testconfig', 'NEXT_PLAN_ID', '0', db)
db.commit()
# Fix templates with a blank id
if self._check_blank_id_templates(db):
self._fix_blank_id_templates(db)
db.commit()
self.env.log.info(_("""
Test Manager templates with blank IDs have been fixed.\n
Please go to the Administration panel, in the Test Manager Templates
section, and check the associations between templates and Test Cases
and Test Catalogs.\n
You will have to manually fix any misconfiguration you should find.
"""))
# Create the basic "TC" Wiki page, used as the root test catalog
tc_page = WikiPage(self.env, 'TC')
if not tc_page.exists:
tc_page.text = ' '
tc_page.save('System', '', '127.0.0.1')
db.commit()
if self._need_upgrade(db):
# Set custom ticket field to hold related test case
custom = self.config['ticket-custom']
config_dirty = False
if 'testcaseid' not in custom:
custom.set('testcaseid', 'text')
custom.set('testcaseid.label', _("Test Case"))
config_dirty = True
if 'planid' not in custom:
custom.set('planid', 'text')
custom.set('planid.label', _("Test Plan"))
config_dirty = True
# Set config section for test case outcomes
if 'test-outcomes' not in self.config:
self.config.set('test-outcomes', 'green.SUCCESSFUL', _("Successful"))
self.config.set('test-outcomes', 'yellow.TO_BE_TESTED', _("Untested"))
self.config.set('test-outcomes', 'red.FAILED', _("Failed"))
self.config.set('test-outcomes', 'default', 'TO_BE_TESTED')
config_dirty = True
if config_dirty:
self.config.save()
示例8: main
def main():
names = sorted(name for name in resource_listdir('trac.wiki',
'default-pages')
if not name.startswith('.'))
env = EnvironmentStub()
load_components(env)
with env.db_transaction:
for name in names:
wiki = WikiPage(env, name)
wiki.text = resource_string('trac.wiki', 'default-pages/' +
name).decode('utf-8')
if wiki.text:
wiki.save('trac', '')
else:
printout('%s: Skipped empty page' % name)
req = Mock(href=Href('/'), abs_href=Href('http://trac.edgewall.org/'),
perm=MockPerm(), chrome={})
for name in sys.argv[1:]:
name = os.path.basename(name)
wiki = WikiPage(env, name)
if not wiki.exists:
continue
context = web_context(req, wiki.resource, absurls=True)
rst = wiki2rest(env, context, wiki)
sys.stdout.write(rst)
示例9: setUp
def setUp(self):
wiki = WikiPage(self.env)
wiki.name = 'WikiStart'
wiki.text = '--'
wiki.save('joe', 'Entry page', '::1', datetime.now(utc))
if self._setup:
self._setup(self)
示例10: _do_wiki_upgrade
def _do_wiki_upgrade(self):
"""Move all wiki pages starting with Trac prefix to unbranded user
guide pages.
"""
wiki_admin = WikiAdmin(self.env)
pages = wiki_admin.get_wiki_list()
for old_name in pages:
if old_name.startswith('Trac'):
new_name = wiki.new_name(old_name)
if not new_name:
continue
if new_name in pages:
printout(_('Ignoring %(page)s : '
'The page %(new_page)s already exists',
page=old_name, new_page=new_name))
continue
try:
wiki_admin._do_rename(old_name, new_name)
except AdminCommandError, exc:
printout(_('Error moving %(page)s : %(message)s',
page=old_name, message=unicode(exc)))
else:
# On success, rename links in other pages
self._do_wiki_rename_links(old_name, new_name)
# On success, insert redirection page
redirection = WikiPage(self.env, old_name)
redirection.text = _('See [wiki:"%(name)s"].', name=new_name)
comment = 'Bloodhound guide update'
redirection.save('bloodhound', comment, '0.0.0.0')
示例11: _get_interwiki_map
def _get_interwiki_map(self):
from trac.wiki.model import WikiPage
if self._interwiki_map is None:
self._interwiki_lock.acquire()
try:
if self._interwiki_map is None:
self._interwiki_map = {}
content = WikiPage(self.env, InterWikiMap._page_name).text
in_map = False
for line in content.split('\n'):
if in_map:
if line.startswith('----'):
in_map = False
else:
m = re.match(InterWikiMap._interwiki_re, line)
if m:
prefix, url, title = m.groups()
url = url.strip()
title = title and title.strip() or prefix
self[prefix] = (prefix, url, title)
elif line.startswith('----'):
in_map = True
finally:
self._interwiki_lock.release()
return self._interwiki_map
示例12: save_wiki_data
def save_wiki_data(self, req):
page = WikiPage(self.env, self.name)
if not page.exists:
self.log.error('Wiki page "%s" doesn\'t exist' % self.name)
return None
lines = page.text.split('\n')
first = -1
last = -1
new_lines = []
for index, line in enumerate(lines):
if first < 0:
new_lines.append(line)
if self.data_start_regexp.match(line):
first = index + 1
new_lines.append(self.get_json(False, True))
elif last < 0:
if self.data_end_regexp.match(line):
last = index - 1
new_lines.append(line)
else:
new_lines.append(line)
if last > 0:
page.text = '\n'.join(new_lines)
try:
page.save(req.authname, 'Kanban board data changed', req.remote_addr)
except TracError as e:
self.log.error('TracError: "%s"' % e.message)
示例13: getPageInfo
def getPageInfo(self, req, pagename, version=None):
""" Returns information about the given page. """
page = WikiPage(self.env, pagename, version)
if page.exists:
last_update = page.get_history().next()
return self._page_info(page.name, last_update[1], last_update[2],
page.version)
示例14: interwiki_map
def interwiki_map(self):
"""Map from upper-cased namespaces to (namespace, prefix, title)
values.
"""
from trac.wiki.model import WikiPage
map = {}
content = WikiPage(self.env, InterWikiMap._page_name).text
in_map = False
for line in content.split('\n'):
if in_map:
if line.startswith('----'):
in_map = False
else:
m = re.match(InterWikiMap._interwiki_re, line)
if m:
prefix, url, title = m.groups()
url = url.strip()
title = title.strip() if title else prefix
map[prefix.upper()] = (prefix, url, title)
elif line.startswith('----'):
in_map = True
for prefix, value in self.interwiki_section.options():
value = value.split(None, 1)
if value:
url = value[0].strip()
title = value[1].strip() if len(value) > 1 else prefix
map[prefix.upper()] = (prefix, url, title)
return map
示例15: import_wiki_pages
def import_wiki_pages(self, template_path):
"""Creates wiki pages from wiki.xml template file.
Creates wiki pages inside the project using data extracted from
an wiki.ml file. We don't set the author or version as that wouldn't
be applicable to a new project.
"""
# open the wiki XML file, parse the data and create wiki pages
full_path = os.path.join(template_path, 'wiki.xml')
try:
tree = ET.ElementTree(file=full_path)
for page in tree.getroot():
if page.text:
wikipage = WikiPage(self.env, page.attrib['name'])
wikipage.readonly = int(page.attrib['readonly']) # we store as a string in xml
wikipage.text = page.text
wikipage.save(None, None, None)
self.log.info("Wiki page %s created", page.attrib['name'])
else:
self.log.debug("Cannot create wiki pages with no text. "
"Unable to import %s", wikipage)
except IOError as exception:
if exception.errno == errno.ENOENT:
self.log.info("Path to wiki.xml file %s does not exist. Unable "
"to import wiki pages from template.", full_path)