本文整理汇总了Python中trac.util.translation._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rename
def rename(self, new_name):
"""Rename wiki page in-place, keeping the history intact.
Renaming a page this way will eventually leave dangling references
to the old page - which litterally doesn't exist anymore.
"""
assert self.exists, "Cannot rename non-existent page"
if not validate_page_name(new_name):
raise TracError(_("Invalid Wiki page name '%(name)s'",
name=new_name))
old_name = self.name
with self.env.db_transaction as db:
new_page = WikiPage(self.env, new_name)
if new_page.exists:
raise TracError(_("Can't rename to existing %(name)s page.",
name=new_name))
db("UPDATE wiki SET name=%s WHERE name=%s", (new_name, old_name))
# Invalidate page name cache
del WikiSystem(self.env).pages
# Reparent attachments
from trac.attachment import Attachment
Attachment.reparent_all(self.env, 'wiki', old_name, 'wiki',
new_name)
self.name = new_name
self.env.log.info('Renamed page %s to %s', old_name, new_name)
for listener in WikiSystem(self.env).change_listeners:
if hasattr(listener, 'wiki_page_renamed'):
listener.wiki_page_renamed(self, old_name)
示例2: render_usermanager_admin_panel
def render_usermanager_admin_panel(self, req, panel, user, path_info):
user_actions = self._get_user_permissions(user)
all_user_actions = PermissionSystem(self.env).get_user_permissions(user.username)
actions = PermissionSystem(self.env).get_actions()+list(set([group for group, permissions in PermissionSystem(self.env).get_all_permissions()]))
data = dict(actions=actions,
all_user_actions=all_user_actions,
user_actions=user_actions,
permsys = PermissionSystem(self.env),
messages=[], errors=[])
if req.method=="POST":
updated_user_permissions = req.args.getlist('um_permission')
for action in actions:
if action in updated_user_permissions:
if not all_user_actions.has_key(action):
try:
PermissionSystem(self.env).grant_permission(user.username, action)
data['messages'].append(_("Granted permission [%s] for user [%s].")%(action, user.username))
except Exception, e:
data['errors'].append(e)
else:
if user_actions.has_key(action):
try:
PermissionSystem(self.env).revoke_permission(user.username, action)
data['messages'].append(_("Revoked permission [%s] for user [%s].")%(action, user.username))
except Exception, e:
data['errors'].append(e)
示例3: _do_list
def _do_list(self):
print_table([(m.name, m.due and
format_date(m.due, console_date_format),
m.completed and
format_datetime(m.completed, console_datetime_format))
for m in model.Milestone.select(self.env)],
[_("Name"), _("Due"), _("Completed")])
示例4: __init__
def __init__(self, path, rev, msg=None):
if msg is None:
msg = _("No node %(path)s at revision %(rev)s", path=path, rev=rev)
else:
msg = _("%(msg)s: No node %(path)s at revision %(rev)s",
msg=msg, path=path, rev=rev)
ResourceNotFound.__init__(self, msg, _('No such node'))
示例5: check_header
def check_header(self, header):
"""Check the headers for mandatory fields"""
if not ((Key.ID in header) or ("ticket" in header)):
return _("Header must contain '%s' or '%s'") % (Key.ID, "ticket")
if not (Key.SUMMARY in header):
return _("Header must contain '%s'") % Key.SUMMARY
return None
示例6: _sync
def _sync(self, reponame, rev, clean):
rm = RepositoryManager(self.env)
if reponame == '*':
if rev is not None:
raise TracError(_('Cannot synchronize a single revision '
'on multiple repositories'))
repositories = rm.get_real_repositories()
else:
if is_default(reponame):
reponame = ''
repos = rm.get_repository(reponame)
if repos is None:
raise TracError(_("Repository '%(repo)s' not found",
repo=reponame or '(default)'))
if rev is not None:
repos.sync_changeset(rev)
printout(_('%(rev)s resynced on %(reponame)s.', rev=rev,
reponame=repos.reponame or '(default)'))
return
repositories = [repos]
db = self.env.get_db_cnx()
for repos in sorted(repositories, key=lambda r: r.reponame):
printout(_('Resyncing repository history for %(reponame)s... ',
reponame=repos.reponame or '(default)'))
repos.sync(self._sync_feedback, clean=clean)
cursor = db.cursor()
cursor.execute("SELECT count(rev) FROM revision WHERE repos=%s",
(repos.id,))
for cnt, in cursor:
printout(ngettext('%(num)s revision cached.',
'%(num)s revisions cached.', num=cnt))
printout(_('Done.'))
示例7: modify_repository
def modify_repository(self, reponame, changes):
"""Modify attributes of a repository."""
if is_default(reponame):
reponame = ''
new_reponame = changes.get('name', reponame)
if is_default(new_reponame):
new_reponame = ''
rm = RepositoryManager(self.env)
with self.env.db_transaction as db:
id = rm.get_repository_id(reponame)
if reponame != new_reponame:
if db("""SELECT id FROM repository WHERE name='name' AND
value=%s""", (new_reponame,)):
raise TracError(_('The repository "%(name)s" already '
'exists.',
name=new_reponame or '(default)'))
for (k, v) in changes.iteritems():
if k not in self.repository_attrs:
continue
if k in ('alias', 'name') and is_default(v):
v = ''
if k == 'dir' and not os.path.isabs(v):
raise TracError(_("The repository directory must be "
"absolute"))
db("UPDATE repository SET value=%s WHERE id=%s AND name=%s",
(v, id, k))
if not db(
"SELECT value FROM repository WHERE id=%s AND name=%s",
(id, k)):
db("""INSERT INTO repository (id, name, value)
VALUES (%s, %s, %s)
""", (id, k, v))
rm.reload_repositories()
示例8: get_navigation_items
def get_navigation_items(self, req):
# The 'Admin' navigation item is only visible if at least one
# admin panel is available
panels, providers = self._get_panels(req)
if panels:
yield ('mainnav', 'monitoring', tag.a(_('Monitoring'),
href=req.href.monitoring(), title=_('Monitoring')))
示例9: pre_process_request
def pre_process_request(self, req, handler):
if req.path_info.startswith('/admin/ticket/components/'):
if req.method == "POST" and 'renamechildren' in req.args:
if req.args.get('renamechildren') != 'on':
return handler # Let trac handle this update
# First process the parent component.
parentcomponentname = req.path_info[25:]
parentcomponent = model.Component(self.env, parentcomponentname)
parentcomponent.name = req.args.get('name')
parentcomponent.owner = req.args.get('owner')
parentcomponent.description = req.args.get('description')
try:
parentcomponent.update()
except self.env.db_exc.IntegrityError:
raise TracError(_('The component "%(name)s" already '
'exists.', name=parentcomponentname))
# Now update the child components
childcomponents = self._get_component_children(parentcomponentname)
for component in childcomponents:
component.name = component.name.replace(parentcomponentname, req.args.get('name'), 1)
component.update()
add_notice(req, _('Your changes have been saved.'))
req.redirect(req.href.admin('ticket', 'components'))
return handler
示例10: _do_delete
def _do_delete(self, req, milestone):
req.perm(milestone.resource).require('MILESTONE_DELETE')
retarget_to = req.args.get('target') or None
# Don't translate ticket comment (comment:40:ticket:5658)
retargeted_tickets = \
milestone.move_tickets(retarget_to, req.authname,
"Ticket retargeted after milestone deleted")
milestone.delete(author=req.authname)
add_notice(req, _('The milestone "%(name)s" has been deleted.',
name=milestone.name))
if retargeted_tickets:
add_notice(req, _('The tickets associated with milestone '
'"%(name)s" have been retargeted to milestone '
'"%(retarget)s".', name=milestone.name,
retarget=retarget_to))
new_values = {'milestone': retarget_to}
comment = _("Tickets retargeted after milestone deleted")
tn = BatchTicketNotifyEmail(self.env)
try:
tn.notify(retargeted_tickets, new_values, comment, None,
req.authname)
except Exception, e:
self.log.error("Failure sending notification on ticket batch "
"change: %s", exception_to_unicode(e))
add_warning(req, tag_("The changes have been saved, but an "
"error occurred while sending "
"notifications: %(message)s",
message=to_unicode(e)))
示例11: _render_editor
def _render_editor(self, req, id, copy):
if id != -1:
req.perm.require("REPORT_MODIFY")
for title, description, query in self.env.db_query(
"SELECT title, description, query FROM report WHERE id=%s", (id,)
):
break
else:
raise TracError(_("Report {%(num)s} does not exist.", num=id), _("Invalid Report Number"))
else:
req.perm.require("REPORT_CREATE")
title = description = query = ""
# an explicitly given 'query' parameter will override the saved query
query = req.args.get("query", query)
if copy:
title += " (copy)"
if copy or id == -1:
data = {"title": _("Create New Report"), "action": "new", "error": None}
else:
data = {
"title": _("Edit Report {%(num)d} %(title)s", num=id, title=title),
"action": "edit",
"error": req.args.get("error"),
}
data["report"] = {"id": id, "title": title, "sql": query, "description": description}
return data
示例12: _render_editor
def _render_editor(self, req, id, copy):
if id != -1:
req.perm.require('REPORT_MODIFY')
for title, description, query in self.env.db_query(
"SELECT title, description, query FROM report WHERE id=%s",
(id,)):
break
else:
raise TracError(_("Report {%(num)s} does not exist.", num=id),
_("Invalid Report Number"))
else:
req.perm.require('REPORT_CREATE')
title = description = query = ''
# an explicitly given 'query' parameter will override the saved query
query = req.args.get('query', query)
if copy:
title += ' (copy)'
if copy or id == -1:
data = {'title': _('Create New Report'),
'action': 'new',
'error': None}
else:
data = {'title': _('Edit Report {%(num)d} %(title)s', num=id,
title=title),
'action': 'edit',
'error': req.args.get('error')}
data['report'] = {'id': id, 'title': title,
'sql': query, 'description': description}
return data
示例13: _launch
def _launch(self, encoded_input, *args):
"""Launch a process (cmd), and returns exitcode, stdout + stderr"""
# Note: subprocess.Popen doesn't support unicode options arguments
# (http://bugs.python.org/issue1759845) so we have to encode them.
# Anyway, dot expects utf-8 or the encoding specified with -Gcharset.
encoded_cmd = []
for arg in args:
if isinstance(arg, unicode):
arg = arg.encode(self.encoding, 'replace')
encoded_cmd.append(arg)
p = subprocess.Popen(encoded_cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if encoded_input:
p.stdin.write(encoded_input)
p.stdin.close()
out = p.stdout.read()
err = p.stderr.read()
failure = p.wait() != 0
if failure or err or out:
return (failure, tag.p(tag.br(), _("The command:"),
tag.pre(repr(' '.join(encoded_cmd))),
(_("succeeded but emitted the following output:"),
_("failed with the following output:"))[failure],
out and tag.pre(repr(out)),
err and tag.pre(repr(err))))
else:
return (False, None)
示例14: process_request
def process_request(self, req):
presel = req.args.get('preselected')
if presel and (presel + '/').startswith(req.href.browser() + '/'):
req.redirect(presel)
path = req.args.get('path', '/')
rev = req.args.get('rev', '')
if rev.lower() in ('', 'head'):
rev = None
format = req.args.get('format')
order = req.args.get('order', 'name').lower()
desc = 'desc' in req.args
xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest'
rm = RepositoryManager(self.env)
all_repositories = rm.get_all_repositories()
reponame, repos, path = rm.get_repository_by_path(path)
# Repository index
show_index = not reponame and path == '/'
if show_index:
if repos and (as_bool(all_repositories[''].get('hidden'))
or not repos.is_viewable(req.perm)):
repos = None
if not repos and reponame:
raise ResourceNotFound(_("Repository '%(repo)s' not found",
repo=reponame))
if reponame and reponame != repos.reponame: # Redirect alias
qs = req.query_string
req.redirect(req.href.browser(repos.reponame or None, path)
+ ('?' + qs if qs else ''))
reponame = repos.reponame if repos else None
# Find node for the requested path/rev
context = web_context(req)
node = None
changeset = None
display_rev = lambda rev: rev
if repos:
try:
if rev:
rev = repos.normalize_rev(rev)
# If `rev` is `None`, we'll try to reuse `None` consistently,
# as a special shortcut to the latest revision.
rev_or_latest = rev or repos.youngest_rev
node = get_existing_node(req, repos, path, rev_or_latest)
except NoSuchChangeset, e:
raise ResourceNotFound(e, _('Invalid changeset number'))
if node:
try:
# use changeset instance to retrieve branches and tags
changeset = repos.get_changeset(node.rev)
except NoSuchChangeset:
pass
context = context.child(repos.resource.child('source', path,
version=rev_or_latest))
display_rev = repos.display_rev
示例15: get_navigation_items
def get_navigation_items(self, req):
if 'WIKI_VIEW' in req.perm('wiki'):
yield ('mainnav', 'wiki',
tag.a(_('Wiki'), href=req.href.wiki(), accesskey=1))
yield ('metanav', 'help',
tag.a(_('Help/Guide'), href=req.href.wiki('TracGuide'),
accesskey=6))