- Support this in many u-d-t scripts, and update manpages.

- Deprecate old configuration environment variables.
This commit is contained in:
Stefano Rivera 2010-12-22 00:07:48 +02:00
parent 86facf23c2
commit c43e9775e0
3 changed files with 24 additions and 7 deletions

4
debian/changelog vendored
View File

@ -11,6 +11,8 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low
* Support reading configuration variables from devscripts configuration
files. (LP: #681693)
- Added ubuntu-dev-tools.5
- Support this in many u-d-t scripts, and update manpages.
- Deprecate old configuration environment variables.
* Support the combined "Name <email>" format in UBUMAIL, DEBFULLNAME, and
DEBEMAIL. (LP: #665202)
* Add the beginnings of a test suite. (LP: #690386)
@ -22,7 +24,7 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low
* ubuntutools/lp/lpapicache.py: Allow easier selection of 'staging' as LP
instance to use (lp: #693060).
-- Michael Bienia <geser@ubuntu.com> Tue, 21 Dec 2010 19:14:57 +0100
-- Stefano Rivera <stefanor@ubuntu.com> Wed, 22 Dec 2010 00:06:29 +0200
ubuntu-dev-tools (0.108) experimental; urgency=low

View File

@ -21,8 +21,7 @@ import pwd
import re
import shlex
import socket
import StringIO
import sys
from sys import argv, stderr
class UDTConfig(object):
"""Ubuntu Dev Tools configuration file (devscripts config file) and
@ -43,7 +42,7 @@ class UDTConfig(object):
def __init__(self, no_conf=False, prefix=None):
self.no_conf = no_conf
if prefix is None:
prefix = os.path.basename(sys.argv[0]).upper().replace('-', '_')
prefix = os.path.basename(argv[0]).upper().replace('-', '_')
self.prefix = prefix
if not no_conf:
self.config = self.parse_devscripts_config()
@ -60,10 +59,10 @@ class UDTConfig(object):
continue
for line in f:
parsed = shlex.split(line, comments=True)
if len(parsed) > 1 and not isinstance(f, StringIO.StringIO):
print >> sys.stderr, (
if len(parsed) > 1:
print >> stderr, (
"W: Cannot parse variable assignment in %s: %s"
% (f.name, line))
% (getattr(f, 'name', '<config>'), line))
if len(parsed) >= 1 and '=' in parsed[0]:
key, value = parsed[0].split('=', 1)
config[key] = value
@ -98,6 +97,10 @@ class UDTConfig(object):
value = value == 'yes'
else:
continue
if k in compat_keys:
print >> stderr, (
'W: Deprecated configuration variable: %s. '
'Replaced by %s.') % (k, key)
return value
return default

View File

@ -17,6 +17,7 @@
import os
import os.path
from StringIO import StringIO
from sys import stderr
import ubuntutools.config
from ubuntutools.config import UDTConfig, ubu_email
@ -42,10 +43,13 @@ def fake_open(filename, mode='r'):
class ConfigTestCase(unittest.TestCase):
def setUp(self):
ubuntutools.config.open = fake_open
ubuntutools.config.stderr = StringIO()
self.cleanEnvironment()
def tearDown(self):
del ubuntutools.config.open
self.assertEqual(ubuntutools.config.stderr.getvalue(), '')
ubuntutools.config.stderr = stderr
self.cleanEnvironment()
def cleanEnvironment(self):
@ -82,6 +86,10 @@ REPEAT=yes
'INHERIT': 'user',
'REPEAT': 'yes',
})
errs = ubuntutools.config.stderr.getvalue().strip()
ubuntutools.config.stderr = StringIO()
self.assertEqual(len(errs.splitlines()), 1)
self.assertRegexpMatches(errs, r'Cannot parse.*\bCOMMAND_EXECUTION=a')
def get_value(self, *args, **kwargs):
config = UDTConfig(prefix='TEST')
@ -117,6 +125,10 @@ REPEAT=yes
config_files['user'] = 'COMPATFOOBAR=bar'
self.assertEqual(self.get_value('QUX', compat_keys=['COMPATFOOBAR']),
'bar')
errs = ubuntutools.config.stderr.getvalue().strip()
ubuntutools.config.stderr = StringIO()
self.assertEqual(len(errs.splitlines()), 1)
self.assertRegexpMatches(errs, r'Deprecated.*\bCOMPATFOOBAR\b.*\bQUX\b')
def test_boolean(self):
config_files['user'] = "TEST_BOOLEAN=yes"