Further magic reduction in ubu_email

This commit is contained in:
Stefano Rivera 2010-12-21 00:18:47 +02:00
parent 0a272cab3f
commit 7229c63dc2

View File

@ -118,28 +118,24 @@ def ubu_email(name=None, email=None, export=True):
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:
export = False export = False
for var, target in ( for var, target in (('UBUMAIL', 'email'),
('UBUMAIL', 'name'),
('UBUMAIL', 'email'),
('DEBFULLNAME', 'name'), ('DEBFULLNAME', 'name'),
('DEBEMAIL', 'name'),
('DEBEMAIL', '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:
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 not name:
if target == 'name': name = m.group(1)
name = m.group(1) if not email:
elif target == 'email': email = m.group(2)
email = m.group(2) elif target == 'name' and not name:
elif target == 'email':
email = os.environ[var].strip()
elif var.endswith('NAME') and target == 'name':
name = os.environ[var].strip() name = os.environ[var].strip()
elif target == 'email' and not email:
email = os.environ[var].strip()
if not name: if not name:
gecos_name = pwd.getpwuid(os.getuid())[4].split(',')[0].strip() gecos_name = pwd.getpwuid(os.getuid())[4].split(',')[0].strip()