本文整理汇总了Python中mercurial.util.email函数的典型用法代码示例。如果您正苦于以下问题:Python email函数的具体用法?Python email怎么用?Python email使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了email函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_data_authors
def fetch_data_authors(ctx, stat_maker, options):
localstat = stat_maker(ctx, options)
# data is dictionnary mapping an author name to the data for
# this author
email = util.email(ctx.user())
email = options.amap.get(email, email) # alias remap
yield email, localstat
示例2: fetch_data_authors
def fetch_data_authors(ctx):
# data is a dictionnary mapping an author name to the data for
# this author
user = ctx.user()
email = util.email(user)
name = person(user)
yield name
示例3: update
def update(self, bugid, ctx):
'''update bugzilla bug with reference to changeset.'''
def webroot(root):
'''strip leading prefix of repo root and turn into
url-safe path.'''
count = int(self.ui.config('bugzilla', 'strip', 0))
root = util.pconvert(root)
while count > 0:
c = root.find('/')
if c == -1:
break
root = root[c+1:]
count -= 1
return root
mapfile = self.ui.config('bugzilla', 'style')
tmpl = self.ui.config('bugzilla', 'template')
t = cmdutil.changeset_templater(self.ui, self.repo,
False, None, mapfile, False)
if not mapfile and not tmpl:
tmpl = _('changeset {node|short} in repo {root} refers '
'to bug {bug}.\ndetails:\n\t{desc|tabindent}')
if tmpl:
tmpl = templater.parsestring(tmpl, quoted=False)
t.use_template(tmpl)
self.ui.pushbuffer()
t.show(ctx, changes=ctx.changeset(),
bug=str(bugid),
hgweb=self.ui.config('web', 'baseurl'),
root=self.repo.root,
webroot=webroot(self.repo.root))
data = self.ui.popbuffer()
self.add_comment(bugid, data, util.email(ctx.user()))
示例4: fixup_user
def fixup_user(user,authors):
user=user.strip("\"")
if "<<>>" in user:
user = user.replace("<<>>", "")
if "<<" in user:
user = user.replace("<<", "<")
if authors!=None:
# if we have an authors table, try to get mapping
# by defaulting to the current value of 'user'
user=authors.get(user,user)
name,mail,m='','',user_re.match(user)
if m==None:
# if we don't have 'Name <mail>' syntax, extract name
# and mail from hg helpers. this seems to work pretty well.
# if email doesn't contain @, replace it with [email protected]
name=templatefilters.person(user)
mail='<%s>' % util.email(user)
if '@' not in mail:
mail = '<[email protected]>'
else:
# if we have 'Name <mail>' syntax, everything is fine :)
name,mail=m.group(1),m.group(2)
# remove any silly quoting from username
m2=user_clean_re.match(name)
if m2!=None:
name=m2.group(1)
return '%s %s' % (name,mail)
示例5: send
def send(self, ctx, count, data):
'''send message.'''
p = email.Parser.Parser()
msg = p.parsestr(data)
# store sender and subject
sender, subject = msg['From'], msg['Subject']
del msg['From'], msg['Subject']
# store remaining headers
headers = msg.items()
# create fresh mime message from msg body
text = msg.get_payload()
# for notification prefer readability over data precision
msg = mail.mimeencode(self.ui, text, self.charsets, self.test)
# reinstate custom headers
for k, v in headers:
msg[k] = v
msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
# try to make subject line exist and be useful
if not subject:
if count > 1:
subject = _('%s: %d new changesets') % (self.root, count)
else:
s = ctx.description().lstrip().split('\n', 1)[0].rstrip()
subject = '%s: %s' % (self.root, s)
maxsubject = int(self.ui.config('notify', 'maxsubject', 67))
if maxsubject and len(subject) > maxsubject:
subject = subject[:maxsubject-3] + '...'
msg['Subject'] = mail.headencode(self.ui, subject,
self.charsets, self.test)
# try to make message have proper sender
if not sender:
sender = self.ui.config('email', 'from') or self.ui.username()
if '@' not in sender or '@localhost' in sender:
sender = self.fixmail(sender)
msg['From'] = mail.addressencode(self.ui, sender,
self.charsets, self.test)
msg['X-Hg-Notification'] = 'changeset %s' % ctx
if not msg['Message-Id']:
msg['Message-Id'] = ('<hg.%s.%s.%[email protected]%s>' %
(ctx, int(time.time()),
hash(self.repo.root), socket.getfqdn()))
msg['To'] = ', '.join(self.subs)
msgtext = msg.as_string(0)
if self.test:
self.ui.write(msgtext)
if not msgtext.endswith('\n'):
self.ui.write('\n')
else:
self.ui.status(_('notify: sending %d subscribers %d changes\n') %
(len(self.subs), count))
mail.sendmail(self.ui, util.email(msg['From']),
self.subs, msgtext)
示例6: send
def send(self, node, count, data):
'''send message.'''
p = email.Parser.Parser()
msg = p.parsestr(data)
def fix_subject():
'''try to make subject line exist and be useful.'''
subject = msg['Subject']
if not subject:
if count > 1:
subject = _('%s: %d new changesets') % (self.root, count)
else:
changes = self.repo.changelog.read(node)
s = changes[4].lstrip().split('\n', 1)[0].rstrip()
subject = '%s: %s' % (self.root, s)
maxsubject = int(self.ui.config('notify', 'maxsubject', 67))
if maxsubject and len(subject) > maxsubject:
subject = subject[:maxsubject-3] + '...'
del msg['Subject']
msg['Subject'] = subject
def fix_sender():
'''try to make message have proper sender.'''
sender = msg['From']
if not sender:
sender = self.ui.config('email', 'from') or self.ui.username()
if '@' not in sender or '@localhost' in sender:
sender = self.fixmail(sender)
del msg['From']
msg['From'] = sender
msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
fix_subject()
fix_sender()
msg['X-Hg-Notification'] = 'changeset ' + short(node)
if not msg['Message-Id']:
msg['Message-Id'] = ('<hg.%s.%s.%[email protected]%s>' %
(short(node), int(time.time()),
hash(self.repo.root), socket.getfqdn()))
msg['To'] = ', '.join(self.subs)
msgtext = msg.as_string(0)
if self.ui.configbool('notify', 'test', True):
self.ui.write(msgtext)
if not msgtext.endswith('\n'):
self.ui.write('\n')
else:
self.ui.status(_('notify: sending %d subscribers %d changes\n') %
(len(self.subs), count))
mail.sendmail(self.ui, util.email(msg['From']),
self.subs, msgtext)
示例7: fixmail
def fixmail(self, addr):
'''try to clean up email addresses.'''
addr = util.email(addr.strip())
if self.domain:
a = addr.find('@localhost')
if a != -1:
addr = addr[:a]
if '@' not in addr:
return addr + '@' + self.domain
return addr
示例8: sendemail
def sendemail(self, address, data):
p = email.Parser.Parser()
msg = p.parsestr(data)
msg["Date"] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
msg["To"] = address
msg["From"] = self.emailfrom
msg["Subject"] = "DeliverXML"
msg["Content-type"] = "text/xml"
msgtext = msg.as_string()
self.ui.status(_("hgcia: sending update to %s\n") % address)
mail.sendmail(self.ui, util.email(self.emailfrom), [address], msgtext)
示例9: __gather
def __gather(ui, repo, node1, node2):
def dirtywork(f, mmap1, mmap2):
lines = 0
to = mmap1 and repo.file(f).read(mmap1[f]) or None
tn = mmap2 and repo.file(f).read(mmap2[f]) or None
diff = mdiff.unidiff(to, "", tn, "", f, f).split("\n")
for line in diff:
if not line:
continue # skip EOF
if line.startswith(" "):
continue # context line
if line.startswith("--- ") or line.startswith("+++ "):
continue # begining of diff
if line.startswith("@@ "):
continue # info line
# changed lines
lines += 1
return lines
##
lines = 0
changes = repo.status(node1, node2, None, util.always)[:5]
modified, added, removed, deleted, unknown = changes
who = repo.changelog.read(node2)[1]
who = util.email(who) # get the email of the person
mmap1 = repo.manifest.read(repo.changelog.read(node1)[0])
mmap2 = repo.manifest.read(repo.changelog.read(node2)[0])
for f in modified:
lines += dirtywork(f, mmap1, mmap2)
for f in added:
lines += dirtywork(f, None, mmap2)
for f in removed:
lines += dirtywork(f, mmap1, None)
for f in deleted:
lines += dirtywork(f, mmap1, mmap2)
for f in unknown:
lines += dirtywork(f, mmap1, mmap2)
return (who, lines)
示例10: collect_data
def collect_data(cl,options):
if options.split=='none':
fetch_data = fetch_data_any
else:
fetch_data = globals()['fetch_data_' + options.split]
stat_maker = nostat
if options.uselines:
stat_maker = diffstat
# starting with mercurial 1.1, this could be simplified by iterating in cl directly
data = {}
for i in xrange(options.length):
node = cl.read(cl.node(i))
# Check whether the number of changed files == 0
if options.skipmerges and len(node[3]) == 0:
continue # Skip merges
# find out date and filter
date = datetime.fromtimestamp(node[2][0])
if options.datemin!=None and date<options.datemin:
continue
if options.datemax!=None and date>options.datemax:
continue
# find out who this is
who = node[1]
email = util.email(who)
if email in options.exclude:
continue
ctx = options.repo.changectx(i)
for k, v in fetch_data(ctx, stat_maker, options):
if not data.has_key(k):
data[k] = {}
data[k][date] = sum(v)
# post_collect_data
titlemap = {}
if options.split=='authors':
for who in data.keys():
email = util.email(who)
titlemap[email] = person(who)
options.titlemap = titlemap
return data
示例11: sendemail
def sendemail(self, address, data):
p = email.Parser.Parser()
msg = p.parsestr(data)
msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
msg['To'] = address
msg['From'] = self.emailfrom
msg['Subject'] = 'DeliverXML'
msg['Content-type'] = 'text/xml'
msgtext = msg.as_string()
self.ui.status(_('hgcia: sending update to %s\n') % address)
mail.sendmail(self.ui, util.email(self.emailfrom),
[address], msgtext)
示例12: hook
def hook(ui, repo, hooktype, node=None, **kwargs):
'''add comment to bugzilla for each changeset that refers to a
bugzilla bug id. only add a comment once per bug, so same change
seen multiple times does not fill bug with duplicate data.'''
if node is None:
raise util.Abort(_('hook type %s does not pass a changeset id') %
hooktype)
try:
bz = bugzilla(ui, repo)
ctx = repo[node]
bugs = bz.find_bugs(ctx)
if bugs:
for bug in bugs:
bz.update(bug, bugs[bug], ctx)
bz.notify(bugs, util.email(ctx.user()))
except Exception, e:
raise util.Abort(_('Bugzilla error: %s') % e)
示例13: collect_data
def collect_data(cl,options):
data = {}
namemap = {}
if not options.split:
data["Overall activity"] = {}
localactivity = 1
# starting with mercurial 1.1, this could be simplified by iterating in cl directly
for i in xrange(options.length):
node = cl.read(cl.node(i))
# Check whether the number of changed files == 0
if options.skipmerges and len(node[3]) == 0:
continue # Skip merges
# find out date and filter
date = datetime.datetime.fromtimestamp(node[2][0])
if options.datemin!=None and date<options.datemin:
continue
if options.datemax!=None and date>options.datemax:
continue
# find out who this is
who = node[1]
email = util.email(who)
namemap[email] = person(who)
if email in options.exclude:
continue
if options.uselines:
localactivity = changedlines(options.repo, i)
if options.split:
# data is dictionnary mapping an author name to the data for
# this author
email = options.amap.get(email, email) # alias remap
if not data.has_key(email):
data[email] = {}
data[email][date] = localactivity
else:
# data only contains one entry for the global graphic
data["Overall activity"][date] = localactivity
options.namemap = namemap
return data
示例14: unlock
def unlock(ui, repo, *pats, **opts):
"""
Release Lock:
$ hg unlock [-f] [-v] <file ...>
If no file specified, unlock would try to relaes all availble
locks.
-f Force unlock. Allows you to break others locks. Owner will
be notified about this.
-v Will display a bit more information then usual.
Other options are available only for hook execution handling.
"""
lockFile = repo.root + pathSep + ".hg" + pathSep + "locked.files"
user = ui.username()
ui.note("repository: %s\n" % repo.root)
ui.note("lockfile: %s\n" % lockFile)
ui.note("user name: %s\n\n" % user)
filesList=list()
# Identify whether function is called as a hook,
# and if so, change the command and reexecutei it.
if 'hooktype' in opts:
cmdline = list()
cmdline = opts['args'].split()
cmdline[0] = 'unlock'
# Fixing problems around changed dispatcher (since v1.9)
if hasattr(dispatch, 'request'):
return(dispatch.dispatch(dispatch.request(cmdline)))
else:
return(dispatch.dispatch(cmdline))
#Calculate file path in repository
if pats:
for file in pats:
if not os.path.exists(file): # file defined as path in repo (via hook call)
if file in repo.dirstate:
filesList.append(file)
else:
filesList.append(PathInRepo(repo.root, file))
# Load stored locking data
lockedFilesList = LoadData(lockFile)
# If files are not specified
# try to release all available locks
if not pats:
filesList = lockedFilesList.keys()
err = 0
for file in filesList:
ui.note("checking: %s\n" % file)
if file in lockedFilesList:
# UnLock
if not lockedFilesList[file][UserName] == user:
# Force unlock and send email to lock owner
if opts['force']:
# Email format: RFC 2822
# example: "Vladimir Legeza <[email protected]>"
from mercurial import mail
sendFrom = util.email(user)
sendTo = [util.email(lockedFilesList[file][UserName])]
message = "The lock you have set on '%s' file was removed by %s." % \
(file, lockedFilesList[file][UserName])
ui.note("sending email to: %s\n" % sendTo)
mail.sendmail(ui, sendFrom, sendTo, message)
ui.note("unlocking: %s\n" % file)
lockedFilesList.pop(file)
else:
err += 1
ui.warn("%s - locked by %s.\n" % (file, lockedFilesList[file][UserName]))
else:
ui.note("unlocking: %s\n" % file)
lockedFilesList.pop(file)
if err:
raise util.Abort(i18n._("Lock ownership violation."))
# Save changes
StoreData(lockFile, lockedFilesList)
示例15: hook
root=self.repo.root,
webroot=webroot(self.repo.root))
data = self.ui.popbuffer()
self.add_comment(bugid, data, util.email(ctx.user()))
def hook(ui, repo, hooktype, node=None, **kwargs):
'''add comment to bugzilla for each changeset that refers to a
bugzilla bug id. only add a comment once per bug, so same change
seen multiple times does not fill bug with duplicate data.'''
try:
import MySQLdb as mysql
global MySQLdb
MySQLdb = mysql
except ImportError, err:
raise util.Abort(_('python mysql support not available: %s') % err)
if node is None:
raise util.Abort(_('hook type %s does not pass a changeset id') %
hooktype)
try:
bz = bugzilla(ui, repo)
ctx = repo[node]
ids = bz.find_bug_ids(ctx)
if ids:
for id in ids:
bz.update(id, ctx)
bz.notify(ids, util.email(ctx.user()))
except MySQLdb.MySQLError, err:
raise util.Abort(_('database error: %s') % err[1])