mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-06 14:31:30 +00:00
Tone down ubu_email magic
This commit is contained in:
parent
b038e247d5
commit
2a1a48ae56
@ -95,33 +95,21 @@ def ubu_email(name=None, email=None, export=True):
|
|||||||
"""Find the developer's Ubuntu e-mail address, and export it in
|
"""Find the developer's Ubuntu e-mail address, and export it in
|
||||||
DEBFULLNAME, DEBEMAIL if necessary (and export isn't False).
|
DEBFULLNAME, DEBEMAIL if necessary (and export isn't False).
|
||||||
|
|
||||||
e-mail Priority: arguments, UBUMAIL, DEBEMAIL, DEBFULLNAME, user@mailname
|
e-mail Priority: arguments, UBUMAIL, DEBEMAIL, user@mailname
|
||||||
name Priority: arguments, UBUMAIL, DEBFULLNAME, DEBEMAIL, NAME, /etc/passwd
|
name Priority: arguments, UBUMAIL, DEBFULLNAME, DEBEMAIL, NAME, /etc/passwd
|
||||||
|
|
||||||
Name and email are only exported if provided as arguments or found in
|
Name and email are only exported if provided as arguments or found in
|
||||||
UBUMAIL. Otherwise, wrapped devscripts scripts can be expected to determine
|
UBUMAIL. Otherwise, wrapped devscripts scripts can be expected to determine
|
||||||
the values themselves.
|
the values themselves.
|
||||||
|
|
||||||
Return email, name.
|
Return name, email.
|
||||||
"""
|
"""
|
||||||
name_email_re = re.compile(r'^\s*(.+?)\s*<(.+@.+)>\s*$')
|
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:
|
if email:
|
||||||
m = name_email_re.match(email)
|
m = name_email_re.match(email)
|
||||||
if m:
|
if m and not name:
|
||||||
if not name:
|
name = m.group(1)
|
||||||
name = m.group(1)
|
|
||||||
email = m.group(2)
|
email = m.group(2)
|
||||||
|
|
||||||
if export and not name and not email and 'UBUMAIL' not in os.environ:
|
if export and not name and not email and 'UBUMAIL' not in os.environ:
|
||||||
@ -130,23 +118,23 @@ def ubu_email(name=None, email=None, export=True):
|
|||||||
for var, target in (
|
for var, target in (
|
||||||
('UBUMAIL', 'name'),
|
('UBUMAIL', 'name'),
|
||||||
('UBUMAIL', 'email'),
|
('UBUMAIL', 'email'),
|
||||||
('DEBEMAIL', 'email'),
|
|
||||||
('DEBFULLNAME', 'name'),
|
('DEBFULLNAME', 'name'),
|
||||||
('DEBEMAIL', 'name'),
|
('DEBEMAIL', 'name'),
|
||||||
('DEBFULLNAME', 'email'),
|
('DEBEMAIL', 'email'),
|
||||||
('NAME', 'name'),
|
('NAME', 'name'),
|
||||||
):
|
):
|
||||||
if name and email:
|
if name and email:
|
||||||
break
|
break
|
||||||
if var in os.environ and not locals()[target]:
|
if var in os.environ and not locals()[target]:
|
||||||
m = name_email_re.match(os.environ[var])
|
if var.endswith('MAIL'):
|
||||||
if m:
|
m = name_email_re.match(os.environ[var])
|
||||||
if target == 'name':
|
if m:
|
||||||
name = m.group(1)
|
if target == 'name':
|
||||||
|
name = m.group(1)
|
||||||
|
elif target == 'email':
|
||||||
|
email = m.group(2)
|
||||||
elif target == 'email':
|
elif target == 'email':
|
||||||
email = m.group(2)
|
email = os.environ[var].strip()
|
||||||
elif var.endswith('MAIL') and target == 'email':
|
|
||||||
email = os.environ[var].strip()
|
|
||||||
elif var.endswith('NAME') and target == 'name':
|
elif var.endswith('NAME') and target == 'name':
|
||||||
name = os.environ[var].strip()
|
name = os.environ[var].strip()
|
||||||
|
|
||||||
|
@ -179,13 +179,6 @@ class UbuEmailTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(os.environ['DEBFULLNAME'], name)
|
self.assertEqual(os.environ['DEBFULLNAME'], name)
|
||||||
self.assertEqual(os.environ['DEBEMAIL'], email)
|
self.assertEqual(os.environ['DEBEMAIL'], email)
|
||||||
|
|
||||||
def test_debfullname_with_email(self):
|
|
||||||
name = 'Joe Developer'
|
|
||||||
email = 'joe@example.net'
|
|
||||||
os.environ['DEBFULLNAME'] = orig = '%s <%s>' % (name, email)
|
|
||||||
self.assertEqual(ubu_email(), (name, email))
|
|
||||||
self.assertEqual(os.environ['DEBFULLNAME'], orig)
|
|
||||||
|
|
||||||
def test_debemail_with_name(self):
|
def test_debemail_with_name(self):
|
||||||
name = 'Joe Developer'
|
name = 'Joe Developer'
|
||||||
email = 'joe@example.net'
|
email = 'joe@example.net'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user