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]))
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')
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()), )
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
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")
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
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 }
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)
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")
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)
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') show_files = int( self.config.get('timeline', 'changeset_show_files')) db = self.env.get_db_cnx() repos = self.env.get_repository() authzperm = SubversionAuthorizer(self.env, req.authname) rev = repos.youngest_rev while rev: if not authzperm.has_permission_for_changeset(rev): rev = repos.previous_rev(rev) continue chgset = repos.get_changeset(rev) if chgset.date < start: return if chgset.date < stop: message = chgset.message or '--' if format == 'rss': title = util.Markup('Changeset <em>[%s]</em>: %s', chgset.rev, util.shorten_line(message)) href = self.env.abs_href.changeset(chgset.rev) message = wiki_to_html(message, self.env, req, db, absurls=True) else: title = util.Markup('Changeset <em>[%s]</em> by %s', chgset.rev, chgset.author) href = self.env.href.changeset(chgset.rev) message = wiki_to_oneliner(message, self.env, db, shorten=True) if show_files: files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append('...') break files.append('<span class="%s">%s</span>' % (chg[2], util.escape(chg[0]))) message = '<span class="changes">' + ', '.join(files) +\ '</span>: ' + message yield 'changeset', href, title, chgset.date, chgset.author,\ util.Markup(message) rev = repos.previous_rev(rev)
def get_timeline_events(self, req, start, stop, filters): if 'ticket_details' in filters: db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute( "SELECT tc.time,tc.ticket,t.type,tc.field, " " tc.oldvalue,tc.newvalue,tc.author,t.summary " "FROM ticket_change tc" " INNER JOIN ticket t ON t.id = tc.ticket " "AND tc.time>=%s AND tc.time<=%s ORDER BY tc.time" % (start, stop)) previous_update = None updates = [] ticket_change = False for time, id, type, field, oldvalue, newvalue, author, summary in cursor: if not previous_update or (time, id, author) != previous_update[:3]: if previous_update and not ticket_change: updates.append( (previous_update, field_changes, comment)) ticket_change = False field_changes = [] comment = '' previous_update = (time, id, author, type, summary) if field == 'comment': comment = newvalue elif field == 'status' and newvalue in ['reopened', 'closed']: ticket_change = True else: field_changes.append(field) if previous_update and not ticket_change: updates.append((previous_update, field_changes, comment)) absurls = req.args.get('format') == 'rss' # Kludge for (t, id, author, type, summary), field_changes, comment in updates: if absurls: href = self.env.abs_href.ticket(id) else: href = self.env.href.ticket(id) title = 'Ticket <em title="%s">#%s</em> (%s) updated by %s' \ % (util.escape(summary), id, type, util.escape(author)) message = '' if len(field_changes) > 0: message = ', '.join(field_changes) + ' changed.<br />' message += wiki_to_oneliner(util.shorten_line(comment), self.env, db, absurls=absurls) yield 'editedticket', href, title, t, author, message
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]))
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()))
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)
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')
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 = RepositoryManager(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 as e: return tag.a(sha, class_='missing changeset', title=to_unicode(e), rel='nofollow')
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)
def get_search_results(self, req, query, filters): if not 'ticket' in filters: return db = self.env.get_db_cnx() sql = "SELECT DISTINCT a.summary,a.description,a.reporter, " \ "a.keywords,a.id,a.time FROM ticket a " \ "LEFT JOIN ticket_change b ON a.id = b.ticket " \ "WHERE (b.field='comment' AND %s ) OR %s" % \ (query_to_sql(db, query, 'b.newvalue'), query_to_sql(db, query, 'summary||keywords||description||reporter||cc')) cursor = db.cursor() cursor.execute(sql) for summary, desc, author, keywords, tid, date in cursor: yield (self.env.href.ticket(tid), '#%d: %s' % (tid, util.escape(util.shorten_line(summary))), date, author, util.escape(shorten_result(desc, query.split())))
def get_search_results(self, req, query, filters): if not 'ticket' in filters: return db = self.env.get_db_cnx() sql, args = query_to_sql(db, query, 'b.newvalue') sql2, args2 = query_to_sql(db, query, 'summary||keywords||description||reporter||cc') cursor = db.cursor() cursor.execute("SELECT DISTINCT a.summary,a.description,a.reporter, " "a.keywords,a.id,a.time FROM ticket a " "LEFT JOIN ticket_change b ON a.id = b.ticket " "WHERE (b.field='comment' AND %s ) OR %s" % (sql, sql2), args + args2) for summary,desc,author,keywords,tid,date in cursor: yield (self.env.href.ticket(tid), '#%d: %s' % (tid, util.shorten_line(summary)), date, author, shorten_result(desc, query.split()))
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') show_files = int(self.config.get('timeline', 'changeset_show_files')) db = self.env.get_db_cnx() repos = self.env.get_repository() authzperm = SubversionAuthorizer(self.env, req.authname) rev = repos.youngest_rev while rev: if not authzperm.has_permission_for_changeset(rev): rev = repos.previous_rev(rev) continue chgset = repos.get_changeset(rev) if chgset.date < start: return if chgset.date < stop: message = chgset.message or '--' if format == 'rss': title = util.Markup('Changeset <em>[%s]</em>: %s', chgset.rev, util.shorten_line(message)) href = self.env.abs_href.changeset(chgset.rev) message = wiki_to_html(message, self.env, req, db, absurls=True) else: title = util.Markup('Changeset <em>[%s]</em> by %s', chgset.rev, chgset.author) href = self.env.href.changeset(chgset.rev) message = wiki_to_oneliner(message, self.env, db, shorten=True) if show_files: files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append('...') break files.append('<span class="%s">%s</span>' % (chg[2], util.escape(chg[0]))) message = '<span class="changes">' + ', '.join(files) +\ '</span>: ' + message yield 'changeset', href, title, chgset.date, chgset.author,\ util.Markup(message) rev = repos.previous_rev(rev)
def get_search_results(self, req, query, filters): if not 'wiki' in filters: return db = self.env.get_db_cnx() sql = "SELECT w1.name,w1.time,w1.author,w1.text " \ "FROM wiki w1," \ "(SELECT name,max(version) AS ver " \ "FROM wiki GROUP BY name) w2 " \ "WHERE w1.version = w2.ver AND w1.name = w2.name " \ "AND %s" % \ (query_to_sql(db, query, 'w1.name||w1.author||w1.text'),) cursor = db.cursor() cursor.execute(sql) for name, date, author, text in cursor: yield (self.env.href.wiki(name), '%s: %s' % (name, escape(shorten_line(text))), date, author, escape(shorten_result(text, query.split())))
def _format_sha_link(self, formatter, ns, sha, label, context=None): reponame = '' if context is None: context = formatter.context if formatter is None: formatter = context # hack 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=formatter.href.changeset(sha, reponame)) except Exception, e: errmsg = to_unicode(e)
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') show_files = int( self.config.get('timeline', 'changeset_show_files')) db = self.env.get_db_cnx() repos = self.env.get_repository() rev = repos.youngest_rev while rev: chgset = repos.get_changeset(rev) if chgset.date < start: return if chgset.date < stop: excerpt = util.shorten_line(chgset.message or '--') if format == 'rss': title = 'Changeset <em>[%s]</em>: %s' % (util.escape( chgset.rev), util.escape(excerpt)) href = self.env.abs_href.changeset(chgset.rev) message = wiki_to_html(chgset.message or '--', self.env, db, absurls=True) else: title = 'Changeset <em>[%s]</em> by %s' % (util.escape( chgset.rev), util.escape(chgset.author)) href = self.env.href.changeset(chgset.rev) message = wiki_to_oneliner(excerpt, self.env, db) if show_files: files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append('...') break files.append('<span class="%s">%s</span>' % (chg[2], util.escape(chg[0]))) message = '<span class="changes">' + ', '.join(files) +\ '</span>: ' + message yield 'changeset', href, title, chgset.date, chgset.author,\ message rev = repos.previous_rev(rev)
def render_macro(self, req, name, content): query_string = '' compact = 0 argv = content.split(',') if len(argv) > 0: query_string = argv[0] if len(argv) > 1: if argv[1].strip().lower() == 'compact': compact = 1 try: from cStringIO import StringIO except NameError: from StringIO import StringIO buf = StringIO() query = Query.from_string(self.env, query_string) query.order = 'id' tickets = query.execute() if tickets: if compact: links = [] for ticket in tickets: href = self.env.href.ticket(int(ticket['id'])) summary = escape(shorten_line(ticket['summary'])) links.append( '<a class="%s ticket" href="%s" ' 'title="%s">#%s</a>' % (ticket['status'], href, summary, ticket['id'])) buf.write(', '.join(links)) else: buf.write('<dl class="wiki compact">') for ticket in tickets: href = self.env.href.ticket(int(ticket['id'])) buf.write('<dt><a href="%s">#%s</a></dt>' % (href, ticket['id'])) buf.write('<dd>%s</dd>' % (escape(ticket['summary']))) buf.write('</dl>') return buf.getvalue()
def get_timeline_events(self, req, start, stop, filters): if 'wiki' in filters: format = req.args.get('format') db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute( "SELECT time,name,comment,author " "FROM wiki WHERE time>=%s AND time<=%s", (start, stop)) for t, name, comment, author in cursor: title = '<em>%s</em> edited by %s' % (escape(name), escape(author)) if format == 'rss': href = self.env.abs_href.wiki(name) comment = wiki_to_html(comment or '--', self.env, db, absurls=True) else: href = self.env.href.wiki(name) comment = wiki_to_oneliner(shorten_line(comment), self.env, db) yield 'wiki', href, title, t, author, comment
def _format_sha_link(self, formatter, ns, sha, label, context=None): reponame = "" if context is None: context = formatter.context if formatter is None: formatter = context # hack 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=formatter.href.changeset(sha, reponame), ) except Exception, e: errmsg = to_unicode(e)
def get_search_results(self, req, query, filters): if not "wiki" in filters: return db = self.env.get_db_cnx() sql_query, args = query_to_sql(db, query, "w1.name||w1.author||w1.text") cursor = db.cursor() cursor.execute( "SELECT w1.name,w1.time,w1.author,w1.text " "FROM wiki w1," "(SELECT name,max(version) AS ver " "FROM wiki GROUP BY name) w2 " "WHERE w1.version = w2.ver AND w1.name = w2.name " "AND " + sql_query, args, ) for name, date, author, text in cursor: yield ( self.env.href.wiki(name), "%s: %s" % (name, shorten_line(text)), date, author, shorten_result(text, query.split()), )
def get_timeline_events(self, req, start, stop, filters): if 'ticket' in filters: format = req.args.get('format') sql = [] # New tickets sql.append("SELECT time,id,'','new',type,summary,reporter,summary" " FROM ticket WHERE time>=%s AND time<=%s") # Reopened tickets sql.append("SELECT t1.time,t1.ticket,'','reopened',t.type," " t2.newvalue,t1.author,t.summary " " FROM ticket_change t1" " LEFT OUTER JOIN ticket_change t2 ON (t1.time=t2.time" " AND t1.ticket=t2.ticket AND t2.field='comment')" " LEFT JOIN ticket t on t.id = t1.ticket " " WHERE t1.field='status' AND t1.newvalue='reopened'" " AND t1.time>=%s AND t1.time<=%s") # Closed tickets sql.append("SELECT t1.time,t1.ticket,t2.newvalue,'closed',t.type," " t3.newvalue,t1.author,t.summary" " FROM ticket_change t1" " INNER JOIN ticket_change t2 ON t1.ticket=t2.ticket" " AND t1.time=t2.time" " LEFT OUTER JOIN ticket_change t3 ON t1.time=t3.time" " AND t1.ticket=t3.ticket AND t3.field='comment'" " LEFT JOIN ticket t on t.id = t1.ticket " " WHERE t1.field='status' AND t1.newvalue='closed'" " AND t2.field='resolution'" " AND t1.time>=%s AND t1.time<=%s") db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute(" UNION ALL ".join(sql), (start, stop, start, stop, start, stop)) kinds = {'new': 'newticket', 'reopened': 'newticket', 'closed': 'closedticket'} verbs = {'new': 'created', 'reopened': 'reopened', 'closed': 'closed'} for t, id, resolution, status, type, message, author, summary \ in cursor: title = 'Ticket <em title="%s">#%s</em> (%s) %s by %s' % ( util.escape(summary), id, type, verbs[status], util.escape(author)) if format == 'rss': href = self.env.abs_href.ticket(id) if status != 'new': message = wiki_to_html(message or '--', self.env, req, db) else: message = util.escape(message) else: href = self.env.href.ticket(id) if status != 'new': message = ': '.join(filter(None, [ resolution, wiki_to_oneliner(message, self.env, db, shorten=True) ])) else: message = util.escape(util.shorten_line(message)) yield kinds[status], href, title, t, author, message
def _render_overview(self, req): data = {'title': 'Build Status'} show_all = False if req.args.get('show') == 'all': show_all = True data['show_all'] = show_all repos = self.env.get_repository(req.authname) if hasattr(repos, 'sync'): repos.sync() configs = [] for config in BuildConfig.select(self.env, include_inactive=show_all): if not repos.authz.has_permission(config.path): continue description = config.description if description: description = wiki_to_html(description, self.env, req) platforms_data = [] for platform in TargetPlatform.select(self.env, config=config.name): pd = { 'name': platform.name, 'id': platform.id, 'builds_pending': len(list(Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len(list(Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } platforms_data.append(pd) config_data = { 'name': config.name, 'label': config.label or config.name, 'active': config.active, 'path': config.path, 'description': description, 'builds_pending' : len(list(Build.select(self.env, config=config.name, status=Build.PENDING))), 'builds_inprogress' : len(list(Build.select(self.env, config=config.name, status=Build.IN_PROGRESS))), 'href': req.href.build(config.name), 'builds': [], 'platforms': platforms_data } configs.append(config_data) if not config.active: continue prev_rev = None for platform, rev, build in collect_changes(repos, config): if rev != prev_rev: if prev_rev is None: chgset = repos.get_changeset(rev) config_data['youngest_rev'] = { 'id': rev, 'href': req.href.changeset(rev), 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner( shorten_line(chgset.message), self.env, req=req) } else: break prev_rev = rev if build: build_data = _get_build_data(self.env, req, build) build_data['platform'] = platform.name config_data['builds'].append(build_data) else: config_data['builds'].append({ 'platform': platform.name, 'status': 'pending' }) data['configs'] = configs data['page_mode'] = 'overview' in_progress_builds = Build.select(self.env, status=Build.IN_PROGRESS) pending_builds = Build.select(self.env, status=Build.PENDING) data['builds_pending'] = len(list(pending_builds)) data['builds_inprogress'] = len(list(in_progress_builds)) add_link(req, 'views', req.href.build(view='inprogress'), 'In Progress Builds') add_ctxtnav(req, 'In Progress Builds', req.href.build(view='inprogress')) return data
def _render_overview(self, req): data = {'title': 'Build Status'} show_all = False if req.args.get('show') == 'all': show_all = True data['show_all'] = show_all repos = self.env.get_repository(authname=req.authname) assert repos, 'No "(default)" Repository: Add a repository or alias ' \ 'named "(default)" to Trac.' configs = [] for config in BuildConfig.select(self.env, include_inactive=show_all): rev = config.max_rev or repos.youngest_rev try: if not _has_permission(req.perm, repos, config.path, rev=rev): continue except NoSuchNode: add_warning(req, "Configuration '%s' points to non-existing " "path '/%s' at revision '%s'. Configuration skipped." \ % (config.name, config.path, rev)) continue description = config.description if description: description = wiki_to_html(description, self.env, req) platforms_data = [] for platform in TargetPlatform.select(self.env, config=config.name): pd = { 'name': platform.name, 'id': platform.id, 'builds_pending': len(list(Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len(list(Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } platforms_data.append(pd) config_data = { 'name': config.name, 'label': config.label or config.name, 'active': config.active, 'path': config.path, 'description': description, 'builds_pending' : len(list(Build.select(self.env, config=config.name, status=Build.PENDING))), 'builds_inprogress' : len(list(Build.select(self.env, config=config.name, status=Build.IN_PROGRESS))), 'href': req.href.build(config.name), 'builds': [], 'platforms': platforms_data } configs.append(config_data) if not config.active: continue prev_rev = None for platform, rev, build in collect_changes(repos, config): if rev != prev_rev: if prev_rev is None: chgset = repos.get_changeset(rev) config_data['youngest_rev'] = { 'id': rev, 'href': req.href.changeset(rev), 'display_rev': repos.normalize_rev(rev), 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner( shorten_line(chgset.message), self.env, req=req) } else: break prev_rev = rev if build: build_data = _get_build_data(self.env, req, build) build_data['platform'] = platform.name config_data['builds'].append(build_data) else: config_data['builds'].append({ 'platform': platform.name, 'status': 'pending' }) data['configs'] = sorted(configs, key=lambda x:x['label'].lower()) data['page_mode'] = 'overview' in_progress_builds = Build.select(self.env, status=Build.IN_PROGRESS) pending_builds = Build.select(self.env, status=Build.PENDING) data['builds_pending'] = len(list(pending_builds)) data['builds_inprogress'] = len(list(in_progress_builds)) add_link(req, 'views', req.href.build(view='inprogress'), 'In Progress Builds') add_ctxtnav(req, 'In Progress Builds', req.href.build(view='inprogress')) return data
testrepo.get_changeset(testrepo.normalize_rev(sha)) reponame = testrepo.reponame except Exception, e: self.log.debug("%s not found in repo: %s" % (sha, r)) 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") def get_wiki_syntax(self): yield (r'(?:\b|!)r?[0-9a-fA-F]{%d,40}\b' % self._wiki_shortrev_len, lambda fmt, sha, match: self._format_sha_link(fmt, sha.startswith('r') and sha[1:] or sha, sha)) def get_link_resolvers(self): yield 'sha', lambda fmt, _, sha, label, match=None: self._format_sha_link(fmt, sha, label) ####################### # IRepositoryConnector
def get_timeline_events(self, req, start, stop, filters): if 'ticket' in filters: format = req.args.get('format') sql = [] # New tickets sql.append("SELECT time,id,'','new',type,summary,reporter,summary" " FROM ticket WHERE time>=%s AND time<=%s") # Reopened tickets sql.append("SELECT t1.time,t1.ticket,'','reopened',t.type," " t2.newvalue,t1.author,t.summary " " FROM ticket_change t1" " LEFT OUTER JOIN ticket_change t2 ON (t1.time=t2.time" " AND t1.ticket=t2.ticket AND t2.field='comment')" " LEFT JOIN ticket t on t.id = t1.ticket " " WHERE t1.field='status' AND t1.newvalue='reopened'" " AND t1.time>=%s AND t1.time<=%s") # Closed tickets sql.append("SELECT t1.time,t1.ticket,t2.newvalue,'closed',t.type," " t3.newvalue,t1.author,t.summary" " FROM ticket_change t1" " INNER JOIN ticket_change t2 ON t1.ticket=t2.ticket" " AND t1.time=t2.time" " LEFT OUTER JOIN ticket_change t3 ON t1.time=t3.time" " AND t1.ticket=t3.ticket AND t3.field='comment'" " LEFT JOIN ticket t on t.id = t1.ticket " " WHERE t1.field='status' AND t1.newvalue='closed'" " AND t2.field='resolution'" " AND t1.time>=%s AND t1.time<=%s") db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute(" UNION ALL ".join(sql), (start, stop, start, stop, start, stop)) kinds = {'new': 'newticket', 'reopened': 'newticket', 'closed': 'closedticket'} verbs = {'new': 'created', 'reopened': 'reopened', 'closed': 'closed'} for t, id, resolution, status, type, message, author, summary \ in cursor: title = util.Markup('Ticket <em title="%s">#%s</em> (%s) %s by ' '%s', summary, id, type, verbs[status], author) if format == 'rss': href = self.env.abs_href.ticket(id) if status != 'new': message = wiki_to_html(message or '--', self.env, req, db) else: message = util.escape(message) else: href = self.env.href.ticket(id) if status != 'new': message = util.Markup(': ').join(filter(None, [ resolution, wiki_to_oneliner(message, self.env, db, shorten=True) ])) else: message = util.escape(util.shorten_line(message)) yield kinds[status], href, title, t, author, message
def _render_overview(self, req): data = {'title': 'Build Status'} show_all = False if req.args.get('show') == 'all': show_all = True data['show_all'] = show_all repos = self.env.get_repository(authname=req.authname) assert repos, 'No "(default)" Repository: Add a repository or alias ' \ 'named "(default)" to Trac.' configs = [] for config in BuildConfig.select(self.env, include_inactive=show_all): rev = config.max_rev or repos.youngest_rev try: if not _has_permission(req.perm, repos, config.path, rev=rev): continue except NoSuchNode: add_warning(req, "Configuration '%s' points to non-existing " "path '/%s' at revision '%s'. Configuration skipped." \ % (config.name, config.path, rev)) continue description = config.description if description: description = wiki_to_html(description, self.env, req) platforms_data = [] for platform in TargetPlatform.select(self.env, config=config.name): pd = { 'name': platform.name, 'id': platform.id, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } platforms_data.append(pd) config_data = { 'name': config.name, 'label': config.label or config.name, 'active': config.active, 'path': config.path, 'description': description, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS))), 'href': req.href.build(config.name), 'builds': [], 'platforms': platforms_data } configs.append(config_data) if not config.active: continue prev_rev = None for platform, rev, build in collect_changes(repos, config): if rev != prev_rev: if prev_rev is None: chgset = repos.get_changeset(rev) config_data['youngest_rev'] = { 'id': rev, 'href': req.href.changeset(rev), 'display_rev': repos.normalize_rev(rev), 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner(shorten_line(chgset.message), self.env, req=req) } else: break prev_rev = rev if build: build_data = _get_build_data(self.env, req, build) build_data['platform'] = platform.name config_data['builds'].append(build_data) else: config_data['builds'].append({ 'platform': platform.name, 'status': 'pending' }) data['configs'] = sorted(configs, key=lambda x: x['label'].lower()) data['page_mode'] = 'overview' in_progress_builds = Build.select(self.env, status=Build.IN_PROGRESS) pending_builds = Build.select(self.env, status=Build.PENDING) data['builds_pending'] = len(list(pending_builds)) data['builds_inprogress'] = len(list(in_progress_builds)) add_link(req, 'views', req.href.build(view='inprogress'), 'In Progress Builds') add_ctxtnav(req, 'In Progress Builds', req.href.build(view='inprogress')) return data
def _render_overview(self, req): data = {'title': 'Build Status'} show_all = False if req.args.get('show') == 'all': show_all = True data['show_all'] = show_all repos = self.env.get_repository(req.authname) configs = [] for config in BuildConfig.select(self.env, include_inactive=show_all): if not repos.authz.has_permission(config.branch): continue description = config.description if description: description = wiki_to_html(description, self.env, req) platforms_data = [] for platform in TargetPlatform.select(self.env, config=config.name): pd = { 'name': platform.name, 'id': platform.id, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } platforms_data.append(pd) config_data = { 'name': config.name, 'label': config.label or config.name, 'active': config.active, 'branch': config.branch, 'description': description, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS))), 'href': req.href.build(config.name), 'builds': [], 'platforms': platforms_data } configs.append(config_data) if not config.active: continue prev_rev = None for platform, rev, build in collect_changes(repos, config): if rev != prev_rev: if prev_rev is None: chgset = repos.get_changeset(rev) config_data['youngest_rev'] = { 'id': rev, 'href': req.href.changeset(rev), 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner(shorten_line(chgset.message), self.env, req=req) } else: break prev_rev = rev if build: build_data = _get_build_data(self.env, req, build) build_data['platform'] = platform.name config_data['builds'].append(build_data) else: config_data['builds'].append({ 'platform': platform.name, 'status': 'pending' }) data['configs'] = configs data['page_mode'] = 'overview' in_progress_builds = Build.select(self.env, status=Build.IN_PROGRESS) pending_builds = Build.select(self.env, status=Build.PENDING) data['builds_pending'] = len(list(pending_builds)) data['builds_inprogress'] = len(list(in_progress_builds)) add_link(req, 'views', req.href.build(view='inprogress'), 'In Progress Builds') add_ctxtnav(req, 'In Progress Builds', req.href.build(view='inprogress')) return data