Commit 35f81f2e authored by Gary Poster's avatar Gary Poster

make the two built-in recipes use the new bool option conveniences

parent 67ffcdf5
......@@ -1068,6 +1068,7 @@ def _install_and_load(spec, group, entry, buildout):
group, entry, spec, v)
raise
class Options(UserDict.DictMixin):
def __init__(self, buildout, section, data):
......@@ -1277,31 +1278,32 @@ class Options(UserDict.DictMixin):
self.name)
return self._created
def get_bool(self, name, default=None, on_error=None):
def query_bool(self, name, default=None):
"""Given a name, return a boolean value for that name.
``default``, if given, should be 'true', 'false', or None. None
is the default, and means that there is no default for the
value: the call should raise a MissingOption error if the name
is not present.
``on_error``, if given, should be a callable that takes the name and
the found value.
``default``, if given, should be 'true', 'false', or None.
"""
if default is None:
value = self[name]
if default is not None:
value = self.setdefault(name, default=default)
else:
value = self.get(name, default=default)
value = self.get(name)
if value is None:
return value
return _convert_bool(name, value)
def get_bool(self, name):
"""Given a name, return a boolean value for that name.
"""
return _convert_bool(name, self[name])
def _convert_bool(name, value):
if value not in ('true', 'false'):
if on_error is None:
raise zc.buildout.UserError(
'Invalid value for %s option: %s' % (name, value))
else:
on_error(name, value)
else:
return value == 'true'
_spacey_nl = re.compile('[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
'|'
'^[ \t\r\f\v]+'
......
......@@ -35,23 +35,13 @@ class Base(ScriptBase):
'*')
self.allowed_eggs = tuple(name.strip() for name in value.split('\n'))
value = options.setdefault(
self.include_site_packages = options.query_bool(
'include-site-packages',
b_options.get('include-site-packages', 'false'))
if value not in ('true', 'false'):
raise zc.buildout.UserError(
"Invalid value for include-site-packages option: %s" %
(value,))
self.include_site_packages = (value == 'true')
default=b_options.get('include-site-packages', 'false'))
value = options.setdefault(
self.exec_sitecustomize = options.query_bool(
'exec-sitecustomize',
b_options.get('exec-sitecustomize', 'false'))
if value not in ('true', 'false'):
raise zc.buildout.UserError(
"Invalid value for exec-sitecustomize option: %s" %
(value,))
self.exec_sitecustomize = (value == 'true')
default=b_options.get('exec-sitecustomize', 'false'))
class Interpreter(Base):
......
......@@ -52,9 +52,6 @@ class Eggs(object):
options['develop-eggs-directory'] = b_options['develop-eggs-directory']
options['_d'] = options['develop-eggs-directory'] # backward compat.
# verify that this is None, 'true' or 'false'
get_bool(options, 'unzip')
python = options.setdefault('python', b_options['python'])
options['executable'] = buildout[python]['executable']
......@@ -84,7 +81,7 @@ class Eggs(object):
else:
kw = {}
if 'unzip' in options:
kw['always_unzip'] = get_bool(options, 'unzip')
kw['always_unzip'] = options.query_bool('unzip', None)
ws = zc.buildout.easy_install.install(
distributions, options['eggs-directory'],
links=self.links,
......@@ -159,7 +156,7 @@ class ScriptBase(Eggs):
raise zc.buildout.UserError("Invalid entry point")
reqs.append(parsed.groups())
if get_bool(options, 'dependent-scripts'):
if options.query_bool('dependent-scripts', 'false'):
# Generate scripts for all packages in the working set,
# except setuptools.
reqs = list(reqs)
......@@ -192,17 +189,4 @@ class Scripts(ScriptBase):
relative_paths=self._relative_paths
)
def get_bool(options, name, default=False):
value = options.get(name)
if not value:
return default
if value == 'true':
return True
elif value == 'false':
return False
else:
raise zc.buildout.UserError(
"Invalid value for %s option: %s" % (name, value))
Egg = Scripts
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment