本文整理汇总了Python中tractags.api.TagEngine类的典型用法代码示例。如果您正苦于以下问题:Python TagEngine类的具体用法?Python TagEngine怎么用?Python TagEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TagEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: process_request
def process_request(self, req):
from tractags.api import TagEngine
from trac.web.chrome import add_stylesheet
add_stylesheet(req, 'tags/css/tractags.css')
pagename = req.args.get('page', 'WikiStart')
action = req.args.get('action', 'view')
engine = TagEngine(self.env)
wikitags = engine.tagspace.wiki
tags = list(wikitags.get_tags([pagename]))
tags.sort()
if action == 'edit':
req.hdf['tags'] = req.args.get('tags', ', '.join(tags))
elif action == 'view':
hdf_tags = []
for tag in tags:
href, title = engine.get_tag_link(tag)
hdf_tags.append({'name': tag,
'href': href,
'title': title})
req.hdf['tags'] = hdf_tags
result = WikiModule.process_request(self, req)
if result is None:
return None
if result[0] == 'wiki.cs':
return 'tagswiki.cs', None
return result
示例3: render_listtags
def render_listtags(self, req, *tags, **kwargs):
""" List tags. For backwards compatibility, can accept a list of tags.
This will simply call ListTagged. Optional keyword arguments are
tagspace=wiki, tagspaces=(wiki, ticket, ...) and shownames=true. """
if tags:
# Backwards compatibility
return self.render_listtagged(req, *tags, **kwargs)
page = self._current_page(req)
engine = TagEngine(self.env)
showpages = kwargs.get('showpages', None) or kwargs.get('shownames', 'false')
if 'tagspace' in kwargs:
tagspaces = [kwargs['tagspace']]
else:
tagspaces = kwargs.get('tagspaces', []) or \
list(TagEngine(self.env).tagspaces)
out = StringIO()
out.write('<ul class="listtags">\n')
tag_details = {}
for tag, names in sorted(engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems()):
href, title = engine.get_tag_link(tag)
htitle = wiki_to_oneliner(title, self.env)
out.write('<li><a href="%s" title="%s">%s</a> %s <span class="tagcount">(%i)</span>' % (href, title, tag, htitle, len(names)))
if showpages == 'true':
out.write('\n')
out.write(self.render_listtagged(req, tag, tagspaces=tagspaces))
out.write('</li>\n')
out.write('</ul>\n')
return out.getvalue()
示例4: _update_tags
def _update_tags(self, req, page):
newtags = set([t.strip() for t in
_tag_split.split(req.args.get('tags')) if t.strip()])
wikitags = TagEngine(self.env).tagspace.wiki
oldtags = wikitags.get_tags([page.name])
if oldtags != newtags:
wikitags.replace_tags(req, page.name, newtags)
示例5: _page_titles
def _page_titles(self, pages):
""" Extract page titles, if possible. """
titles = {}
tagspace = TagEngine(self.env).tagspace.wiki
for pagename in pages:
href, link, title = tagspace.name_details(pagename)
titles[pagename] = title
return titles
示例6: render_listtagged
def render_listtagged(self, req, *tags, **kwargs):
""" List tagged objects. Optionally accepts a list of tags to match
against. The special tag '''. (dot)''' inserts the current Wiki page name.
`[[ListTagged(<tag>, ...)]]`
||'''Argument'''||'''Description'''||
||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
||`operation=intersection|union`||The set operation to perform on the discovered objects.||
||`showheadings=true|false`||List objects under the tagspace they occur in.||
"""
if 'tagspace' in kwargs:
tagspaces = [kwargs.get('tagspace', None)]
else:
tagspaces = kwargs.get('tagspaces', '') or \
list(TagEngine(self.env).tagspaces)
showheadings = kwargs.get('showheadings', 'false')
operation = kwargs.get('operation', 'intersection')
if operation not in ('union', 'intersection'):
raise TracError("Invalid tag set operation '%s'" % operation)
engine = TagEngine(self.env)
page_name = req.hdf.get('wiki.page_name')
if page_name:
tags = [tag == '.' and page_name or tag for tag in tags]
taginfo = {}
out = StringIO()
out.write('<ul class="listtagged">')
# Cull empty names
tagged_names = [(tagspace, names) for tagspace, names in
engine.get_tagged_names(tags=tags, tagspaces=tagspaces,
operation=operation, detailed=True).iteritems()
if names]
for tagspace, tagspace_names in sorted(tagged_names):
if showheadings == 'true':
out.write('<lh>%s tags</lh>' % tagspace)
for name, tags in sorted(tagspace_names.iteritems()):
if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue
tags = sorted(tags)
taginfo = self._tag_details(taginfo, tags)
href, link, title = engine.name_details(tagspace, name)
htitle = wiki_to_oneliner(title, self.env)
name_tags = ['<a href="%s" title="%s">%s</a>'
% (taginfo[tag][0], taginfo[tag][1], tag)
for tag in tags]
if not name_tags:
name_tags = ''
else:
name_tags = ' (' + ', '.join(sorted(name_tags)) + ')'
out.write('<li>%s %s%s</li>\n' %
(link, htitle, name_tags))
out.write('</ul>')
return out.getvalue()
示例7: render_tagcloud
def render_tagcloud(self, req, smallest=10, biggest=20, tagspace=None, tagspaces=[]):
""" Display a summary of all tags, with the font size reflecting the
number of pages the tag applies to. Font size ranges from 10 to 22
pixels, but this can be overridden by the smallest=n and biggest=n
macro parameters. By default, all tagspaces are displayed, but this
can be overridden with tagspaces=(wiki, ticket) or tagspace=wiki."""
smallest = int(smallest)
biggest = int(biggest)
engine = TagEngine(self.env)
# Get wiki tagspace
if tagspace:
tagspaces = [tagspace]
else:
tagspaces = tagspaces or engine.tagspaces
cloud = {}
for tag, names in engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems():
cloud[tag] = len(names)
tags = cloud.keys()
# No tags?
if not tags: return ''
# by_count maps tag counts to an index in the set of counts
by_count = list(set(cloud.values()))
by_count.sort()
by_count = dict([(c, float(i)) for i, c in enumerate(by_count)])
taginfo = self._tag_details({}, tags)
tags.sort()
rlen = float(biggest - smallest)
tlen = float(len(by_count))
scale = 1.0
if tlen:
scale = rlen / tlen
out = StringIO()
out.write('<ul class="tagcloud">\n')
last = tags[-1]
for tag in tags:
if tag == last:
cls = ' class="last"'
else:
cls = ''
out.write('<li%s><a rel="tag" title="%s" style="font-size: %ipx" href="%s">%s</a> <span class="tagcount">(%i)</span></li>\n' % (
cls,
taginfo[tag][1],
smallest + int(by_count[cloud[tag]] * scale),
taginfo[tag][0],
tag,
cloud[tag]))
out.write('</ul>\n')
return out.getvalue()
示例8: getDetails
def getDetails(self, req, hack):
""" Fetch hack details. Returns dict with name, dependencies and
description. """
from tractags.api import TagEngine
wikitags = TagEngine(self.env).tagspace.wiki
tags = wikitags.get_tags(hack)
types = self.getTypes()
hacks = wikitags.get_tagged_names(types)
dependencies = hacks.intersection(tags)
href, htmllink, description = wikitags.name_details(hack)
return {"name": hack, "dependencies": tuple(dependencies), "description": description}
示例9: render_listtagged
def render_listtagged(self, req, *tags, **kwargs):
""" List tagged objects. Takes a list of tags to match against.
The special tag '.' inserts the current Wiki page name.
Optional keyword arguments are tagspace=wiki,
tagspaces=(wiki, title, ...) and showheadings=true.
By default displays the intersection of objects matching each tag.
By passing operation=union this can be modified to display
the union of objects matching each tag.
"""
if 'tagspace' in kwargs:
tagspaces = [kwargs.get('tagspace', None)]
else:
tagspaces = kwargs.get('tagspaces', '') or \
list(TagEngine(self.env).tagspaces)
showheadings = kwargs.get('showheadings', 'false')
operation = kwargs.get('operation', 'intersection')
if operation not in ('union', 'intersection'):
raise TracError("Invalid tag set operation '%s'" % operation)
engine = TagEngine(self.env)
page_name = req.hdf.get('wiki.page_name')
if page_name:
tags = [tag == '.' and page_name or tag for tag in tags]
taginfo = {}
out = StringIO()
out.write('<ul class="listtagged">')
for tagspace, tagspace_names in sorted(engine.get_tagged_names(tags=tags, tagspaces=tagspaces, operation=operation, detailed=True).iteritems()):
if showheadings == 'true':
out.write('<lh>%s tags</lh>' % tagspace)
for name, tags in sorted(tagspace_names.iteritems()):
if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue
tags = sorted(tags)
taginfo = self._tag_details(taginfo, tags)
href, link, title = engine.name_details(tagspace, name)
htitle = wiki_to_oneliner(title, self.env)
name_tags = ['<a href="%s" title="%s">%s</a>'
% (taginfo[tag][0], taginfo[tag][1], tag)
for tag in tags]
if not name_tags:
name_tags = ''
else:
name_tags = ' (' + ', '.join(sorted(name_tags)) + ')'
out.write('<li>%s %s%s</li>\n' %
(link, htitle, name_tags))
out.write('</ul>')
return out.getvalue()
示例10: getNames
def getNames(self, req, tagname):
""" Returns all pages with tagname """
engine = TagEngine(self.env)
try:
tagspaces = list()
tagspaces.append(self.tagsystem.tagspace)
tags = list()
tags.append (tagname)
names = engine.get_tagged_names(tags=tags,tagspaces=tagspaces)
self.env.log.debug("getNames found %s for tagname %s"%(names, tagname))
return list(names[self.tagsystem.tagspace])
except Exception, e:
self.env.log.debug('Error in getNames(%s): %s\n' % (tagname, str(e)))
return None
示例11: download_deleted
def download_deleted(self, download):
tags = TagEngine(self.env).tagspace.downloads
# Prepare tag names.
self._resolve_ids(download)
tag_names = [download['author'], download['component'],
download['version'], download['architecture'],
download['platform'], download['type']]
if download['tags']:
tag_names.extend(download['tags'].split(' '))
# Add tags to download.
self.log.debug(tag_names)
tags.remove_tags(None, download['id'], list(sets.Set(tag_names)))
示例12: _wiki_view
def _wiki_view(self, req, stream):
tags = self._page_tags(req)
if not tags:
return stream
engine = TagEngine(self.env)
add_stylesheet(req, 'tags/css/tractags.css')
li = []
for tag in tags:
href, title = engine.get_tag_link(tag)
li.append(T.li(T.a(title=title, href=href)(tag), ' '))
insert = T.ul(class_='tags')(T.lh('Tags'), li)
return stream | Transformer('//div[@class="buttons"]').before(insert)
示例13: _do_save
def _do_save(self, req, db, page):
# This method is overridden so the user doesn't get "Page not modified"
# exceptions when updating tags but not wiki content.
from tractags.api import TagEngine
if 'tags' in req.args:
newtags = set([t.strip() for t in
_tag_split.split(req.args.get('tags')) if t.strip()])
wikitags = TagEngine(self.env).tagspace.wiki
oldtags = wikitags.get_tags([page.name])
if oldtags != newtags:
wikitags.replace_tags(req, page.name, newtags)
# No changes, just redirect
if req.args.get('text') == page.text:
req.redirect(self.env.href.wiki(page.name))
return
return WikiModule._do_save(self, req, db, page)
示例14: _prepare_wiki
def _prepare_wiki(self, req):
from tractags.api import TagEngine
page = req.path_info[6:] or 'WikiStart'
engine = TagEngine(self.env)
wikitags = engine.tagspace.wiki
tags = list(wikitags.get_tags(page))
tags.sort()
action = req.args.get('action', 'view')
if action == 'edit':
req.hdf['tags'] = req.args.get('tags', ', '.join(tags))
elif action == 'view':
hdf_tags = []
for tag in tags:
href, title = engine.get_tag_link(tag)
hdf_tags.append({'name': tag,
'href': href,
'title': title})
req.hdf['tags'] = hdf_tags
示例15: getHacks
def getHacks(self, req, release, type):
""" Fetch a list of hacks for Trac release, of type. """
from trac.versioncontrol.api import Node
from tractags.api import TagEngine
repo = self.env.get_repository(req.authname)
wikitags = TagEngine(self.env).tagspace.wiki
repo_rev = repo.get_youngest_rev()
releases = wikitags.get_tagged_names([release])
types = wikitags.get_tagged_names([type])
for plugin in releases.intersection(types):
if plugin.startswith("tags/"):
continue
path = "%s/%s" % (plugin.lower(), release)
rev = 0
if repo.has_node(str(path), repo_rev):
node = repo.get_node(path)
rev = node.rev
yield (plugin, rev)