本文整理汇总了Python中trac.ticket.web_ui.TicketModule类的典型用法代码示例。如果您正苦于以下问题:Python TicketModule类的具体用法?Python TicketModule怎么用?Python TicketModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TicketModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_preset
def apply_preset(self, req, tickets, preset=None):
if preset is None:
return tickets
presets = preset and [kw.split('=', 1) for kw in preset.split('&')] or []
fields = dict([(field, value) for field, value in presets])
warn = []
modified_tickets = []
if tickets and presets:
db = self.env.get_db_cnx()
ticket_module = TicketModule(self.env)
action = fields.get('action')
for ticket_id in tickets:
if 'TICKET_CHGPROP' in req.perm('ticket', ticket_id):
ticket = Ticket(self.env, ticket_id, db)
ticket.populate(fields)
if action:
field_changes, problems = ticket_module.get_ticket_changes(req, ticket, action)
if problems:
for problem in problems:
warn.append(problem)
ticket_module._apply_ticket_changes(ticket, field_changes) # Apply changes made by the workflow
ticket.save_changes(req.authname, None, db=db)
modified_tickets.append(ticket_id)
else:
warn.append(_("You have no permission to modify ticket '%(ticket)s'", ticket=ticket_id))
db.commit()
return { 'tickets' : modified_tickets, 'warnings': warn}
示例2: save_ticket
def save_ticket(self, tckt, db, msg):
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(tckt, db):
if change['permanent']:
cnum += 1
tckt.save_changes(self.authname, msg, self.now, db, cnum+1)
## Often the time overlaps and causes a db error,
## especially when the trac integration post-commit hook is used.
## NOTE TO SELF. I DON'T THINK THIS IS NECESSARY RIGHT NOW...
#count = 0
#while count < 10:
# try:
# tckt.save_changes(self.authname, msg, self.now, db, cnum+1)
# count = 42
# except Exception, e:
# self.now += 1
# count += 1
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(tckt, newticket=0, modtime=self.now)
# We fudge time as it has to be unique
self.now += 1
示例3: attachment_added
def attachment_added(self, attachment):
# Check whether we're dealing with a ticket resource
resource = attachment.resource
while resource:
if resource.realm == 'ticket':
break
resource = resource.parent
if (resource and resource.realm == 'ticket' and resource.id is not None):
with self.env.db_transaction as db:
ticket = Ticket(attachment.env, resource.id, db)
if (attachment.author == ticket['reporter'] and ticket['status'] == 'pending'):
self.env.log.info('Removing Pending status for ticket %s due to attachment' % (ticket.id))
comment = 'Attachment (%s) added by ticket reporter.' % (attachment.filename)
ticket['status'] = self.config.get('ticket', 'pending_removal_status')
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
c_cnum = change.get('cnum', None)
if c_cnum and int(c_cnum) > cnum:
cnum = int(c_cnum)
#We can't just use attachment.date as it screws up event sequencing
now = datetime.now(utc)
ticket.save_changes(attachment.author, comment, now, db, str(cnum + 1))
#trigger notification since we've changed the ticket
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=False, modtime=now)
示例4: post_to_ticket
def post_to_ticket(msg, author, tkt_id, env):
"""Post the message to the ticket and send a notify email."""
from trac.ticket.notification import TicketNotifyEmail
from trac.ticket import Ticket
from trac.ticket.web_ui import TicketModule
from trac.util.datefmt import utc
now = datetime.now(utc)
try:
db = env.get_db_cnx()
# Get the related trac ticket object
ticket = Ticket(env, tkt_id, db)
# determine sequence number...
cnum = 0
tm = TicketModule(env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(author, msg, now, db, cnum + 1)
db.commit()
tn = TicketNotifyEmail(env)
tn.notify(ticket, newticket=0, modtime=now)
except Exception, e:
msg = 'Unexpected error processing ticket ID %s: %s' % (tkt_id, e)
print >>sys.stderr, msg
示例5: process
def process(self, commit, status, branch):
self.closestatus = status
milestones = [m.name for m in Milestone.select(self.env) if m.name != "unknown"]
if branch.startswith("fixes/"):
branch = branch[6:]
milestones = [m for m in milestones if m.startswith(branch)]
self.milestone = sorted(milestones)[-1]
msg = commit["message"]
self.env.log.debug("Processing Commit: %s", msg)
msg = "%s \n Branch: %s \n Changeset: %s" % (msg, branch, commit["id"])
# author = commit['author']['name']
author = "Github"
timestamp = datetime.now(utc)
cmd_groups = command_re.findall(msg)
self.env.log.debug("Function Handlers: %s" % cmd_groups)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = self.__class__._supported_cmds.get(cmd.lower(), "")
self.env.log.debug("Function Handler: %s" % funcname)
if funcname:
for tkt_id in ticket_re.findall(tkts):
if (branch == "master") or branch.startswith("fixes/"):
tickets.setdefault(tkt_id, []).append(getattr(self, funcname))
# disable this stuff for now, it causes duplicates on merges
# proper implementation of this will require tracking commit hashes
# else:
# tickets.setdefault(tkt_id, []).append(self._cmdRefs)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change["permanent"]:
cnum += 1
ticket.save_changes(author, msg, timestamp, db, cnum + 1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=timestamp)
except Exception, e:
import traceback
traceback.print_exc(file=sys.stderr)
示例6: __init__
def __init__(self, project=options.project, author=AUTHOR,
maxage=options.maxage, url=options.url):
self.env = open_environment(project)
db = self.env.get_db_cnx()
cursor = db.cursor()
if url is None:
url = self.env.config.get('trac', 'base_url')
self.env.href = Href(url)
self.env.abs_href = Href(url)
self.msg = MESSAGE % (maxage)
self.now = int(time.time())
maxtime = int(time.time()) - (60 * 60 * 24 * maxage)
cursor.execute("SELECT id FROM ticket t, ticket_custom c " \
"WHERE t.status <> %s " \
"AND t.changetime < %s " \
"AND t.id = c.ticket " \
"AND c.name = %s " \
"AND c.value = %s ", ('closed', maxtime, 'pending', '1'))
rows = cursor.fetchall()
for row in rows:
id = row[0]
try:
ticket = Ticket(self.env, id, db);
ticket['status'] = 'closed'
ticket['pending'] = '0';
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(author, self.msg, self.now, db, cnum + 1)
db.commit()
print 'Closing Ticket %s (%s)\n' % (id, ticket['summary'])
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=self.now)
except Exception, e:
import traceback
traceback.print_exc(file=sys.stderr)
print>>sys.stderr, 'Unexpected error while processing ticket ' \
'ID %s: %s' % (id, e)
示例7: process
def process(self, commit, status, enable_revmap,reponame):
self.closestatus = status
msg = commit['message']
self.env.log.debug("Processing Commit: %s", msg)
note = "Changeset: [/changeset/%s %s]" % (commit['id'], commit['id'])
url = "URL: %s" % commit['url']
msg = "%s \n * %s \n * %s" % (msg, note, url)
author = commit['author']['name']
timestamp = datetime.now(utc)
if int(enable_revmap):
self.env.log.debug("adding commit %s to revmap", commit['id'])
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("INSERT INTO svn_revmap (svn_rev, git_hash, commit_msg) VALUES (0, %s, %s);",
(commit['id'], commit['message']))
db.commit()
cmd_groups = command_re.findall(msg)
self.env.log.debug("Function Handlers: %s" % cmd_groups)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = self.__class__._supported_cmds.get(cmd.lower(), '')
self.env.log.debug("Function Handler: %s" % funcname)
if funcname:
for tkt_id in ticket_re.findall(tkts):
func = getattr(self, funcname)
tickets.setdefault(tkt_id, []).append(func)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(author, msg, timestamp, db, cnum+1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=timestamp)
except Exception, e:
import traceback
traceback.print_exc(file=sys.stderr)
示例8: __init__
def __init__(self, project=options.project, author=options.user,
rev=options.rev, url=options.url):
self.env = open_environment(project)
repos = self.env.get_repository()
repos.sync()
# Instead of bothering with the encoding, we'll use unicode data
# as provided by the Trac versioncontrol API (#1310).
try:
chgset = repos.get_changeset(rev)
except NoSuchChangeset:
return # out of scope changesets are not cached
self.author = chgset.author
self.rev = rev
self.msg = "(In [%s]) %s" % (rev, chgset.message)
self.now = datetime.now(utc)
cmd_groups = command_re.findall(self.msg)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = CommitHook._supported_cmds.get(cmd.lower(), '')
if funcname:
for tkt_id in ticket_re.findall(tkts):
func = getattr(self, funcname)
tickets.setdefault(tkt_id, []).append(func)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(self.author, self.msg, self.now, db, cnum+1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=self.now)
except Exception, e:
# import traceback
# traceback.print_exc(file=sys.stderr)
print>>sys.stderr, 'Unexpected error while processing ticket ' \
'ID %s: %s' % (tkt_id, e)
示例9: _update_ticket
def _update_ticket(ticket):
# Determine sequence number.
cnum = 0
tm = TicketModule(self.env)
db = self.env.get_db_cnx()
for change in tm.grouped_changelog_entries(ticket, db):
# FIXME - should this say "and change['cnum'] > cnum?
if change['permanent']:
cnum = change['cnum']
# FIXME - Put something in the message?
# FIXME - the ticket_changed method gets an author, should
# this say "value propagation on behalf of <author>"?
ticket.save_changes('value propagation', '', when, db, cnum+1)
示例10: _update_controls
def _update_controls(self, req, action_controls, actions, tkt):
"""Given list of actions, update action_controls w/all requiring input.
control[2] represents HTML inputs required before an action can be
completed. If it exists, we make a note of the action operation."""
tm = TicketModule(self.env)
for (act, act_ops) in actions.itervalues():
for act_op in act_ops:
if act_op not in action_controls:
control = list(tm.get_action_control(req, act, tkt))
control[2] = str(control[2])
if control[2]:
action_controls[act_op] = control
示例11: process_request
def process_request(self, req):
id = int(req.args.get('id'))
req.perm('ticket', id).require('TICKET_ADMIN')
ticket = Ticket(self.env, id)
action = req.args['action']
cnum = req.args.get('cnum')
if req.method == 'POST':
if 'cancel' in req.args:
href = req.href.ticket(id)
if action == 'delete-comment':
href += '#comment:%s' % cnum
req.redirect(href)
if action == 'delete':
ticket.delete()
add_notice(req, _('The ticket #%(id)s has been deleted.',
id=ticket.id))
req.redirect(req.href())
elif action == 'delete-comment':
cdate = from_utimestamp(long(req.args.get('cdate')))
ticket.delete_change(cdate=cdate)
add_notice(req, _('The ticket comment %(num)s on ticket '
'#%(id)s has been deleted.',
num=cnum, id=ticket.id))
req.redirect(req.href.ticket(id))
tm = TicketModule(self.env)
data = tm._prepare_data(req, ticket)
tm._insert_ticket_data(req, ticket, data,
get_reporter_id(req, 'author'), {})
data.update(action=action, cdate=None)
if action == 'delete-comment':
data['cdate'] = req.args.get('cdate')
cdate = from_utimestamp(long(data['cdate']))
for change in data['changes']:
if change.get('date') == cdate:
data['change'] = change
data['cnum'] = change.get('cnum')
break
else:
raise TracError(_('Comment %(num)s not found', num=cnum))
elif action == 'delete':
attachments = Attachment.select(self.env, ticket.realm, ticket.id)
data.update(attachments=list(attachments))
add_stylesheet(req, 'common/css/ticket.css')
return 'ticket_delete.html', data, None
示例12: process
def process(self, commit, status, payload):
self.closestatus = status
self.env.log.debug("Processing Commit: %s", commit['id'])
comment = (commit['message']
+ "\n\n"
+ self.comment_template.format(commit=commit,**payload))
self.env.log.debug("Prepared Comment: %s", comment)
author = commit['author']['name']
timestamp = datetime.now(utc)
cmd_groups = command_re.findall(comment)
self.env.log.debug("Function Handlers: %s" % cmd_groups)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = self.__class__._supported_cmds.get(cmd.lower(), '')
self.env.log.debug("Function Handler: %s" % funcname)
if funcname:
for tkt_id in ticket_re.findall(tkts):
func = getattr(self, funcname)
tickets.setdefault(tkt_id, []).append(func)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(author, comment, timestamp, db, cnum+1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=timestamp)
except Exception, e:
import traceback
traceback.print_exc(file=sys.stderr)
示例13: handle_commit
def handle_commit(commit, env, repo):
from trac.ticket.notification import TicketNotifyEmail
from trac.ticket import Ticket
from trac.ticket.web_ui import TicketModule
from trac.util.text import to_unicode
from trac.util.datefmt import utc
commit_log = call_git("rev-list", ["-n", "1", commit, "--pretty=medium"])
commit_log = process_commit_log(commit_log, repo)
commit_log = commit_log.rstrip()
msg = to_unicode(commit_log)
eml = to_unicode(call_git("rev-list", ["-n", "1", commit, "--pretty=format:%ae"]).splitlines()[1])
now = datetime.now(utc)
tickets = {}
for cmd, tkts in command_re.findall(msg.split("\n\n", 1)[1]):
action = COMMANDS.get(cmd.lower())
if action:
for tkt_id in ticket_re.findall(tkts):
tickets.setdefault(tkt_id, []).append(action)
for tkt_id, actions in tickets.iteritems():
try:
db = env.get_db_cnx()
ticket = Ticket(env, int(tkt_id), db)
if "close" in actions:
ticket["status"] = "closed"
ticket["resolution"] = "fixed"
# determine sequence number...
cnum = 0
tm = TicketModule(env)
for change in tm.grouped_changelog_entries(ticket, db):
if change["permanent"]:
cnum += 1
ticket.save_changes(eml, msg, now, db, cnum + 1)
db.commit()
tn = TicketNotifyEmail(env)
tn.notify(ticket, newticket=0, modtime=now)
except Exception, e:
print >>sys.stderr, "Unexpected error while processing ticket ID %s: %s" % (tkt_id, e)
示例14: on_change
def on_change(self, env, chgset):
self.env = env
self.author = chgset.author
self.rev = chgset.rev
self.msg = "(In [%s]) %s" % (self.rev, chgset.message)
self.now = chgset.date
cmd_groups = command_re.findall(self.msg)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = self._supported_cmds.get(cmd.lower(), '')
if funcname:
for tkt_id in ticket_re.findall(tkts):
func = getattr(self, funcname)
tickets.setdefault(tkt_id, []).append(func)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change['permanent']:
cnum += 1
ticket.save_changes(self.author, self.msg, self.now, db, cnum+1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=self.now)
except Exception, e:
# import traceback
# traceback.print_exc(file=sys.stderr)
print>>sys.stderr, 'Unexpected error while processing ticket ' \
'ID %s: %s' % (tkt_id, e)
示例15: _implementation
def _implementation(db):
tkt = Ticket(self.env, ticket_id)
ts = TicketSystem(self.env)
tm = TicketModule(self.env)
if action not in ts.get_available_actions(req, tkt):
raise ValueError(["This ticket cannot be moved to this status,\
perhaps the ticket has been updated by someone else."])
field_changes, problems = \
tm.get_ticket_changes(req, tkt, action)
if problems:
raise ValueError(problems)
tm._apply_ticket_changes(tkt, field_changes)
valid = tm._validate_ticket(req, tkt, force_collision_check=True)
if not valid:
raise ValueError(req.chrome['warnings'])
else:
tkt.save_changes(req.authname, "", when=datetime.now(utc))