Tone down ubu_email magic

This commit is contained in:
Stefano Rivera 2010-12-20 23:56:54 +02:00
parent b038e247d5
commit 2a1a48ae56
2 changed files with 13 additions and 32 deletions

View File

@ -95,32 +95,20 @@ 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)
@ -130,22 +118,22 @@ 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]:
if var.endswith('MAIL'):
m = name_email_re.match(os.environ[var]) m = name_email_re.match(os.environ[var])
if m: if m:
if target == 'name': if target == 'name':
name = m.group(1) name = m.group(1)
elif target == 'email': elif target == 'email':
email = m.group(2) email = m.group(2)
elif var.endswith('MAIL') and target == 'email': elif target == 'email':
email = os.environ[var].strip() 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()

View File

@ -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'