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): ...@@ -1068,6 +1068,7 @@ def _install_and_load(spec, group, entry, buildout):
group, entry, spec, v) group, entry, spec, v)
raise raise
class Options(UserDict.DictMixin): class Options(UserDict.DictMixin):
def __init__(self, buildout, section, data): def __init__(self, buildout, section, data):
...@@ -1277,30 +1278,31 @@ class Options(UserDict.DictMixin): ...@@ -1277,30 +1278,31 @@ class Options(UserDict.DictMixin):
self.name) self.name)
return self._created 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. """Given a name, return a boolean value for that name.
``default``, if given, should be 'true', 'false', or None. None ``default``, if given, should be 'true', 'false', or 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.
""" """
if default is None: if default is not None:
value = self[name] value = self.setdefault(name, default=default)
else:
value = self.get(name, default=default)
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: else:
return value == 'true' 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'):
raise zc.buildout.UserError(
'Invalid value for %s option: %s' % (name, value))
else:
return value == 'true'
_spacey_nl = re.compile('[ \t\r\f\v]*\n[ \t\r\f\v\n]*' _spacey_nl = re.compile('[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
'|' '|'
......
...@@ -35,23 +35,13 @@ class Base(ScriptBase): ...@@ -35,23 +35,13 @@ class Base(ScriptBase):
'*') '*')
self.allowed_eggs = tuple(name.strip() for name in value.split('\n')) 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', 'include-site-packages',
b_options.get('include-site-packages', 'false')) default=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')
value = options.setdefault( self.exec_sitecustomize = options.query_bool(
'exec-sitecustomize', 'exec-sitecustomize',
b_options.get('exec-sitecustomize', 'false')) default=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')
class Interpreter(Base): class Interpreter(Base):
......
...@@ -52,9 +52,6 @@ class Eggs(object): ...@@ -52,9 +52,6 @@ class Eggs(object):
options['develop-eggs-directory'] = b_options['develop-eggs-directory'] options['develop-eggs-directory'] = b_options['develop-eggs-directory']
options['_d'] = options['develop-eggs-directory'] # backward compat. 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']) python = options.setdefault('python', b_options['python'])
options['executable'] = buildout[python]['executable'] options['executable'] = buildout[python]['executable']
...@@ -84,7 +81,7 @@ class Eggs(object): ...@@ -84,7 +81,7 @@ class Eggs(object):
else: else:
kw = {} kw = {}
if 'unzip' in options: 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( ws = zc.buildout.easy_install.install(
distributions, options['eggs-directory'], distributions, options['eggs-directory'],
links=self.links, links=self.links,
...@@ -159,7 +156,7 @@ class ScriptBase(Eggs): ...@@ -159,7 +156,7 @@ class ScriptBase(Eggs):
raise zc.buildout.UserError("Invalid entry point") raise zc.buildout.UserError("Invalid entry point")
reqs.append(parsed.groups()) 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, # Generate scripts for all packages in the working set,
# except setuptools. # except setuptools.
reqs = list(reqs) reqs = list(reqs)
...@@ -192,17 +189,4 @@ class Scripts(ScriptBase): ...@@ -192,17 +189,4 @@ class Scripts(ScriptBase):
relative_paths=self._relative_paths 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 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