mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-16 01:21:07 +00:00
Support the combined "Name <email>" format in UBUMAIL, DEBFULLNAME, and
DEBEMAIL. (LP: #665202)
This commit is contained in:
parent
a335ef7949
commit
3a9ffe412c
4
debian/changelog
vendored
4
debian/changelog
vendored
@ -4,8 +4,10 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low
|
|||||||
(LP: #692003)
|
(LP: #692003)
|
||||||
* Support reading configuration variables from devscripts configuration
|
* Support reading configuration variables from devscripts configuration
|
||||||
files. (LP: #681693)
|
files. (LP: #681693)
|
||||||
|
* Support the combined "Name <email>" format in UBUMAIL, DEBFULLNAME, and
|
||||||
|
DEBEMAIL. (LP: #665202)
|
||||||
|
|
||||||
-- Stefano Rivera <stefanor@ubuntu.com> Sun, 19 Dec 2010 20:41:06 +0200
|
-- Stefano Rivera <stefanor@ubuntu.com> Sun, 19 Dec 2010 20:47:22 +0200
|
||||||
|
|
||||||
ubuntu-dev-tools (0.108) experimental; urgency=low
|
ubuntu-dev-tools (0.108) experimental; urgency=low
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import pwd
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ubuntutools.common import memoize_noargs
|
from ubuntutools.common import memoize_noargs
|
||||||
@ -59,3 +61,78 @@ def get_value(key, default=None, prefix=None, compat_keys=[]):
|
|||||||
value = value == 'yes'
|
value = value == 'yes'
|
||||||
return value
|
return value
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def ubu_email(name=None, email=None, export=True):
|
||||||
|
"""Find the developer's Ubuntu e-mail address, and export it in
|
||||||
|
DEBFULLNAME, DEBEMAIL if necessary (and export isn't False).
|
||||||
|
|
||||||
|
e-mail Priority: arguments, UBUMAIL, DEBEMAIL, DEBFULLNAME, user@mailname
|
||||||
|
name Priority: arguments, UBUMAIL, DEBFULLNAME, DEBEMAIL, NAME, /etc/passwd
|
||||||
|
|
||||||
|
Name and email are only exported if provided as arguments or found in
|
||||||
|
UBUMAIL. Otherwise, wrapped devscripts scripts can be expected to determine
|
||||||
|
the values themselves.
|
||||||
|
|
||||||
|
Return email, name.
|
||||||
|
"""
|
||||||
|
name_email_re = re.compile(r'^\s*(.+?)\s*<(.+@.+)>\s*$')
|
||||||
|
|
||||||
|
# First priority is to sanity-check command-line supplied values:
|
||||||
|
if name:
|
||||||
|
name = name.strip()
|
||||||
|
if email:
|
||||||
|
email = email.strip()
|
||||||
|
if name:
|
||||||
|
m = name_email_re.match(name)
|
||||||
|
if m:
|
||||||
|
name = m.group(1)
|
||||||
|
if not email:
|
||||||
|
email = m.group(2)
|
||||||
|
if email:
|
||||||
|
m = name_email_re.match(email)
|
||||||
|
if m:
|
||||||
|
if not name:
|
||||||
|
name = m.group(1)
|
||||||
|
email = m.group(2)
|
||||||
|
|
||||||
|
if export and not name and not email and 'UBUMAIL' not in os.environ:
|
||||||
|
export = False
|
||||||
|
|
||||||
|
for var, target in (
|
||||||
|
('UBUMAIL', 'name'),
|
||||||
|
('UBUMAIL', 'email'),
|
||||||
|
('DEBEMAIL', 'email'),
|
||||||
|
('DEBFULLNAME', 'name'),
|
||||||
|
('DEBEMAIL', 'name'),
|
||||||
|
('DEBFULLNAME', 'email'),
|
||||||
|
('NAME', 'name'),
|
||||||
|
):
|
||||||
|
if name and email:
|
||||||
|
break
|
||||||
|
if var in os.environ and not locals()[target]:
|
||||||
|
m = name_email_re.match(os.environ[var])
|
||||||
|
if m:
|
||||||
|
if target == 'name':
|
||||||
|
name = m.group(1)
|
||||||
|
elif target == 'email':
|
||||||
|
email = m.group(2)
|
||||||
|
elif var.endswith('MAIL') and target == 'email':
|
||||||
|
email = os.environ[var].strip()
|
||||||
|
elif var.endswith('NAME') and target == 'name':
|
||||||
|
name = os.environ[var].strip()
|
||||||
|
|
||||||
|
if not name:
|
||||||
|
gecos_name = pwd.getpwuid(os.getuid())[4].split(',')[0].strip()
|
||||||
|
if gecos_name:
|
||||||
|
name = gecos_name
|
||||||
|
|
||||||
|
if not email:
|
||||||
|
mailname = socket.getfqdn()
|
||||||
|
if os.path.isfile('/etc/mailname'):
|
||||||
|
mailname = open('/etc/mailname', 'r').read().strip()
|
||||||
|
email = pwd.getpwuid(os.getuid())[0] + '@' + mailname
|
||||||
|
|
||||||
|
if export:
|
||||||
|
os.environ['DEBFULLNAME'] = name
|
||||||
|
os.environ['DEBEMAIL'] = email
|
||||||
|
return name, email
|
||||||
|
Loading…
x
Reference in New Issue
Block a user