本文整理汇总了Python中trac.ticket.Ticket类的典型用法代码示例。如果您正苦于以下问题:Python Ticket类的具体用法?Python Ticket怎么用?Python Ticket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ticket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _save_ticket_changes
def _save_ticket_changes(self, req, env, log, selectedTickets, tickets,
values, comment, modify_changetime, send_notifications):
for id in selectedTickets:
if id in tickets:
t = Ticket(env, int(id))
new_changetime = datetime.now(utc)
log_msg = ""
if not modify_changetime:
original_changetime = to_timestamp(t.time_changed)
_values = values.copy()
for field in [f for f in values.keys() \
if f in self._fields_as_list]:
_values[field] = self._merge_keywords(t.values[field],
values[field],
log)
t.populate(_values)
t.save_changes(req.authname, comment, when=new_changetime)
if send_notifications:
tn = TicketNotifyEmail(env)
tn.notify(t, newticket=0, modtime=new_changetime)
if not modify_changetime:
self._reset_changetime(env, original_changetime, t)
log_msg = "(changetime not modified)"
log.debug('BatchModifyPlugin: saved changes to #%s %s' %
(id, log_msg))
示例2: _insert_ticket
def _insert_ticket(cls, env, summary, **kw):
"""Helper for inserting a ticket into the database"""
ticket = Ticket(env)
ticket["summary"] = summary
for k, v in kw.items():
ticket[k] = v
return ticket.insert()
示例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: handle_commit
def handle_commit(commit, env):
from trac.ticket.notification import TicketNotifyEmail
from trac.ticket import Ticket
from trac.util.text import to_unicode
from trac.util.datefmt import utc
msg = to_unicode(call_git('rev-list', ['-n', '1', commit, '--pretty=medium']).rstrip())
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'
# trac 1.0: `db` parameter is no longer needed and will be removed in 1.1.1
# trac 1.0: `cnum` parameter is deprecated
ticket.save_changes(eml, msg, now)
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)
示例5: 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
示例6: save_changesets
def save_changesets(self, ticket_id, author, rev, when=0):
"""
Store ticket setchangesets in the database. The ticket must already exist in
the database.
"""
# TODO: fetch ticket and assert it exists
ticket = Ticket(self.env, ticket_id)
assert ticket.exists, 'Cannot update a new ticket'
db = None
if not db:
db = self.env.get_db_cnx()
handle_ta = True
else:
handle_ta = False
cursor = db.cursor()
when = int(when or time.time())
cursor.execute("INSERT INTO ticket_revision (rev,ticket_id) VALUES(%s,%s)",
(rev, ticket_id))
if handle_ta:
db.commit()
ticket._old = {}
ticket.time_changed = when
示例7: process_request
def process_request(self, req):
req.perm.assert_permission('TICKET_VIEW')
action = req.args.get('action', 'view')
if not req.args.has_key('id'):
req.redirect(self.env.href.wiki())
db = self.env.get_db_cnx()
id = int(req.args.get('id'))
ticket = Ticket(self.env, id, db=db)
reporter_id = util.get_reporter_id(req)
if req.method == 'POST':
if not req.args.has_key('preview'):
self._do_save(req, db, ticket)
else:
# Use user supplied values
ticket.populate(req.args)
req.hdf['ticket.action'] = action
req.hdf['ticket.ts'] = req.args.get('ts')
req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \
or req.authname
req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution')
reporter_id = req.args.get('author')
comment = req.args.get('comment')
if comment:
req.hdf['ticket.comment'] = comment
# Wiki format a preview of comment
req.hdf['ticket.comment_preview'] = wiki_to_html(comment,
self.env,
req, db)
else:
req.hdf['ticket.reassign_owner'] = req.authname
# Store a timestamp in order to detect "mid air collisions"
req.hdf['ticket.ts'] = ticket.time_changed
self._insert_ticket_data(req, db, ticket, reporter_id)
# If the ticket is being shown in the context of a query, add
# links to help navigate in the query result set
if 'query_tickets' in req.session:
tickets = req.session['query_tickets'].split()
if str(id) in tickets:
idx = tickets.index(str(ticket.id))
if idx > 0:
add_link(req, 'first', self.env.href.ticket(tickets[0]),
'Ticket #%s' % tickets[0])
add_link(req, 'prev', self.env.href.ticket(tickets[idx - 1]),
'Ticket #%s' % tickets[idx - 1])
if idx < len(tickets) - 1:
add_link(req, 'next', self.env.href.ticket(tickets[idx + 1]),
'Ticket #%s' % tickets[idx + 1])
add_link(req, 'last', self.env.href.ticket(tickets[-1]),
'Ticket #%s' % tickets[-1])
add_link(req, 'up', req.session['query_href'])
add_stylesheet(req, 'common/css/ticket.css')
return 'ticket.cs', None
示例8: _handle_ripe_save
def _handle_ripe_save(self, req):
""" hander for save """
# TODO: workflow
# get ticket id
ticket_id = req.args.get("ticket_id")
value = req.args.get("value", "").strip()
field = req.args.get("field")
old_value = req.args.get("old_value")
# ticket
ticket = Ticket(self.env, ticket_id)
current_value = ticket.values.get(field)
# validation
if current_value != old_value and (old_value or current_value):
self.log.info("Field value should be %s, got %s" % (repr(current_value), repr(old_value)))
raise TracError("field value inconsistant.")
# set params
params = {}
params[field] = value
ticket.populate(params)
# save ticket
comment = "Updated from report"
author = get_reporter_id(req, 'author')
ticket.save_changes(author, comment)
return value
示例9: import_tickets
def import_tickets(self):
trac_cursor = self.env.get_db_cnx().cursor()
peer = SymfonyErrorPeer(self.env)
owners = {}
trac_cursor.execute("select owner, name from component")
for name, owner in trac_cursor:
owners[name] = owner
for error in peer.select_grouped():
# ticket with current hash key not exists ?
trac_cursor.execute("select ticket from ticket_custom where name = 'symfony_error_key' and value = '%s'" % error['hash_key'])
existing = trac_cursor.fetchone()
if not existing:
ticket = Ticket(self.env)
ticket.values['summary'] = 'Bug #' + error['hash_key'] + ' ' + error['message']
ticket.values['symfony_error_key'] = error['hash_key']
ticket.values['reporter'] = 'cron'
ticket.values['resolution'] = 'new'
ticket.values['status'] = 'new'
ticket.values['milestone'] = '0.3.1'
if error['module_name'] in owners:
owner = owners[error['module_name']]
else:
owner = self.default_owner
ticket.values['owner'] = owner
ticket.insert()
示例10: pre_process_request
def pre_process_request(self, req, handler):
if req.method == 'POST' and req.args.get('testman_cnum', None):
t = Ticket(self.env, tkt_id=req.args.get('path'))
cdate = t.get_change(cnum=req.args.get('testman_cnum'))['date']
comment = t.get_change(cnum=req.args.get('testman_cnum'))['fields']['comment']['new']
new_comment = u"%s\n attachment added: [attachment:ticket:%s:%s]" % (comment, req.args.get("id"), req.args.get('attachment').filename)
t.modify_comment(cdate, req.authname, new_comment, when=cdate)
return handler
示例11: 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)
示例12: __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)
示例13: create_ticket_for_lineitem
def create_ticket_for_lineitem (self, req, id, addMesage, lineitem, summary=None):
#skip line items that have a ticket
if re.search('/ticket/\d+', lineitem.description): return
compname = 'Estimate-'+str(id)
if summary: compname = summary
ensure_component(self.env, compname, req.authname)
t = Ticket(self.env)
# try to split on a newline or space that is less than 80 chars into the string
idx = lineitem.description.find('\n', 0, 80)
if idx < 0: idx = lineitem.description.find(' ', 45, 80)
if idx < 0: idx = 45
summary = lineitem.description[:idx]
desc = lineitem.description
desc += "\n\nFrom [/Estimate?id=%s Created From Estimate %s]" % \
(lineitem.estimate_id,lineitem.estimate_id)
t.values['summary'] = summary
t.values['description'] = desc
t.values['status'] = 'new'
t.values['reporter'] = req.authname
t.values['component'] = compname
t.values['estimatedhours'] = avg(lineitem.low, lineitem.high)
t.insert()
lineitem.description+="\n\nCreated as /ticket/%s" % (t.id, )
return t
示例14: _implementation
def _implementation(db):
"""Apply each change to the ticket and save it."""
for change in changes.strip(',').split(','):
change_items = change.split(':')
self.log.debug('WhiteboardModule: change_items=%s', change_items)
t = Ticket(self.env, int(change_items[0]))
values = {}
values[field] = change_items[1]
t.populate(values)
t.save_changes(req.authname)
示例15: test_remove_all
def test_remove_all(self):
test_name = sys._getframe().f_code.co_name
expected = self.expected_results[test_name]
ticket = Ticket(self.env)
ticket.populate({'reporter': 'santa', 'summary': 'Summary line',
'description': 'Lorem ipsum dolor sit amet',
})
ticket.insert()
self.assertEqual(1, len(self._get_docs()))
rv, output = self._execute('fulltext remove')
self.assertEqual(expected, output)
self.assertEqual(0, len(self._get_docs()))