本文整理汇总了Python中trac.ticket.notification.TicketNotifyEmail类的典型用法代码示例。如果您正苦于以下问题:Python TicketNotifyEmail类的具体用法?Python TicketNotifyEmail怎么用?Python TicketNotifyEmail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TicketNotifyEmail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: test_ignore_domains
def test_ignore_domains(self):
"""Non-SMTP domain exclusion"""
self.env.config.set('notification', 'ignore_domains',
'example.com, example.org')
self.env.known_users = \
[('[email protected]', 'No Email', ''),
('[email protected]', 'With Email', '[email protected]')]
ticket = Ticket(self.env)
ticket['reporter'] = '[email protected]'
ticket['owner'] = '[email protected]'
ticket['summary'] = 'This is a summary'
ticket.insert()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should always have a 'To' field
self.failIf('To' not in headers)
tolist = [addr.strip() for addr in headers['To'].split(',')]
# 'To' list should not contain addresses with non-SMTP domains
self.failIf('[email protected]' in tolist)
self.failIf('[email protected]' in tolist)
# 'To' list should have been resolved to the actual email address
self.failIf('[email protected]' not in tolist)
self.failIf(len(tolist) != 1)
示例3: create
def create(self, req, summary, description, attributes = {}, notify=False):
""" Create a new ticket, returning the ticket ID.
PS: Borrowed from XmlRpcPlugin.
"""
t = Ticket(self.env)
t['summary'] = summary
t['description'] = description
t['reporter'] = req.authname
for k, v in attributes.iteritems():
t[k] = v
t['status'] = 'new'
t['resolution'] = ''
t.insert()
# Call ticket change listeners
ts = TicketSystem(self.env)
for listener in ts.change_listeners:
listener.ticket_created(t)
if notify:
try:
tn = TicketNotifyEmail(self.env)
tn.notify(t, newticket=True)
except Exception, e:
self.log.exception("Failure sending notification on creation "
"of ticket #%s: %s" % (t.id, e))
示例4: ticket_changed
def ticket_changed(self,ticket,comment,author,old_values):
self.env.log.debug("ticket_change - TicketNotifySMS: %s" % author)
# Q) why does debug work on DEBUG setting but not INFO?
db = self.env.get_db_cnx()
cursor = db.cursor()
sql = "select field, newvalue from ticket_change where ticket = %s ORDER BY time DESC LIMIT 1" % ticket.id
cursor.execute(sql)
data = cursor.fetchall()
msg = ''
for row in data:
# TODO check alerts aren't needed on other fields
if row[0] == 'comment':
patt = re.compile('{{{(.+)}}}')
mobj = patt.match(row[1])
self.env.log.debug('comment value: ' + row[1])
body = ''
try:
body = mobj.group(0)
except AttributeError:
self.env.log.debug('no brackets')
body = row[1]
msg = "Re: shot %s - %s" % (ticket.values['summary'], body )
# ticket.id if necessary
tne = TicketNotifyEmail(self.env)
peeps = tne.get_recipients(ticket.id)
list = {}
for person in peeps:
for p in person:
list[p] = 1
for k in list.keys():
self.env.log.debug("recepient: %s" % k)
if k != None:
self.sms(k, str(ticket.time_changed), ticket.values['summary'], msg)
示例5: test_recipients
def test_recipients(self):
"""To/Cc recipients"""
ticket = Ticket(self.env)
ticket['reporter'] = '"Joe User" <[email protected]>'
ticket['owner'] = '[email protected]'
ticket['cc'] = '[email protected], [email protected], ' \
'[email protected]'
ticket['summary'] = 'Foo'
ticket.insert()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
recipients = notifysuite.smtpd.get_recipients()
# checks there is no duplicate in the recipient list
rcpts = []
for r in recipients:
self.failIf(r in rcpts)
rcpts.append(r)
# checks that all cc recipients have been notified
cc_list = self.env.config.get('notification', 'smtp_always_cc')
cc_list = "%s, %s" % (cc_list, ticket['cc'])
for r in cc_list.replace(',', ' ').split():
self.failIf(r not in recipients)
# checks that owner has been notified
self.failIf(smtp_address(ticket['owner']) not in recipients)
# checks that reporter has been notified
self.failIf(smtp_address(ticket['reporter']) not in recipients)
示例6: test_email_map
def test_email_map(self):
"""Login-to-email mapping"""
self.env.config.set("notification", "always_notify_owner", "true")
self.env.config.set("notification", "always_notify_reporter", "true")
self.env.config.set("notification", "smtp_always_cc", "[email protected]")
self.env.known_users = [
("joeuser", "Joe User", "[email protected]"),
("[email protected]", "Jim User", "[email protected]"),
]
ticket = Ticket(self.env)
ticket["reporter"] = "joeuser"
ticket["owner"] = "[email protected]"
ticket["summary"] = "This is a summary"
ticket.insert()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should always have a 'To' field
self.failIf("To" not in headers)
tolist = [addr.strip() for addr in headers["To"].split(",")]
# 'To' list should have been resolved to the real email address
self.failIf("[email protected]" not in tolist)
self.failIf("[email protected]" not in tolist)
self.failIf("joeuser" in tolist)
self.failIf("[email protected]" in tolist)
示例7: _test_default_domain
def _test_default_domain(enabled):
self.env.config.set("notification", "always_notify_owner", "false")
self.env.config.set("notification", "always_notify_reporter", "false")
self.env.config.set("notification", "smtp_always_cc", "")
ticket = Ticket(self.env)
ticket["cc"] = "joenodom, [email protected]"
ticket["summary"] = "This is a summary"
ticket.insert()
# Be sure that at least one email address is valid, so that we
# send a notification even if other addresses are not valid
self.env.config.set("notification", "smtp_always_cc", "[email protected]")
if enabled:
self.env.config.set("notification", "smtp_default_domain", "example.org")
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should always have a 'Cc' field
self.failIf("Cc" not in headers)
cclist = [addr.strip() for addr in headers["Cc"].split(",")]
self.failIf("[email protected]" not in cclist)
self.failIf("[email protected]" not in cclist)
if not enabled:
self.failIf(len(cclist) != 2)
self.failIf("joenodom" in cclist)
else:
self.failIf(len(cclist) != 3)
self.failIf("[email protected]" not in cclist)
示例8: test_ignore_domains
def test_ignore_domains(self):
"""Non-SMTP domain exclusion"""
self.env.config.set("notification", "ignore_domains", "example.com, example.org")
self.env.known_users = [
("[email protected]", "No Email", ""),
("[email protected]", "With Email", "[email protected]"),
]
ticket = Ticket(self.env)
ticket["reporter"] = "[email protected]"
ticket["owner"] = "[email protected]"
ticket["summary"] = "This is a summary"
ticket.insert()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should always have a 'To' field
self.failIf("To" not in headers)
tolist = [addr.strip() for addr in headers["To"].split(",")]
# 'To' list should not contain addresses with non-SMTP domains
self.failIf("[email protected]" in tolist)
self.failIf("[email protected]" in tolist)
# 'To' list should have been resolved to the actual email address
self.failIf("[email protected]" not in tolist)
self.failIf(len(tolist) != 1)
示例9: _test_short_login
def _test_short_login(enabled):
ticket = Ticket(self.env)
ticket["reporter"] = "joeuser"
ticket["summary"] = "This is a summary"
ticket.insert()
# Be sure that at least one email address is valid, so that we
# send a notification even if other addresses are not valid
self.env.config.set("notification", "smtp_always_cc", "[email protected]")
if enabled:
self.env.config.set("notification", "use_short_addr", "true")
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should not have a 'To' header
if not enabled:
self.failIf("To" in headers)
else:
tolist = [addr.strip() for addr in headers["To"].split(",")]
# Msg should have a 'Cc' field
self.failIf("Cc" not in headers)
cclist = [addr.strip() for addr in headers["Cc"].split(",")]
if enabled:
# Msg should be delivered to the reporter
self.failIf(ticket["reporter"] not in tolist)
else:
# Msg should not be delivered to joeuser
self.failIf(ticket["reporter"] in cclist)
# Msg should still be delivered to the always_cc list
self.failIf(self.env.config.get("notification", "smtp_always_cc") not in cclist)
示例10: _validate_mimebody
def _validate_mimebody(self, mime, ticket, newtk):
"""Body of a ticket notification message"""
(mime_decoder, mime_name, mime_charset) = mime
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=newtk)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
self.failIf('MIME-Version' not in headers)
self.failIf('Content-Type' not in headers)
self.failIf('Content-Transfer-Encoding' not in headers)
self.failIf(not re.compile(r"1.\d").match(headers['MIME-Version']))
type_re = re.compile(r'^text/plain;\scharset="([\w\-\d]+)"$')
charset = type_re.match(headers['Content-Type'])
self.failIf(not charset)
charset = charset.group(1)
self.assertEqual(charset, mime_charset)
self.assertEqual(headers['Content-Transfer-Encoding'], mime_name)
# checks the width of each body line
for line in body.splitlines():
self.failIf(len(line) > MAXBODYWIDTH)
# attempts to decode the body, following the specified MIME endoding
# and charset
try:
if mime_decoder:
body = mime_decoder.decodestring(body)
body = unicode(body, charset)
except Exception, e:
raise AssertionError, e
示例11: _test_short_login
def _test_short_login(enabled):
ticket = Ticket(self.env)
ticket['reporter'] = 'joeuser'
ticket['summary'] = 'This is a summary'
ticket.insert()
# Be sure that at least one email address is valid, so that we
# send a notification even if other addresses are not valid
self.env.config.set('notification', 'smtp_always_cc',
'[email protected]')
if enabled:
self.env.config.set('notification', 'use_short_addr', 'true')
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
# Msg should not have a 'To' header
if not enabled:
self.failIf('To' in headers)
else:
tolist = [addr.strip() for addr in headers['To'].split(',')]
# Msg should have a 'Cc' field
self.failIf('Cc' not in headers)
cclist = [addr.strip() for addr in headers['Cc'].split(',')]
if enabled:
# Msg should be delivered to the reporter
self.failIf(ticket['reporter'] not in tolist)
else:
# Msg should not be delivered to joeuser
self.failIf(ticket['reporter'] in cclist)
# Msg should still be delivered to the always_cc list
self.failIf(self.env.config.get('notification',
'smtp_always_cc') not in cclist)
示例12: test_date
def test_date(self):
"""Date format compliance (RFC822)
we do not support 'military' format"""
date_str = r"^((?P<day>\w{3}),\s*)*(?P<dm>\d{2})\s+" \
r"(?P<month>\w{3})\s+(?P<year>200\d)\s+" \
r"(?P<hour>\d{2}):(?P<min>[0-5][0-9])" \
r"(:(?P<sec>[0-5][0-9]))*\s" \
r"((?P<tz>\w{2,3})|(?P<offset>[+\-]\d{4}))$"
date_re = re.compile(date_str)
# python time module does not detect incorrect time values
days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
months = ['Jan','Feb','Mar','Apr','May','Jun', \
'Jul','Aug','Sep','Oct','Nov','Dec']
tz = ['UT','GMT','EST','EDT','CST','CDT','MST','MDT''PST','PDT']
ticket = Ticket(self.env)
ticket['reporter'] = '"Joe User" <[email protected]>'
ticket['summary'] = 'This is a summary'
ticket.insert()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=True)
message = notifysuite.smtpd.get_message()
(headers, body) = parse_smtp_message(message)
self.failIf('Date' not in headers)
mo = date_re.match(headers['Date'])
self.failIf(not mo)
if mo.group('day'):
self.failIf(mo.group('day') not in days)
self.failIf(int(mo.group('dm')) not in range(1,32))
self.failIf(mo.group('month') not in months)
self.failIf(int(mo.group('hour')) not in range(0,24))
if mo.group('tz'):
self.failIf(mo.group('tz') not in tz)
示例13: create
def create(self, req, summary, description, attributes={}, notify=False):
""" Create a new ticket, returning the ticket ID.
PS: Borrowed from XmlRpcPlugin.
"""
if 'product' in attributes:
env = self.env.parent or self.env
if attributes['product']:
env = ProductEnvironment(env, attributes['product'])
else:
env = self.env
t = Ticket(env)
t['summary'] = summary
t['description'] = description
t['reporter'] = req.authname
for k, v in attributes.iteritems():
t[k] = v
t['status'] = 'new'
t['resolution'] = ''
t.insert()
if notify:
try:
tn = TicketNotifyEmail(env)
tn.notify(t, newticket=True)
except Exception, e:
self.log.exception("Failure sending notification on creation "
"of ticket #%s: %s" % (t.id, e))
示例14: 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
示例15: execute
def execute(self):
"""Execute the parsed commands"""
#print "Commands: %s" % self.commands
# Now parse the command in the ticket, and react accordingly
# Cannnot produce error messages, as the pre-commit-hook would have failed already
parser = CommitMessageCommandParser(self.env, self.changeset.message)
parsed_commands = parser.validate_and_parse_commit_message()
self.commands = dict()
for command, ticket_id, remaining_time in parsed_commands:
# REFACT: the parser should give the ids as ints already
ticket_id = int(ticket_id)
self.commands.setdefault(ticket_id, list())
self.commands.get(ticket_id).append(
self.findCommand(command, remaining=remaining_time[:-1]))
# Sort the ticket in reverse order by id, it will be most likely
# that a task is existing after a User Story has been created,
# in which case it will be possible to execute multiple command in
# a hierarchy. TODO: Check hierarchy, but very expensive
keys = self.commands.keys()
keys.sort(reverse=True)
for t_id, cmds in [(key, self.commands[key]) for key in keys]:
ticket = self.tm.get(tkt_id=t_id)
for cmd in cmds:
cmd(ticket)
self.tm.save(ticket, author=self.author, comment=self.message)
from trac.ticket.notification import TicketNotifyEmail
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=False, modtime=ticket.time_changed)
# We need to invalidate the chart cache here because some tickets may
# have been closed through commit comments. Unfortunately there is
# no way to access the shared memory right now, see #565
return True