本文整理汇总了Python中trac.util.shorten_line函数的典型用法代码示例。如果您正苦于以下问题:Python shorten_line函数的具体用法?Python shorten_line怎么用?Python shorten_line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shorten_line函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_search_results
def get_search_results(self, req, terms, filters):
if not 'discussion' in filters:
return
# Create context.
context = Context.from_request(req)
context.realm = 'discussion-core'
# Get database access.
db = self.env.get_db_cnx()
cursor = db.cursor()
# Search in topics.
query, args = search_to_sql(db, ['author', 'subject', 'body'], terms)
columns = ('id', 'forum', 'time', 'subject', 'body', 'author')
sql = ("SELECT id, forum, time, subject, body, author "
"FROM topic "
" WHERE %s" % (query,))
self.log.debug(sql)
cursor.execute(sql, args)
for row in cursor:
row = dict(zip(columns, row))
row['time'] = to_datetime(row['time'], utc)
yield (req.href.discussion('topic', row['id']) + '#-1',
"Topic #%d: %s" % (row['id'], shorten_line(row['subject'])),
row['time'], row['author'], shorten_result(row['body'], [query]))
# Search in messages
query, args = search_to_sql(db, ['m.author', 'm.body',
't.subject'], terms)
columns = ('id', 'forum', 'topic', 'time', 'author', 'body', 'subject')
sql = ("SELECT m.id, m.forum, m.topic, m.time, m.author, m.body, "
"t.subject "
"FROM message m "
"LEFT JOIN "
"(SELECT subject, id "
"FROM topic) t "
"ON t.id = m.topic "
"WHERE %s" % (query))
self.log.debug(sql)
cursor.execute(sql, args)
for row in cursor:
row = dict(zip(columns, row))
row['time'] = to_datetime(row['time'], utc)
yield (req.href.discussion('message', row['id']) + '#%s' % (
row['id']), "Message #%d: %s" % (row['id'], shorten_line(
row['subject'])), row['time'], row['author'], shorten_result(
row['body'], [query]))
示例2: _format_sha_link
def _format_sha_link(self, formatter, sha, label):
# FIXME: this function needs serious rethinking...
reponame = ''
context = formatter.context
while context:
if context.resource.realm in ('source', 'changeset'):
reponame = context.resource.parent.id
break
context = context.parent
try:
repos = self.env.get_repository(reponame)
if not repos:
raise Exception("Repository '%s' not found" % reponame)
sha = repos.normalize_rev(sha) # in case it was abbreviated
changeset = repos.get_changeset(sha)
return tag.a(label, class_='changeset',
title=shorten_line(changeset.message),
href=formatter.href.changeset(sha, repos.reponame))
except Exception, e:
return tag.a(label, class_='missing changeset',
title=to_unicode(e), rel='nofollow')
示例3: get_search_results
def get_search_results(self, req, query, filters):
if not "discussion" in filters:
return
# Create database context
db = self.env.get_db_cnx()
cursor = db.cursor()
# Search in topics.
columns = ("id", "forum", "time", "subject", "body", "author")
sql = "SELECT id, forum, time, subject, body, author FROM topic" " WHERE subject || body LIKE '%%%s%%'" % (
query
)
self.log.debug(sql)
cursor.execute(sql)
for row in cursor:
row = dict(zip(columns, row))
yield (
self.env.href.discussion(row["forum"], row["id"]) + "#-1",
"topic: %d: %s" % (row["id"], util.shorten_line(row["subject"])),
row["time"],
row["author"],
shorten_result(row["body"], query.split()),
)
# Search in messages
columns = ("id", "forum", "topic", "time", "author", "body", "subject")
sql = (
"SELECT id, forum, topic, time, author, body, (SELECT"
" subject FROM topic t WHERE t.id = message.topic) FROM message"
" WHERE body LIKE '%%%s%%'" % (query)
)
self.log.debug(sql)
cursor.execute(sql)
for row in cursor:
row = dict(zip(columns, row))
yield (
self.env.href.discussion(row["forum"], row["topic"], row["id"]) + "#%s" % (row["id"]),
"message: %d: %s" % (row["id"], util.shorten_line(row["subject"])),
row["time"],
row["author"],
shorten_result(row["body"], query.split()),
)
示例4: _format_link
def _format_link(self, formatter, ns, target, label):
cursor = formatter.db.cursor()
cursor.execute("SELECT subject,id FROM mailarc WHERE messageid = %s" , (target,))
row = cursor.fetchone()
if row:
subject = util.escape(util.shorten_line(row[0]))
return '<a href="%s" title="%s">%s</a>' \
% (formatter.href.mailarchive(row[1]), subject, label)
else:
return label
示例5: _format_sha_link
def _format_sha_link(self, formatter, original_sha, label):
for repository in RepositoryManager(self.env).get_real_repositories():
try:
sha = repository.normalize_rev(original_sha) # in case it was abbreviated
changeset = repository.get_changeset(sha)
return tag.a(label, class_='changeset',
title=shorten_line(changeset.message),
href=formatter.href.changeset(sha, repository.reponame))
except Exception, e:
pass
示例6: _format_sha_link
def _format_sha_link(self, formatter, ns, sha, label, fullmatch=None):
try:
changeset = self.env.get_repository().get_changeset(sha)
return tag.a(label, class_="changeset",
title=shorten_line(changeset.message),
href=formatter.href.changeset(sha))
except TracError, e:
return tag.a(label, class_="missing changeset",
href=formatter.href.changeset(sha),
title=unicode(e), rel="nofollow")
示例7: _format_link
def _format_link(self, formatter, ns, rev, label):
cursor = formatter.db.cursor()
cursor.execute('SELECT message FROM revision WHERE rev=%s', (rev,))
row = cursor.fetchone()
if row:
return '<a class="changeset" title="%s" href="%s">%s</a>' \
% (util.escape(util.shorten_line(row[0])),
formatter.href.changeset(rev), label)
else:
return '<a class="missing changeset" href="%s" rel="nofollow">%s</a>' \
% (formatter.href.changeset(rev), label)
示例8: _entry_to_hdf
def _entry_to_hdf(req, entry):
return {
'id': entry.id,
'time': format_datetime(entry.time),
'timedelta': pretty_timedelta(entry.time),
'path': entry.path,
'url': req.abs_href(entry.path),
'path_clipped': shorten_line(entry.path, 25),
'href': req.href(entry.path),
'admin_href': req.href.admin('spamfilter', 'monitor', entry.id),
'author': entry.author,
'author_clipped': shorten_line(entry.author, 25),
'ipnr': entry.ipnr,
'authenticated': entry.authenticated,
'headers': entry.headers,
'content': shorten_line(entry.content),
'full_content': entry.content,
'rejected': entry.rejected,
'karma': entry.karma, 'reasons': entry.reasons
}
示例9: rev_link
def rev_link(rev, label=None):
try:
reponame = context.resource.parent.id
repos = self.env.get_repository(reponame)
return tag.a(label, class_="changeset",
title=shorten_line(label),
href=context.href.browser(repos.reponame) + '?rev=%s' % rev)
except Exception, e:
return tag.a(sha, class_="missing tag",
title=to_unicode(e), rel="nofollow")
示例10: _format_link
def _format_link(self, formatter, ns, target, label):
cursor = formatter.db.cursor()
cursor.execute("SELECT summary,status FROM ticket WHERE id=%s",
(target,))
row = cursor.fetchone()
if row:
summary = util.escape(util.shorten_line(row[0]))
return '<a class="%s ticket" href="%s" title="%s (%s)">%s</a>' \
% (row[1], formatter.href.ticket(target), summary, row[1],
label)
else:
return '<a class="missing ticket" href="%s" rel="nofollow">%s</a>' \
% (formatter.href.ticket(target), label)
示例11: get_search_results
def get_search_results(self, req, query, filters):
if not 'changeset' in filters:
return
authzperm = SubversionAuthorizer(self.env, req.authname)
db = self.env.get_db_cnx()
sql, args = query_to_sql(db, query, 'message||author')
cursor = db.cursor()
cursor.execute("SELECT rev,time,author,message "
"FROM revision WHERE " + sql, args)
for rev, date, author, log in cursor:
if not authzperm.has_permission_for_changeset(rev):
continue
yield (self.env.href.changeset(rev),
'[%s]: %s' % (rev, util.shorten_line(log)),
date, author, shorten_result(log, query.split()))
示例12: get_search_results
def get_search_results(self, req, keywords, filters):
if not 'discussion' in filters:
return
# Create database context
db = self.env.get_db_cnx()
cursor = db.cursor()
# Search in topics.
query = ' '.join(keywords)
columns = ('id', 'forum', 'time', 'subject', 'body', 'author')
sql = "SELECT id, forum, time, subject, body, author FROM topic" \
" WHERE subject || body LIKE '%%%s%%'" % (query)
self.log.debug(sql)
cursor.execute(sql)
for row in cursor:
row = dict(zip(columns, row))
yield (req.href.discussion(row['forum'], row['id']) + '#-1',
"topic: %d: %s" % (row['id'], util.shorten_line(row['subject'])),
row['time'], row['author'], shorten_result(row['body'],
[query]))
# Search in messages
columns = ('id', 'forum', 'topic', 'time', 'author', 'body', 'subject')
sql = "SELECT m.id, m.forum, m.topic, m.time, m.author, m.body," \
" t.subject FROM message m LEFT JOIN (SELECT subject, id FROM" \
" topic) t ON t.id = m.topic WHERE body LIKE '%%%s%%'" \
% (query)
self.log.debug(sql)
cursor.execute(sql)
for row in cursor:
row = dict(zip(columns, row))
yield (req.href.discussion(row['forum'], row['topic'], row['id'])
+ '#%s' % (row['id']), "message: %d: %s" % (row['id'],
util.shorten_line(row['subject'])), row['time'], row['author'],
shorten_result(row['body'], [query]))
示例13: sha_link
def sha_link(sha, label=None):
# sha is assumed to be a non-abbreviated 40-chars sha id
try:
reponame = context.resource.parent.id
repos = self.env.get_repository(reponame)
cset = repos.get_changeset(sha)
if label is None:
label = repos.display_rev(sha)
return tag.a(label, class_='changeset',
title=shorten_line(cset.message),
href=context.href.changeset(sha, repos.reponame))
except Exception, e:
return tag.a(sha, class_='missing changeset',
title=to_unicode(e), rel='nofollow')
示例14: _pydoc_formatter
def _pydoc_formatter(self, formatter, ns, object, label):
object = urllib.unquote(object)
label = urllib.unquote(label)
if not object or object == 'index':
return '<a class="wiki" href="%s">%s</a>' % \
(formatter.href.pydoc(), label)
else:
try:
_, target = PyDoc(self.env).load_object(object)
doc = pydoc.getdoc(target)
if doc: doc = doc.strip().splitlines()[0]
return '<a class="wiki" title="%s" href="%s">%s</a>' % \
(shorten_line(doc), formatter.href.pydoc(object), label)
except ImportError:
return '<a class="missing wiki" href="%s">%s?</a>' % \
(formatter.href.pydoc(object), label)
示例15: _format_sha_link
def _format_sha_link(self, context, sha, label):
reponame = ''
while context:
if context.resource.realm in ('source', 'changeset'):
reponame = context.resource.parent.id
break
context = context.parent
repos = self.env.get_repository(reponame)
if repos:
try:
changeset = repos.get_changeset(sha)
return tag.a(label, class_="changeset",
title=shorten_line(changeset.message),
href=context.href.changeset(sha, reponame))
except NoSuchChangeset, e:
errmsg = to_unicode(e)