rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
self.systeminfo = [('Python': sys.version)]
self.systeminfo = [('Python', sys.version)]
def __init__(self, default_data=False, enable=None): ComponentManager.__init__(self) Component.__init__(self) self.enabled_components = enable self.db = InMemoryDatabase() self.systeminfo = [('Python': sys.version)]
item['message'] = item['message']
item['message'] = wiki_to_oneliner(item['message'])
def get_info (self, start, stop, tickets, changeset, wiki): cnx = db.get_connection() cursor = cnx.cursor ()
if remove_contraints.has_key(field):
if remove_constraints.has_key(field):
def _get_constraints(self, req): constraints = {} ticket_fields = [f['name'] for f in TicketSystem(self.env).get_ticket_fields()]
self.ticket['description'] = wrap(self.ticket.get('description',''),
self.ticket['description'] = wrap(self.ticket.values.get('description', ''),
def notify(self, ticket, newticket=1, modtime=0): self.ticket = ticket self.modtime = modtime self.newticket = newticket self.ticket['description'] = wrap(self.ticket.get('description',''), self.COLS, initial_indent=' ', subsequent_indent=' ', linesep=CRLF) self.ticket['link'] = self.env.abs_href.ticket(ticket['id']) self.hdf['email.ticket_props'] = self.format_props() self.hdf['email.ticket_body_hdr'] = self.format_hdr() self.hdf['ticket'] = self.ticket self.hdf['ticket.new'] = self.newticket and '1' or '0' subject = self.format_subj() if not self.newticket: subject = 'Re: ' + subject self.hdf['email.subject'] = subject changes = '' if not self.newticket and modtime: # Ticket change changelog = ticket.get_changelog(self.db, modtime) for date, author, field, old, new in changelog: self.hdf['ticket.change.author'] = author pfx = 'ticket.change.%s' % field newv = '' if field == 'comment': newv = wrap(new, self.COLS, ' ', ' ', CRLF) elif field == 'description': new_descr = wrap(new, self.COLS, ' ', ' ', CRLF) old_descr = wrap(old, self.COLS, '> ', '> ', CRLF) old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF) cdescr = CRLF cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF cdescr += 'New description:' + 2*CRLF + new_descr + CRLF self.hdf['email.changes_descr'] = cdescr else: newv = new l = 7 + len(field) chg = wrap('%s => %s' % (old, new), self.COLS-l,'', l*' ', CRLF) changes += ' * %s: %s%s' % (field, chg, CRLF) if newv: self.hdf['%s.oldvalue' % pfx] = old self.hdf['%s.newvalue' % pfx] = newv if field == 'cc': self.prev_cc += old and self.parse_cc(old) or [] self.hdf['%s.author' % pfx] = author if changes: self.hdf['email.changes_body'] = changes NotifyEmail.notify(self, ticket['id'], subject)
self.ticket['link'] = self.env.abs_href.ticket(ticket['id'])
self.ticket['link'] = self.env.abs_href.ticket(ticket.id)
def notify(self, ticket, newticket=1, modtime=0): self.ticket = ticket self.modtime = modtime self.newticket = newticket self.ticket['description'] = wrap(self.ticket.get('description',''), self.COLS, initial_indent=' ', subsequent_indent=' ', linesep=CRLF) self.ticket['link'] = self.env.abs_href.ticket(ticket['id']) self.hdf['email.ticket_props'] = self.format_props() self.hdf['email.ticket_body_hdr'] = self.format_hdr() self.hdf['ticket'] = self.ticket self.hdf['ticket.new'] = self.newticket and '1' or '0' subject = self.format_subj() if not self.newticket: subject = 'Re: ' + subject self.hdf['email.subject'] = subject changes = '' if not self.newticket and modtime: # Ticket change changelog = ticket.get_changelog(self.db, modtime) for date, author, field, old, new in changelog: self.hdf['ticket.change.author'] = author pfx = 'ticket.change.%s' % field newv = '' if field == 'comment': newv = wrap(new, self.COLS, ' ', ' ', CRLF) elif field == 'description': new_descr = wrap(new, self.COLS, ' ', ' ', CRLF) old_descr = wrap(old, self.COLS, '> ', '> ', CRLF) old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF) cdescr = CRLF cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF cdescr += 'New description:' + 2*CRLF + new_descr + CRLF self.hdf['email.changes_descr'] = cdescr else: newv = new l = 7 + len(field) chg = wrap('%s => %s' % (old, new), self.COLS-l,'', l*' ', CRLF) changes += ' * %s: %s%s' % (field, chg, CRLF) if newv: self.hdf['%s.oldvalue' % pfx] = old self.hdf['%s.newvalue' % pfx] = newv if field == 'cc': self.prev_cc += old and self.parse_cc(old) or [] self.hdf['%s.author' % pfx] = author if changes: self.hdf['email.changes_body'] = changes NotifyEmail.notify(self, ticket['id'], subject)
changelog = ticket.get_changelog(self.db, modtime)
changelog = ticket.get_changelog(modtime)
def notify(self, ticket, newticket=1, modtime=0): self.ticket = ticket self.modtime = modtime self.newticket = newticket self.ticket['description'] = wrap(self.ticket.get('description',''), self.COLS, initial_indent=' ', subsequent_indent=' ', linesep=CRLF) self.ticket['link'] = self.env.abs_href.ticket(ticket['id']) self.hdf['email.ticket_props'] = self.format_props() self.hdf['email.ticket_body_hdr'] = self.format_hdr() self.hdf['ticket'] = self.ticket self.hdf['ticket.new'] = self.newticket and '1' or '0' subject = self.format_subj() if not self.newticket: subject = 'Re: ' + subject self.hdf['email.subject'] = subject changes = '' if not self.newticket and modtime: # Ticket change changelog = ticket.get_changelog(self.db, modtime) for date, author, field, old, new in changelog: self.hdf['ticket.change.author'] = author pfx = 'ticket.change.%s' % field newv = '' if field == 'comment': newv = wrap(new, self.COLS, ' ', ' ', CRLF) elif field == 'description': new_descr = wrap(new, self.COLS, ' ', ' ', CRLF) old_descr = wrap(old, self.COLS, '> ', '> ', CRLF) old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF) cdescr = CRLF cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF cdescr += 'New description:' + 2*CRLF + new_descr + CRLF self.hdf['email.changes_descr'] = cdescr else: newv = new l = 7 + len(field) chg = wrap('%s => %s' % (old, new), self.COLS-l,'', l*' ', CRLF) changes += ' * %s: %s%s' % (field, chg, CRLF) if newv: self.hdf['%s.oldvalue' % pfx] = old self.hdf['%s.newvalue' % pfx] = newv if field == 'cc': self.prev_cc += old and self.parse_cc(old) or [] self.hdf['%s.author' % pfx] = author if changes: self.hdf['email.changes_body'] = changes NotifyEmail.notify(self, ticket['id'], subject)
NotifyEmail.notify(self, ticket['id'], subject)
NotifyEmail.notify(self, ticket.id, subject)
def notify(self, ticket, newticket=1, modtime=0): self.ticket = ticket self.modtime = modtime self.newticket = newticket self.ticket['description'] = wrap(self.ticket.get('description',''), self.COLS, initial_indent=' ', subsequent_indent=' ', linesep=CRLF) self.ticket['link'] = self.env.abs_href.ticket(ticket['id']) self.hdf['email.ticket_props'] = self.format_props() self.hdf['email.ticket_body_hdr'] = self.format_hdr() self.hdf['ticket'] = self.ticket self.hdf['ticket.new'] = self.newticket and '1' or '0' subject = self.format_subj() if not self.newticket: subject = 'Re: ' + subject self.hdf['email.subject'] = subject changes = '' if not self.newticket and modtime: # Ticket change changelog = ticket.get_changelog(self.db, modtime) for date, author, field, old, new in changelog: self.hdf['ticket.change.author'] = author pfx = 'ticket.change.%s' % field newv = '' if field == 'comment': newv = wrap(new, self.COLS, ' ', ' ', CRLF) elif field == 'description': new_descr = wrap(new, self.COLS, ' ', ' ', CRLF) old_descr = wrap(old, self.COLS, '> ', '> ', CRLF) old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF) cdescr = CRLF cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF cdescr += 'New description:' + 2*CRLF + new_descr + CRLF self.hdf['email.changes_descr'] = cdescr else: newv = new l = 7 + len(field) chg = wrap('%s => %s' % (old, new), self.COLS-l,'', l*' ', CRLF) changes += ' * %s: %s%s' % (field, chg, CRLF) if newv: self.hdf['%s.oldvalue' % pfx] = old self.hdf['%s.newvalue' % pfx] = newv if field == 'cc': self.prev_cc += old and self.parse_cc(old) or [] self.hdf['%s.author' % pfx] = author if changes: self.hdf['email.changes_body'] = changes NotifyEmail.notify(self, ticket['id'], subject)
tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1
fields = [f for f in tkt.fields if f['type'] != 'textarea'] t = self.modtime or tkt.time_changed
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
for f in fields: if not tkt.has_key(f):
for i, f in enum([f['name'] for f in fields]): if not f in tkt.values.keys():
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
fval = str(tkt[f])
fval = tkt[f]
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3]))
idx = 2 * (i % 2) if len(f) > width[idx]: width[idx] = len(f) if len(fval) > width[idx + 1]: width[idx + 1] = len(fval) format = ('%%%is: %%-%is | ' % (width[2], width[3]), ' %%%is: %%-%is%s' % (width[0], width[1], CRLF))
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
big=[] for f in fields: if not tkt.has_key(f): continue
big = [] for i, f in enum([f['name'] for f in fields]): if not tkt.values.has_key(f): continue
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
fname = f.startswith('custom_') and f[7:] or f
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
big.append((fname.capitalize(), fval))
big.append((f.capitalize(), fval))
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0:
txt += format[i % 2] % (f.capitalize(), fval) if i % 2:
def format_props(self): tkt = self.ticket tkt['id'] = '%s' % tkt['id'] t = self.modtime or tkt['time'] tkt['modified'] = time.strftime('%c', time.localtime(t)) fields = ['id', 'status', 'component', 'modified', 'severity', 'milestone', 'priority', 'version', 'owner', 'reporter'] fields.extend(filter(lambda f: f.startswith('custom_'), self.ticket.keys())) i = 1 width = [0,0,0,0] for f in fields: if not tkt.has_key(f): continue fval = str(tkt[f]) if fval.find('\n') > -1: continue fname = f.startswith('custom_') and f[7:] or f idx = 2*(i % 2) if len(fname) > width[idx]: width[idx] = len(fname) if len(fval) > width[idx+1]: width[idx+1] = len(fval) i += 1 format = (' %%%is: %%-%is%s' % (width[0], width[1], CRLF), '%%%is: %%-%is | ' % (width[2], width[3])) i = 1 l = (width[2] + width[3] + 5) sep = l*'-' + '+' + (self.COLS-l)*'-' txt = sep + CRLF big=[] for f in fields: if not tkt.has_key(f): continue fval = tkt[f] fname = f.startswith('custom_') and f[7:] or f if '\n' in str(fval): big.append((fname.capitalize(), fval)) else: txt += format[i%2] % (fname.capitalize(), fval) i += 1 if i % 2 == 0: txt += '\n' if big: txt += sep for k,v in big: txt += '\n%s:\n%s\n\n' % (k,v) txt += sep return txt
int(self.ticket['id']), modtime, rcpt)
int(self.ticket.id), modtime, rcpt)
def get_message_id(self, rcpt, modtime=0): """Generate a predictable, but sufficiently unique message ID.""" s = '%s.%08d.%d.%s' % (self.config.get('project', 'url'), int(self.ticket['id']), modtime, rcpt) dig = md5.new(s).hexdigest() host = self.from_email[self.from_email.find('@') + 1:] msgid = '<%03d.%s@%s>' % (len(s), dig, host) return msgid
print `info`
def _render_diff(self, req, db, page): req.perm.assert_permission('WIKI_VIEW')
num_changes += 1
def _render_diff(self, req, db, page): req.perm.assert_permission('WIKI_VIEW')
match = re.match(r'/(browser|file)(?:(/.*))?', req.path_info)
match = re.match(r'/(export|browser|file)(?:(/.*))?', req.path_info)
def match_request(self, req): import re match = re.match(r'/(browser|file)(?:(/.*))?', req.path_info) if match: req.args['path'] = match.group(2) or '/' if match.group(1) == 'file': req.redirect(req.href.browser(req.args.get('path'), rev=req.args.get('rev'), format=req.args.get('format')), permanent=True) return True
req.args['path'] = match.group(2) or '/' if match.group(1) == 'file': req.redirect(req.href.browser(req.args.get('path'), rev=req.args.get('rev'),
mode, path = match.groups() if mode == 'export': if path and '/' in path: _, rev, path = path.split('/', 2) req.args['rev'] = rev req.args['format'] = 'raw' elif mode == 'file': req.redirect(req.href.browser(path, rev=req.args.get('rev'),
def match_request(self, req): import re match = re.match(r'/(browser|file)(?:(/.*))?', req.path_info) if match: req.args['path'] = match.group(2) or '/' if match.group(1) == 'file': req.redirect(req.href.browser(req.args.get('path'), rev=req.args.get('rev'), format=req.args.get('format')), permanent=True) return True
raw_href = req.href.browser(node.path, rev=rev, format='raw')
raw_href = req.href.export(rev or repos.youngest_rev, node.path)
def _render_file(self, req, repos, node, rev=None): req.perm.require('FILE_VIEW')
return [('repos', self._format_link), ('source', self._format_link), ('browser', self._format_link)] def _format_link(self, formatter, ns, path, label):
return [('repos', self._format_browser_link), ('export', self._format_export_link), ('source', self._format_browser_link), ('browser', self._format_browser_link)] def _format_export_link(self, formatter, ns, export, label): if ':' in export: rev, path = export.split(':', 1) else: rev, path = self.env.get_repository().youngest_rev, export return html.A(label, class_='source', href=formatter.href.export(rev, path)) def _format_browser_link(self, formatter, ns, path, label):
def get_link_resolvers(self): """TracBrowser link resolvers. - `source:` and `browser:` * simple paths (/dir/file) * paths at a given revision (/dir/file@234) * paths with line number marks (/dir/file@234:10,20-30) * paths with line number anchor (/dir/file@234#L100) Marks and anchor can be combined. The revision must be present when specifying line numbers. In the few cases where it would be redundant (e.g. for tags), the revision number itself can be omitted: /tags/v10/file@100-110#L99 """ return [('repos', self._format_link), ('source', self._format_link), ('browser', self._format_link)]
milestone = urllib.quote_plus(milestone) href = href_join(self.base, 'milestone', str(milestone))
if milestone.find('/') >= 0: href = href_join(self.base, 'milestone') params.append(('id', milestone)) else: href = href_join(self.base, 'milestone', urllib.quote_plus(milestone))
def milestone(self, milestone, action=None): if milestone: milestone = urllib.quote_plus(milestone) href = href_join(self.base, 'milestone', str(milestone)) else: href = href_join(self.base, 'milestone') if action: href = href + '?action=' + action return href
href = href + '?action=' + action
params.append(('action', action)) if params: href += '?' + urllib.urlencode(params)
def milestone(self, milestone, action=None): if milestone: milestone = urllib.quote_plus(milestone) href = href_join(self.base, 'milestone', str(milestone)) else: href = href_join(self.base, 'milestone') if action: href = href + '?action=' + action return href
elif name in ['changetime', 'time']: val = int(val)
elif name in ('changetime', 'time'): val = datetime.fromtimestamp(int(val), utc)
def execute(self, req, db=None): if not self.cols: self.get_columns()
time_col = name == 'milestone' and 'milestone.due' or 'version.time'
time_col = name == 'milestone' and 'milestone.due' or \ 'version.time'
def get_constraint_sql(name, value, mode, neg): if name not in custom_fields: name = 't.' + name else: name = name + '.value' value = value[len(mode) + neg:]
if int(ticket['time']) > orig_time:
if ticket['time'] > orig_time:
def template_data(self, req, db, tickets, orig_list=None, orig_time=None): constraints = {} for k, v in self.constraints.items(): constraint = {'values': [], 'mode': ''} for val in v: neg = val.startswith('!') if neg: val = val[1:] mode = '' if val[:1] in ('~', '^', '$'): mode, val = val[:1], val[1:] constraint['mode'] = (neg and '!' or '') + mode constraint['values'].append(val) constraints[k] = constraint
elif int(ticket['changetime']) > orig_time:
elif ticket['changetime'] > orig_time:
def template_data(self, req, db, tickets, orig_list=None, orig_time=None): constraints = {} for k, v in self.constraints.items(): constraint = {'values': [], 'mode': ''} for val in v: neg = val.startswith('!') if neg: val = val[1:] mode = '' if val[:1] in ('~', '^', '$'): mode, val = val[:1], val[1:] constraint['mode'] = (neg and '!' or '') + mode constraint['values'].append(val) constraints[k] = constraint
for field, value in ticket.items(): if field == self.group: groups.setdefault(value, []).append(ticket) if not groupsequence or groupsequence[-1] != value: groupsequence.append(value) if field == 'time': ticket[field] = value elif field == 'description': ticket[field] = \ wiki_to_html(value or '', self.env, req, db) else: ticket[field] = value
if self.group: group_key = ticket[self.group] groups.setdefault(group_key, []).append(ticket) if not groupsequence or groupsequence[-1] != group_key: groupsequence.append(group_key) description = ticket.get('description') if description: ticket['description'] = wiki_to_html(description, self.env, req, db)
def template_data(self, req, db, tickets, orig_list=None, orig_time=None): constraints = {} for k, v in self.constraints.items(): constraint = {'values': [], 'mode': ''} for val in v: neg = val.startswith('!') if neg: val = val[1:] mode = '' if val[:1] in ('~', '^', '$'): mode, val = val[:1], val[1:] constraint['mode'] = (neg and '!' or '') + mode constraint['values'].append(val) constraints[k] = constraint
orig_time = int(time.time())
orig_time = datetime.now(utc) query_time = int(req.session.get('query_time', 0)) query_time = datetime.fromtimestamp(query_time, utc)
def display_html(self, req, query): db = self.env.get_db_cnx() tickets = query.execute(req, db)
or int(req.session.get('query_time', 0)) < orig_time - 3600:
or query_time < orig_time - timedelta(hours=1):
def display_html(self, req, query): db = self.env.get_db_cnx() tickets = query.execute(req, db)
orig_time = int(req.session.get('query_time', 0))
orig_time = query_time
def display_html(self, req, query): db = self.env.get_db_cnx() tickets = query.execute(req, db)
req.session['query_time'] = orig_time
req.session['query_time'] = to_timestamp(orig_time)
def display_html(self, req, query): db = self.env.get_db_cnx() tickets = query.execute(req, db)
% (class_map.get(change, 'mod'), name))
% (class_map.get(change, 'mod'), path))
def _render_changeset(self, req, item): absurls = req.args.get('format') == 'rss' href = self.env.href if absurls: href = self.env.abs_href
conf_dir = os.path.join(self.prefix, 'share', 'trac', 'conf') templates_dir = os.path.join(self.prefix, 'share', 'trac', 'templates') htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') plugins_dir = os.path.join(self.prefix, 'share', 'trac', 'plugins')
path = self.prefix or self.home path = os.path.expanduser(path) conf_dir = os.path.join(path, 'share', 'trac', 'conf') templates_dir = os.path.join(path, 'share', 'trac', 'templates') htdocs_dir = os.path.join(path, 'share', 'trac', 'htdocs') wiki_dir = os.path.join(path, 'share', 'trac', 'wiki-default') macros_dir = os.path.join(path, 'share', 'trac', 'wiki-macros') plugins_dir = os.path.join(path, 'share', 'trac', 'plugins')
def siteconfig(self): conf_dir = os.path.join(self.prefix, 'share', 'trac', 'conf') templates_dir = os.path.join(self.prefix, 'share', 'trac', 'templates') htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') plugins_dir = os.path.join(self.prefix, 'share', 'trac', 'plugins') f = open(_p('trac/siteconfig.py'), 'w') f.write("""
if 'description' in req.args or 'reporter' in req.args:
if 'description' in req.args.keys() or 'reporter' in req.args.keys():
def save_changes(self, req, id): if self.perm.has_permission(perm.TICKET_CHGPROP): # TICKET_CHGPROP gives permission to edit the ticket if not req.args.get('summary'): raise util.TracError('Tickets must contain summary.')
added = [x for x in newcc if x not in oldcc] removed = [x for x in oldcc if x not in newcc]
added = [x for x in newcc if x and x not in oldcc] removed = [x for x in oldcc if x and x not in newcc]
def diff_cc(self, old, new): oldcc = NotifyEmail.addrsep_re.split(old) newcc = NotifyEmail.addrsep_re.split(new) added = [x for x in newcc if x not in oldcc] removed = [x for x in oldcc if x not in newcc] return (added, removed)
import SilverCity
def render(self, req, mimetype, content, filename=None, rev=None): import SilverCity try: mimetype = mimetype.split(';', 1)[0] typelang = self._types[mimetype] lang = typelang[0] module = getattr(SilverCity, lang) generator = getattr(module, lang + "HTMLGenerator") try: allprops = typelang[2] propset = SilverCity.PropertySet() for p in allprops.keys(): propset[p] = allprops[p] except IndexError: pass except (KeyError, AttributeError): err = "No SilverCity lexer found for mime-type '%s'." % mimetype raise Exception, err
attachments_dir = os.path.join(self.env.path, 'attachments')
attachments_dir = os.path.join(os.path.normpath(self.env.path), 'attachments')
def insert(self, filename, fileobj, size, t=None, db=None): if not db: db = self.env.get_db_cnx() handle_ta = True else: handle_ta = False
description="Trac - Wiki-based issue tracker and project environment",
description="Integrated scm, wiki, issue tracker and project environment", long_description=\ """ Trac is a minimalistic web-based software project management and bug/issue tracking system. It provides an interface to the Subversion revision control systems, an integrated wiki, flexible issue tracking and convenient report facilities. """,
def run (self): if not self.skip_build: self.run_command('build_scripts')
safe_name = milestone.name.replace('/', '%2F')
safe_name = None if milestone.exists: safe_name = milestone.name.replace('/', '%2F')
def milestone_to_hdf(env, db, req, milestone): safe_name = milestone.name.replace('/', '%2F') hdf = {'name': escape(milestone.name), 'href': escape(env.href.milestone(safe_name))} if milestone.description: hdf['description_source'] = escape(milestone.description) hdf['description'] = wiki_to_html(milestone.description, env, req, db) if milestone.due: hdf['due'] = milestone.due hdf['due_date'] = format_date(milestone.due) hdf['due_delta'] = pretty_timedelta(milestone.due) hdf['late'] = milestone.is_late if milestone.completed: hdf['completed'] = milestone.completed hdf['completed_date'] = format_datetime(milestone.completed) hdf['completed_delta'] = pretty_timedelta(milestone.completed) return hdf
milestone.name = req.args.get('name')
def _do_save(self, req, db, milestone): if milestone.exists: req.perm.assert_permission('MILESTONE_MODIFY') else: req.perm.assert_permission('MILESTONE_CREATE')
perm_map = {'ticket': perm.TICKET_ADMIN, 'wiki': perm.WIKI_DELETE}
perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE'}
def _do_save(self, req, attachment): perm_map = {'ticket': 'TICKET_APPEND', 'wiki': 'WIKI_MODIFY'} req.perm.assert_permission(perm_map[attachment.parent_type])
fromlines[i] = fr[:start] + '\0' + fr[start:end+len(fr)] + \ '\1' + fr[end:] tolines[i] = to[:start] + '\0' + to[start:end+len(to)] + \ '\1' + to[end:]
last = end+len(fr) fromlines[i] = fr[:start] + '\0' + fr[start:last] + \ '\1' + fr[last:] last = end+len(to) tolines[i] = to[:start] + '\0' + to[start:last] + \ '\1' + to[last:]
def _markup_intraline_change(fromlines, tolines): from trac.versioncontrol.diff import _get_change_extent for i in xrange(len(fromlines)): fr, to = fromlines[i], tolines[i] (start, end) = _get_change_extent(fr, to) if start != 0 or end != 0: fromlines[i] = fr[:start] + '\0' + fr[start:end+len(fr)] + \ '\1' + fr[end:] tolines[i] = to[:start] + '\0' + to[start:end+len(to)] + \ '\1' + to[end:]
for event_provider in self.event_providers:
for provider in self.event_providers:
def process_request(self, req): req.perm.assert_permission('TIMELINE_VIEW') data = {}
for event in event_provider.get_timeline_events(req, start, stop, filters):
for event in provider.get_timeline_events(req, start, stop, filters):
def process_request(self, req): req.perm.assert_permission('TIMELINE_VIEW') data = {}
self._provider_failure(e, req, event_provider, filters,
self._provider_failure(e, req, provider, filters,
def process_request(self, req): req.perm.assert_permission('TIMELINE_VIEW') data = {}
day = format_date(event.date, tzinfo=req.tz), data_events.append((day, event))
data_events.append(event)
def process_request(self, req): req.perm.assert_permission('TIMELINE_VIEW') data = {}
self.req.headers_out.add(name, str(value))
if content_type_re.match(name): self.req.content_type = value else: self.req.headers_out.add(name, str(value))
def send_header(self, name, value): self.req.headers_out.add(name, str(value))
'title': row['title'],
'title': escape(row['title'] or ''),
def perform_query (self, query, changeset, tickets, wiki, page=0): keywords = query.split(' ')
'author': row['author']}
'author': escape(row['author'])}
def perform_query (self, query, changeset, tickets, wiki, page=0): keywords = query.split(' ')
req.send_header('Content-Disposition', 'filename=Changeset%s.diff' % req.args.get('rev'))
req.send_header('Content-Disposition', 'inline;' 'filename=Changeset%s.diff' % chgset.rev)
def _render_diff(self, req, repos, chgset, diff_options): """Raw Unified Diff version""" req.send_response(200) req.send_header('Content-Type', 'text/plain;charset=utf-8') req.send_header('Content-Disposition', 'filename=Changeset%s.diff' % req.args.get('rev')) req.end_headers()
req.send_header('Content-Disposition',
req.send_header('Content-Disposition', 'attachment;'
def _render_zip(self, req, repos, chgset): """ZIP archive with all the added and/or modified files.""" req.send_response(200) req.send_header('Content-Type', 'application/zip') req.send_header('Content-Disposition', 'filename=Changeset%s.zip' % chgset.rev) req.end_headers()
add_link(req, 'start', env.href.wiki()) add_link(req, 'search', env.href.search()) add_link(req, 'help', env.href.wiki('TracGuide')) icon = env.get_config('project', 'icon') if icon: if not icon[0] == '/' and icon.find('://') < 0: icon = htdocs_location + icon mimetype = env.mimeview.get_mimetype(icon) add_link(req, 'icon', icon, type=mimetype) add_link(req, 'shortcut icon', icon, type=mimetype)
def populate_hdf(hdf, env, req=None): from trac import __version__ from time import gmtime, localtime, strftime hdf['trac'] = { 'version': __version__, 'time': strftime('%c', localtime()), 'time.gmt': strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime()) } hdf['trac.href'] = { 'wiki': env.href.wiki(), 'browser': env.href.browser('/'), 'timeline': env.href.timeline(), 'roadmap': env.href.roadmap(), 'milestone': env.href.milestone(None), 'report': env.href.report(), 'query': env.href.query(), 'newticket': env.href.newticket(), 'search': env.href.search(), 'about': env.href.about(), 'about_config': env.href.about('config'), 'login': env.href.login(), 'logout': env.href.logout(), 'settings': env.href.settings(), 'homepage': 'http://trac.edgewall.com/' } hdf['project'] = { 'name': env.get_config('project', 'name'), 'name.encoded': escape(env.get_config('project', 'name')), 'descr': env.get_config('project', 'descr'), 'footer': env.get_config('project', 'footer', 'Visit the Trac open source project at<br />' '<a href="http://trac.edgewall.com/">' 'http://trac.edgewall.com/</a>'), 'url': env.get_config('project', 'url') } htdocs_location = env.get_config('trac', 'htdocs_location') if htdocs_location[-1] != '/': htdocs_location += '/' hdf['htdocs_location'] = htdocs_location src = env.get_config('header_logo', 'src') src_abs = re.match(r'https?://', src) != None if not src[0] == '/' and not src_abs: src = htdocs_location + src hdf['header_logo'] = { 'link': env.get_config('header_logo', 'link'), 'alt': escape(env.get_config('header_logo', 'alt')), 'src': src, 'src_abs': src_abs, 'width': env.get_config('header_logo', 'width'), 'height': env.get_config('header_logo', 'height') } add_link(req, 'start', env.href.wiki()) add_link(req, 'search', env.href.search()) add_link(req, 'help', env.href.wiki('TracGuide')) icon = env.get_config('project', 'icon') if icon: if not icon[0] == '/' and icon.find('://') < 0: icon = htdocs_location + icon mimetype = env.mimeview.get_mimetype(icon) add_link(req, 'icon', icon, type=mimetype) add_link(req, 'shortcut icon', icon, type=mimetype) if req: hdf['base_url'] = req.base_url hdf['base_host'] = req.base_url[:req.base_url.rfind(req.cgi_location)] hdf['cgi_location'] = req.cgi_location hdf['trac.authname'] = escape(req.authname)
r"(?P<bolditalic>%s)" % BOLDITALIC_TOKEN, r"(?P<bold>%s)" % BOLD_TOKEN, r"(?P<italic>%s)" % ITALIC_TOKEN,
r"(?P<bolditalic>!?%s)" % BOLDITALIC_TOKEN, r"(?P<bold>!?%s)" % BOLD_TOKEN, r"(?P<italic>!?%s)" % ITALIC_TOKEN,
def process(self, req, text, in_paragraph=False): if self.error: text = system_message(Markup('Error: Failed to load processor ' '<code>%s</code>', self.name), self.error) else: text = self.processor(req, text) if in_paragraph: content_for_span = None interrupt_paragraph = False if isinstance(text, Element): tagname = text.tagname.lower() if tagname == 'div': class_ = text.attr.get('class_', '') if class_ and 'code' in class_: content_for_span = text.children else: interrupt_paragraph = True elif tagname == 'table': interrupt_paragraph = True else: match = re.match(self._code_block_re, text) if match: if match.group(1) and 'code' in match.group(1): content_for_span = match.group(2) else: interrupt_paragraph = True elif text.startswith('<table'): interrupt_paragraph = True if content_for_span: text = html.SPAN(class_='code-block')[content_for_span] elif interrupt_paragraph: text = "</p>%s<p>" % to_unicode(text) return to_unicode(text)
_anchor_re = re.compile('[^\w\d\.-:]+', re.UNICODE)
_anchor_re = re.compile('[^\w\.-:]+', re.UNICODE)
def process(self, req, text, in_paragraph=False): if self.error: text = system_message(Markup('Error: Failed to load processor ' '<code>%s</code>', self.name), self.error) else: text = self.processor(req, text) if in_paragraph: content_for_span = None interrupt_paragraph = False if isinstance(text, Element): tagname = text.tagname.lower() if tagname == 'div': class_ = text.attr.get('class_', '') if class_ and 'code' in class_: content_for_span = text.children else: interrupt_paragraph = True elif tagname == 'table': interrupt_paragraph = True else: match = re.match(self._code_block_re, text) if match: if match.group(1) and 'code' in match.group(1): content_for_span = match.group(2) else: interrupt_paragraph = True elif text.startswith('<table'): interrupt_paragraph = True if content_for_span: text = html.SPAN(class_='code-block')[content_for_span] elif interrupt_paragraph: text = "</p>%s<p>" % to_unicode(text) return to_unicode(text)
def simple_tag_handler(self, open_tag, close_tag):
def simple_tag_handler(self, match, open_tag, close_tag):
def simple_tag_handler(self, open_tag, close_tag): """Generic handler for simple binary style tags""" if self.tag_open_p((open_tag, close_tag)): return self.close_tag(close_tag) else: self.open_tag(open_tag, close_tag) return open_tag
return self.simple_tag_handler('<strong>', '</strong>')
return self.simple_tag_handler(match, '<strong>', '</strong>')
def _bold_formatter(self, match, fullmatch): return self.simple_tag_handler('<strong>', '</strong>')
return self.simple_tag_handler('<i>', '</i>')
return self.simple_tag_handler(match, '<i>', '</i>')
def _italic_formatter(self, match, fullmatch): return self.simple_tag_handler('<i>', '</i>')
if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<span class="underline">', '</span>')
return self.simple_tag_handler(match, '<span class="underline">', '</span>')
def _underline_formatter(self, match, fullmatch): if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<span class="underline">', '</span>')
if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<del>', '</del>')
return self.simple_tag_handler(match, '<del>', '</del>')
def _strike_formatter(self, match, fullmatch): if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<del>', '</del>')
if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<sub>', '</sub>')
return self.simple_tag_handler(match, '<sub>', '</sub>')
def _subscript_formatter(self, match, fullmatch): if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<sub>', '</sub>')
if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<sup>', '</sup>')
return self.simple_tag_handler(match, '<sup>', '</sup>')
def _superscript_formatter(self, match, fullmatch): if match[0] == '!': return match[1:] else: return self.simple_tag_handler('<sup>', '</sup>')
if key in self[section].overriden:
if key in self[section].overridden:
def save(self): """Write the configuration options to the primary file.""" if not self.filename: return
__slots__ = ['config', 'name', 'overriden']
__slots__ = ['config', 'name', 'overridden']
def has_site_option(self, section, name): return self.site_parser.has_option(section, name)
self.overriden = {}
self.overridden = {}
def __init__(self, config, name): self.config = config self.name = name self.overriden = {}
self.overriden[name] = True
self.overridden[name] = True
def set(self, name, value): """Change a configuration value. These changes are not persistent unless saved with `save()`. """ if not self.config.parser.has_section(self.name): self.config.parser.add_section(self.name) if value is None: self.overriden[name] = True value = '' else: value = to_unicode(value).encode('utf-8') return self.config.parser.set(self.name, name, value)
message = wiki_to_oneliner(util.shorten_line(message), env, db)
message = wiki_to_oneliner(shortlog, env, db)
def _get_changes(env, repos, revs, full=None, req=None, format=None): db = env.get_db_cnx() changes = {} for rev in revs: changeset = repos.get_changeset(rev) message = changeset.message files = None if format == 'changelog': files = [change[0] for change in changeset.get_changes()] elif message: if not full: message = wiki_to_oneliner(util.shorten_line(message), env, db) else: message = wiki_to_html(message, env, req, db, absurls=(format == 'rss'), escape_newlines=True) if not message: message = '--' changes[rev] = { 'date_seconds': changeset.date, 'date': time.strftime('%x %X', time.localtime(changeset.date)), 'age': util.pretty_timedelta(changeset.date), 'author': changeset.author or 'anonymous', 'message': message, 'files': files } return changes
'filename': attachment.filename}
'filename': attachment.filename, 'attachment': attachment}
def _render_confirm(self, req, attachment): perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE'} req.perm.assert_permission(perm_map[attachment.parent_type])
cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host, port=port, use_unicode=True, charset='utf8')
if (self._mysqldb_gt_or_eq((1, 2, 1))): cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host, port=port, charset='utf8') else: cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host, port=port, use_unicode=True) self._set_character_set(cnx, 'utf8')
def __init__(self, path, user=None, password=None, host=None, port=None, params={}): import MySQLdb
cursor = self.db.cursor()
self.env.log.debug('Promoting anonymous session %s to authenticated ' 'session for user %s' % (sid, req.authname)) cursor = self.db.cursor()
def promote_session(self, sid): """ Promotes an anonymous session to an authenticated session, if there is no preexisting session data for that user name. """ assert self.req.authname != 'anonymous', \ 'Cannot promote session of anonymous user'
self.perm.assert_permission(perm.TICKET_CREATE)
def render (self): if self.args.has_key('create'): self.perm.assert_permission(perm.TICKET_CREATE) self.create_ticket()
pfx = '%s.changes.%d' % (self.prefix, self.changeno)
self.changeno += 1 pfx = '%s.changes.%d.line' % (self.prefix, self.changeno)
def writeline(self, text): match = header_re.search(text) if match: self.hdf.setValue('%s.name.old' % self.prefix, match.group(1)) self.hdf.setValue('%s.name.new' % self.prefix, match.group(2)) return self.count = self.count + 1 if self.count < 3: return match = line_re.search(text) if match: pfx = '%s.changes.%d' % (self.prefix, self.changeno) self.print_block() self.hdf.setValue('%s.old' % pfx, match.group(1)) self.hdf.setValue('%s.new' % pfx, match.group(3)) self.changeno += 1 return ttype = text[0] text = text[1:] text = space_re.sub('&nbsp; ', text.expandtabs(8)) if ttype == self.ttype: self.block.append(text) else: if ttype == '+' and self.ttype == '-': self.p_block = self.block self.p_type = self.ttype else: self.print_block() self.block = [text] self.ttype = ttype
self.changeno += 1
def writeline(self, text): match = header_re.search(text) if match: self.hdf.setValue('%s.name.old' % self.prefix, match.group(1)) self.hdf.setValue('%s.name.new' % self.prefix, match.group(2)) return self.count = self.count + 1 if self.count < 3: return match = line_re.search(text) if match: pfx = '%s.changes.%d' % (self.prefix, self.changeno) self.print_block() self.hdf.setValue('%s.old' % pfx, match.group(1)) self.hdf.setValue('%s.new' % pfx, match.group(3)) self.changeno += 1 return ttype = text[0] text = text[1:] text = space_re.sub('&nbsp; ', text.expandtabs(8)) if ttype == self.ttype: self.block.append(text) else: if ttype == '+' and self.ttype == '-': self.p_block = self.block self.p_type = self.ttype else: self.print_block() self.block = [text] self.ttype = ttype
clause.append('%s = \'%s\'' % (constraints[i], vals[j].value))
vals[j] = vals[j].value clause.append('%s = \'%s\'' % (constraints[i], vals[j]))
def render(self): self.perm.assert_permission(perm.TICKET_VIEW)
clause.append('%s = \'%s\'' % (constraints[i], vals.value))
vals = vals.value clause.append('%s = \'%s\'' % (constraints[i], vals))
def render(self): self.perm.assert_permission(perm.TICKET_VIEW)
r"(?P<list>^(?P<ldepth>\s+)(?:\*|\d+\.|[a-zA-Z]+\.) )",
r"(?P<list>^(?P<ldepth>\s+)(?:\*|\d+\.|[a-zA-Z]\.|[ivxIVX]{1,5}\.) )",
def process(self, req, text, in_paragraph=False): if self.error: return system_message(Markup('Error: Failed to load processor ' '<code>%s</code>', self.name), self.error) text = self.processor(req, text) if in_paragraph: content_for_span = None interrupt_paragraph = False if isinstance(text, Element): tagname = text.tagname.lower() if tagname == 'div': class_ = text.attr.get('class_', '') if class_ and 'code' in class_: content_for_span = text.children else: interrupt_paragraph = True elif tagname == 'table': interrupt_paragraph = True else: match = re.match(self._code_block_re, text) if match: if match.group(1) and 'code' in match.group(1): content_for_span = match.group(2) else: interrupt_paragraph = True elif text.startswith('<table'): interrupt_paragraph = True if content_for_span: text = html.SPAN(class_='code-block')[content_for_span] elif interrupt_paragraph: text = "</p>%s<p>" % text return to_unicode(text)
[wiki:TracTickets
[TracTickets
def validate_ticket(req, ticket): """Validate a ticket after it's been populated from user input. Must return a list of `(field, message)` tuples, one for each problem detected. `field` can be `None` to indicate an overall problem with the ticket. Therefore, a return value of `[]` means everything is OK."""
page_name = 'WikiStart' else: page_name = self._set_title(req, page, '')
def _render_view(self, req, db, page): req.perm.assert_permission('WIKI_VIEW')
_anchor_re = re.compile('[^\w\d]+')
_anchor_re = re.compile('[^\w\d\.-_:]+', re.UNICODE)
def format(self, text, out): if not text: return self.out = out self._open_tags = []
if anchor[0].isdigit(): anchor = '_' + anchor
if not anchor or not anchor[0].isalpha(): anchor = 'a' + anchor
def _heading_formatter(self, match, fullmatch): match = match.strip() self.close_table() self.close_paragraph() self.close_indentation() self.close_list()
req.redirect(self.env.href.wiki(pagename, version, action='diff'))
req.redirect(self.env.href.wiki(pagename, version=version, action='diff'))
def _render_diff(self, req, pagename, version): # Stores the diff-style in the session if it has been changed, and adds # diff-style related item to the HDF self.perm.assert_permission(perm.WIKI_VIEW)
env_cache_lock.acquire() if not env_path in env_cache: env_cache[env_path] = open_environment(env_path, mpr) env = env_cache[env_path] env_cache_lock.release()
try: env = None env_cache_lock.acquire() if not env_path in env_cache: env_cache[env_path] = open_environment(env_path, mpr) env = env_cache[env_path] finally: env_cache_lock.release()
def get_environment(req, mpr): global env_cache, env_cache_lock options = req.get_options() if not options.has_key('TracEnv') and not options.has_key('TracEnvParentDir'): raise EnvironmentError, \ 'Missing PythonOption "TracEnv" or "TracEnvParentDir". Trac '\ 'requires one of these options to locate the Trac environment(s).' if options.has_key('TracEnv'): env_path = options['TracEnv'] elif options.has_key('TracEnvParentDir'): env_parent_dir = options['TracEnvParentDir'] env_name = mpr.cgi_location.split('/')[-1] env_path = os.path.join(env_parent_dir, env_name) if len(env_name) == 0 or not os.path.exists(env_path): send_project_index(req, mpr, env_parent_dir) return None env_cache_lock.acquire() if not env_path in env_cache: env_cache[env_path] = open_environment(env_path, mpr) env = env_cache[env_path] env_cache_lock.release() return env
data = {}
def display_html(self, req, query): req.hdf['title'] = 'Custom Query' add_stylesheet(req, 'css/report.css')
data['id'] = ticket.id data['time'] = ticket.time_created data['changetime'] = ticket.time_changed data['removed'] = True
def display_html(self, req, query): req.hdf['title'] = 'Custom Query' add_stylesheet(req, 'css/report.css')
deletions[key_path] = idx
deletions[base_path] = idx
def get_changes(self): pool = Pool(self.pool) tmp = Pool(pool) root = fs.revision_root(self.fs_ptr, self.rev, pool()) editor = repos.RevisionChangeCollector(self.fs_ptr, self.rev, pool()) e_ptr, e_baton = delta.make_editor(editor, pool()) repos.svn_repos_replay(root, e_ptr, e_baton, pool())
k = k.lstrip('/')
def get_changes(self): pool = Pool(self.pool) tmp = Pool(pool) root = fs.revision_root(self.fs_ptr, self.rev, pool()) editor = repos.RevisionChangeCollector(self.fs_ptr, self.rev, pool()) e_ptr, e_baton = delta.make_editor(editor, pool()) repos.svn_repos_replay(root, e_ptr, e_baton, pool())
not mime_type.startswith('text/plain'):
mime_type and not mime_type.startswith('text/plain'):
def _render_view(self, req, attachment): perm_map = {'ticket': 'TICKET_VIEW', 'wiki': 'WIKI_VIEW'} req.perm.assert_permission(perm_map[attachment.parent_type])
u, h = line.strip().split(':')
line = line.strip() if not line: continue try: u, h = line.split(':') except ValueError: print >>sys.stderr, 'Warning: invalid password line in %s: %s' \ % (filename, line) continue
def load(self, filename): fd = open(filename, 'r') for line in fd: u, h = line.strip().split(':') if '$' in h or self.crypt: self.hash[u] = h else: print >>sys.stderr, 'Warning: cannot parse password for ' \ 'user "%s" without the "crypt" module' % u
u, r, a1 = line.strip().split(':')
line = line.strip() if not line: continue try: u, r, a1 = line.split(':') except ValueError: print >>sys.stderr, 'Warning: invalid digest line in %s: %s' \ % (filename, line) continue
def load_htdigest(self, filename, realm): """Load account information from apache style htdigest files, only users from the specified realm are used """ fd = open(filename, 'r') for line in fd.readlines(): u, r, a1 = line.strip().split(':') if r == realm: self.hash[u] = a1 if self.hash == {}: print >> sys.stderr, "Warning: found no users in realm:", realm
logo_width = IntOption('header_logo', 'width', 236,
logo_width = IntOption('header_logo', 'width', -1,
def get_templates_dirs(): """Return a list of directories containing the provided ClearSilver templates. """
logo_height = IntOption('header_logo', 'height', 73,
logo_height = IntOption('header_logo', 'height', -1,
def get_templates_dirs(): """Return a list of directories containing the provided ClearSilver templates. """
'width': self.logo_width, 'height': self.logo_height
'width': width, 'height': height
def populate_hdf(self, req, handler): """Add chrome-related data to the HDF."""
r"(?P<lhref>!?\[(?P<lns>\w+):(?P<ltgt>[^ ]+) (?P<label>.*?)\])",
r"(?P<lhref>!?\[(?P<lns>\w+):(?P<ltgt>[^\] ]+)(?: (?P<label>.*?))?\])",
def process(self, req, text, inline=False): if self.error: return system_message('Error: Failed to load processor <code>%s</code>' % self.name, self.error) text = self.processor(req, text, self.env) if inline: code_block_start = re.compile('^<div class="code-block">') code_block_end = re.compile('</div>$') text, nr = code_block_start.subn('<span class="code-block">', text, 1 ) if nr: text, nr = code_block_end.subn('</span>', text, 1 ) return text else: return text
label = fullmatch.group('label')
label = fullmatch.group('label') or target
def _lhref_formatter(self, match, fullmatch): ns = fullmatch.group('lns') target = fullmatch.group('ltgt') label = fullmatch.group('label') if ns in self.link_resolvers: return self._link_resolvers[ns](self, ns, target, label) elif target[:2] == '//': return self._make_ext_link(ns+':'+target, label) else: return match
for field in constraints:
for field in constraints.keys():
def query(self, constraints, order=None, desc=0): href = href_join(self.base, 'query') params = [] for field in constraints: values = constraints[field] if type(values) != list: values = [values] for value in values: params.append(field + '=' + urllib.quote(value)) if order: params.append('order=' + urllib.quote(order)) if desc: params.append('desc=1') if params: href += '?' + ('&').join(params) return href
field['options'] = items.get(name + '.options', '').split('|')
field['options'] = map(lambda x: x.strip(), items.get(name + '.options', '').split('|'))
def get_custom_fields(env): cfg = env.config.options('ticket-custom') if not cfg: return [] names = [] items = {} for k, v in cfg: items[k] = v if '.' not in k: names.append(k) fields = [] for name in names: field = { 'name': name, 'type': items[name], 'order': items.get(name + '.order', '0'), 'label': items.get(name + '.label', ''), 'value': items.get(name + '.value', '') } if field['type'] == 'select' or field['type'] == 'radio': field['options'] = items.get(name + '.options', '').split('|') elif field['type'] == 'textarea': field['width'] = items.get(name + '.cols', '') field['height'] = items.get(name + '.rows', '') fields.append(field) def cmp_by_order(a, b): try: return int(a['order']) - int(b['order']) except: if a['order'] < b['order']: return -1 elif a['order'] > b['order']: return 1 else: return 0 fields.sort(cmp_by_order) return fields
pfx = 'ticket.custom.%i' % i
pfx = 'ticket.custom.%d' % i
def insert_custom_fields(env, hdf, vals = {}): fields = get_custom_fields(env) i = 0 for f in fields: name = f['name'] val = vals.get('custom_' + name, f['value']) pfx = 'ticket.custom.%i' % i hdf['%s.name' % pfx] = f['name'] hdf['%s.type' % pfx] = f['type'] hdf['%s.label' % pfx] = f['label'] or f['name'] hdf['%s.value' % pfx] = val if f['type'] == 'select' or f['type'] == 'radio': j = 0 for option in f['options']: hdf['%s.option.%d' % (pfx, j)] = option if val and (option == val or str(j) == val): hdf['%s.option.%i.selected' % (pfx, j)] = 1 j += 1 elif f['type'] == 'checkbox': if val in util.TRUE: hdf['%s.selected' % pfx] = 1 elif f['type'] == 'textarea': hdf['%s.width' % pfx] = f['width'] hdf['%s.height' % pfx] = f['height'] i += 1
hdf['%s.option.%i.selected' % (pfx, j)] = 1
hdf['%s.option.%d.selected' % (pfx, j)] = 1
def insert_custom_fields(env, hdf, vals = {}): fields = get_custom_fields(env) i = 0 for f in fields: name = f['name'] val = vals.get('custom_' + name, f['value']) pfx = 'ticket.custom.%i' % i hdf['%s.name' % pfx] = f['name'] hdf['%s.type' % pfx] = f['type'] hdf['%s.label' % pfx] = f['label'] or f['name'] hdf['%s.value' % pfx] = val if f['type'] == 'select' or f['type'] == 'radio': j = 0 for option in f['options']: hdf['%s.option.%d' % (pfx, j)] = option if val and (option == val or str(j) == val): hdf['%s.option.%i.selected' % (pfx, j)] = 1 j += 1 elif f['type'] == 'checkbox': if val in util.TRUE: hdf['%s.selected' % pfx] = 1 elif f['type'] == 'textarea': hdf['%s.width' % pfx] = f['width'] hdf['%s.height' % pfx] = f['height'] i += 1
if cursor.fetchone():
if cursor.fetchone()[0] == 0:
def delete(self, version=None, db=None): assert self.exists, 'Cannot delete non-existent page' if not db: db = self.env.get_db_cnx() handle_ta = True else: handle_ta = False