Тикеты по всем проектам в Trac`e
Categories: Python, Trac on Sep.11, 2008
Выкладываю свой Macros для трака. Это переписанный макрос, который отображал тикеты по выбранному проекту в виде календаря.
На данный момент этот макрос выводит в список все активные тикеты по всем проектам, зашедшего в систему человека, и сортирует их по важности. В этом макросе есть возможность отследить время закрытия/создание/изменение тикетов по дате и по определенному человеку.
Код макроса:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | # Author: Vladimir Boichentsov import time import calendar import sys import string import Cookie import os import fileinput import sqlite3 as sqlite import operator from StringIO import StringIO from trac.wiki.api import WikiSystem from trac.util import * def execute(hdf, txt, env): # building the output buff = StringIO() # you type ticket if(hdf.getValue('args.close', 'no') == "yes"): plist = ['none'] else: plist = ['blocker','critical','high','major','medium','minor','trivial','low'] tickets = [] # directory by trac projects DIR = '/home/pub/trac' o = j = c = 0 users = '' #passwords for users trac projects for line in fileinput.input('/home/pub/svn/.htpasswd'): temp = line.split(':') if(temp[0] != 'admin'): users += '<a href="?user=' + temp[0] + '">' + temp[0] + '</a> ' user = hdf.getValue('args.user', '') if(len(user) < 1): owner = hdf.getValue("trac.authname", "anonymous") else: owner = user buff.write('<a href="?user=' + owner + '&close=yes&time=yes">close(create time)</a> <a href="?user=' + owner + '&close=yes">close(time close)</a> | ' + users + "\n" ) buff.write('<table class="listing tickets"><tbody>\n') buff.write('<thead><tr> <td class="ticket"> Ticket </a></td><td class="summary">Summary</td> <td> Project</td> <td class="owner">Owner</td> <td>Priority</td> <td>Type</td> <td class="date"> Create </td> <td class="date"> Changetime </td> </tr> </thead>\n') for p in plist: for project in os.listdir(DIR): con = sqlite.connect(DIR + '/' + project +'/db/trac.db') cur = con.cursor() if(p != 'none'): t = "and t.priority='" + p + "'" else: t = '' cur.execute("SELECT t.changetime,t.id,t.summary,t.owner,t.status,t.description,t.time,t.priority,t.type FROM ticket t, ticket_custom tc where tc.ticket=t.id and t.owner='" + owner +"' " + t) if(hdf.getValue('args.close', 'no') != "yes"): while (1): row = cur.fetchone() if row == None: break else: j = j + 1 if(row[4] != 'closed'): o = o + 1 else: c = c + 1 if(row[4] != 'closed'): buff.write(show_ticket(row,project,env)) else: while(1): row = cur.fetchone() ticket = [] if row == None: break for t in row: ticket.append(t) ticket.append(project) tickets.append(ticket) if(hdf.getValue('args.close', 'no') == "yes"): if(hdf.getValue('args.time', 'no') == "yes"): tickets.sort(reverse=True,key=operator.itemgetter(6)) else: tickets.sort(reverse=True) for row in tickets: buff.write(show_ticket(row,row[9],env)) j = j + 1 if(row[4] != 'closed'): o = o + 1 else: c = c + 1 buff.write('</tbody></table>\n') buff.write('<br>Ticket all: %(j)i Ticket open: %(o)i Closed ticket: %(c)i \n' % { 'j':j, 'o':o, 'c':c, }) table = buff.getvalue() buff.close() return table def ticket_priority(row): priority = '' if (row[7] == 'minor'): priority = "background: #e7ffff; border-color: #cee; color: #099;" if (row[7] == 'major' or row[7] == 'medium'): priority = "background: #fbfbfb; border-color: #ddd; color: #444;" if (row[7] == 'trivial' or row[7] == 'low'): priority = "background: #e7eeff; border-color: #cde; color: #469;" if (row[7] == 'critical' or row[7] == 'high'): priority = "background: #ffb; border-color: #eea; color: #880;" if (row[7] == 'blocker'): priority = "background: #fdc; border-color: #e88; color: #a22;" if(row[4] == 'closed'): priority = "color: #777; background: #ddd; border-color: #ccc;" return priority def show_ticket(row,project,env): ticket = row[2] line = '<tr style="%(priority)s"> <td class="ticket"> <a href="/trac/%(project)s/ticket/%(id)i"> #%(id)i </a></td><td class="summary"><a href="/trac/%(project)s/ticket/%(id)i" title="%(description)s"> %(ticket)s </a></td><td>%(project)s</td> <td class="owner">%(owner)s</td> <td>%(prio)s</td> <td>%(type)s</td> <td class="date"> %(time)s </td> <td class="date"> %(changetime)s </td> </tr>\n' % { 'id' : row[1], 'url': env.href.ticket(row[1]), 'project' : project, 'priority' : ticket_priority(row), 'prio' : row[7], 'type' : row[8], 'ticket': ticket[0:100], 'owner': row[3], 'time' : time.strftime('%d/%m/%y',time.localtime(row[6])), 'changetime' : time.strftime('%d/%m/%y',time.localtime(row[0])), 'style': row[4] == 'closed' and 'font-size: 9px; color: #777777; text-decoration: line-through;' or 'font-size: 9px; color: #000000', 'description': " ", #replace(description, "\'", "'") == None and " " or replace(description, "\'", "'"), } return line |
Similar posts:

September 17th, 2008 on 11:29 am
Супер вещь! Прям пользуюсь и радуюсь и всем советую!
September 18th, 2008 on 12:15 am
Рад, что кому-то пригодилось!
Не забываем рейтинг ставить :)
December 22nd, 2008 on 10:33 am
Я новичок в траке. Подскажите пожалуйста как прикрутит этот макрос к траку малой кровью.
December 22nd, 2008 on 11:51 pm
Там же написанно :)
DIR – этой переменной указываем директорию, где у вас находятся проекты
в 37 строке пишется путь к файлу в котором находятся пароли и логины пользователей записанные через “:” !
Кидаем этот макрос в папку с макросами, перезапускаем трак, редактируем вики, пишем [[WikiTickets()]]
И если я ничего не забыл, то должно заработать!