本文整理汇总了Python中trac.ticket.Ticket.save_changes方法的典型用法代码示例。如果您正苦于以下问题:Python Ticket.save_changes方法的具体用法?Python Ticket.save_changes怎么用?Python Ticket.save_changes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.ticket.Ticket
的用法示例。
在下文中一共展示了Ticket.save_changes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_commit
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例2: post_to_ticket
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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
示例3: attachment_added
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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_ripe_save
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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
示例5: _save_ticket_changes
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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))
示例6: process
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例7: __init__
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例8: move
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
def move(self, ticket_id, author, env, delete=False):
"""
move a ticket to another environment
env: environment to move to
"""
tables = {"attachment": "id", "ticket_change": "ticket"}
# open the environment if it is a string
if isinstance(env, basestring):
base_path, _project = os.path.split(self.env.path)
env = open_environment(os.path.join(base_path, env), use_cache=True)
# get the old ticket
old_ticket = Ticket(self.env, ticket_id)
# make a new ticket from the old ticket values
new_ticket = Ticket(env)
new_ticket.values = old_ticket.values.copy()
new_ticket.insert(when=old_ticket.time_created)
# copy the changelog and attachment DBs
for table, _id in tables.items():
for row in get_all_dict(self.env, "SELECT * FROM %s WHERE %s=%%s" % (table, _id), str(ticket_id)):
row[_id] = new_ticket.id
insert_row_from_dict(env, table, row)
# copy the attachments
src_attachment_dir = os.path.join(self.env.path, "attachments", "ticket", str(ticket_id))
if os.path.exists(src_attachment_dir):
dest_attachment_dir = os.path.join(env.path, "attachments", "ticket")
if not os.path.exists(dest_attachment_dir):
os.makedirs(dest_attachment_dir)
dest_attachment_dir = os.path.join(dest_attachment_dir, str(new_ticket.id))
shutil.copytree(src_attachment_dir, dest_attachment_dir)
# note the previous location on the new ticket
new_ticket.save_changes(author, "moved from %s" % self.env.abs_href("ticket", ticket_id))
# location of new ticket
new_location = env.abs_href.ticket(new_ticket.id)
if delete:
old_ticket.delete()
else:
# close old ticket and point to new one
old_ticket["status"] = u"closed"
old_ticket["resolution"] = u"moved"
old_ticket.save_changes(author, u"moved to %s" % new_location)
if env.config["trac"].get("base_url"):
return new_location
else:
return None
示例9: _implementation
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例10: process
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例11: __init__
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
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)
示例12: _update_tickets
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
def _update_tickets(self, tickets, changeset, comment, date):
"""Update the tickets with the given comment."""
perm = PermissionCache(self.env, changeset.author)
for tkt_id, cmds in tickets.iteritems():
try:
self.log.debug("Updating ticket #%d", tkt_id)
with self.env.db_transaction as db:
ticket = Ticket(self.env, tkt_id, db)
for cmd in cmds:
cmd(ticket, changeset, perm(ticket.resource))
ticket.save_changes(changeset.author, comment, date, db)
self._notify(ticket, date)
except Exception, e:
self.log.error("Unexpected error while processing ticket " "#%s: %s", tkt_id, exception_to_unicode(e))
示例13: notify_new_tickets
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
def notify_new_tickets(self, req, id, tickets, addMessage):
try:
tag = "[[Estimate(%s)]]" % id
tickets = intlist(tickets)
for t in tickets:
ticket = Ticket (self.env, t)
if ticket['description'].find (tag) == -1:
self.log.debug('Updating Ticket Description : %s'%t)
ticket['description'] = ticket['description']+'\n----\n'+tag
ticket.save_changes(req.authname, 'added estimate')
return True
except Exception, e:
self.log.error("Error saving new ticket changes: %s" % e)
addMessage("Error: %s" % e)
return None
示例14: _batch_modify
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
def _batch_modify(self, req):
tickets = req.session["query_tickets"].split(" ")
comment = req.args.get("comment", "")
values = {}
for field in TicketSystem(self.env).get_ticket_fields():
name = field["name"]
if name not in ("summary", "reporter", "description", "type", "status", "resolution", "owner"):
if req.args.has_key("bm_" + name):
values[name] = req.args.get(name)
for id in tickets:
t = Ticket(self.env, id)
t.populate(values)
t.save_changes(req.authname, comment)
示例15: process_request
# 需要导入模块: from trac.ticket import Ticket [as 别名]
# 或者: from trac.ticket.Ticket import save_changes [as 别名]
def process_request(self, req, db=None):
req.perm.assert_permission('TRAC_ADMIN')
if not db:
self.db = self.env.get_db_cnx()
ticket_id = req.args.get('ticket_id')
req.hdf['ticket_id'] = ticket_id
req.hdf['message'] = ''
repos = self.env.get_repository(req.authname)
authzperm = SubversionAuthorizer(self.env, req.authname)
diff_options = get_diff_options(req)
if req.args.has_key('update'):
req.redirect(self.env.href.svnpublish(ticket_id))
ticket = Ticket(self.env, ticket_id)
chgset = []
if(ticket['ticketaction'] == "ClonePublish"):
from publishrevert.setchangeset import SetChangesetModule
setchangeset = SetChangesetModule(self.env)
setchangesets = setchangeset.get_setchangesets(ticket_id)
# get the list of changesets for the ticket_id
# then loop through and get the actual changesets like the following line
for rev in setchangesets:
authzperm.assert_permission_for_changeset(rev)
changeset = repos.get_changeset(rev)
# now loop through the files in changeset to get all the paths
# and for each path, find the current test/prod revision number and save that info
chgset.append(changeset)
format = req.args.get('format')
self._render_html(req, ticket, repos, chgset, diff_options)
req.hdf['setchangesets'] = setchangesets
ticket['ticketaction'] = 'CloneTest'
ticket.save_changes(req.authname, 'published to clone', 0, db)
req.hdf['message'] += 'Successfully Published All Files'
req.hdf['ticket'] = ticket.values
else:
req.hdf['error'] = 'Error: not in correct state to publish'
return 'setchangeset.cs', None