mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-06 14:31:30 +00:00
Actually configuration variables shouldn't come from the environment
This commit is contained in:
parent
baae70c001
commit
8b5cd3d045
@ -43,26 +43,31 @@ def get_devscripts_config():
|
|||||||
f.close()
|
f.close()
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def get_value(key, default=None, prefix=None, compat_keys=[]):
|
def get_value(key, default=None, prefix=None, compat_vars=[]):
|
||||||
"""Retrieve a value from the environment or configuration files.
|
"""Retrieve a value from a configuration file.
|
||||||
keys are prefixed with the script name + _, or prefix.
|
keys are prefixed with the script name + _, or prefix.
|
||||||
Historical variable names can be supplied via compat_keys, no prefix is
|
Historical *environment variable* names can be supplied via compat_keys, no
|
||||||
applied to them.
|
prefix is applied to them.
|
||||||
"""
|
"""
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
prefix = sys.argv[0].upper().replace('-', '_') + '_'
|
prefix = sys.argv[0].upper().replace('-', '_') + '_'
|
||||||
|
|
||||||
keys = [prefix + key, 'UBUNTUTOOLS_' + key] + compat_keys
|
config = get_devscripts_config()
|
||||||
|
for k in (prefix + key, 'UBUNTUTOOLS_' + key):
|
||||||
|
if k in config:
|
||||||
|
value = config[k]
|
||||||
|
if value in ('yes', 'no'):
|
||||||
|
value = value == 'yes'
|
||||||
|
return value
|
||||||
|
|
||||||
value = default
|
for k in compat_vars:
|
||||||
for store in (os.environ, get_devscripts_config()):
|
if k in os.environ:
|
||||||
for k in keys:
|
value = os.environ[k]
|
||||||
if k in store:
|
if value in ('yes', 'no'):
|
||||||
value = store[k]
|
value = value == 'yes'
|
||||||
if value in ('yes', 'no'):
|
return value
|
||||||
value = value == 'yes'
|
|
||||||
return value
|
return default
|
||||||
return value
|
|
||||||
|
|
||||||
def ubu_email(name=None, email=None, export=True):
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user