Commit d6fe5d64 authored by Julien Muchembled's avatar Julien Muchembled

Clean up reading of options

In particular, buildout already strips values.
parent 509ee4a0
...@@ -44,10 +44,7 @@ class Recipe(object): ...@@ -44,10 +44,7 @@ class Recipe(object):
platform_options = buildout.get( platform_options = buildout.get(
"%s:%s:%s" % (name, sys.platform, self.get_machine()), "%s:%s:%s" % (name, sys.platform, self.get_machine()),
buildout.get("%s:%s" % (name, sys.platform))) buildout.get("%s:%s" % (name, sys.platform)))
if platform_options is None: if platform_options is not None:
self.original_options = options
else:
self.original_options = options.copy()
options.update(platform_options) options.update(platform_options)
environment_section = options.get('environment-section') environment_section = options.get('environment-section')
...@@ -92,28 +89,24 @@ class Recipe(object): ...@@ -92,28 +89,24 @@ class Recipe(object):
buildout['buildout']['parts-directory'], buildout['buildout']['parts-directory'],
self.name) self.name)
prefix = options.get('prefix', '').strip()
if prefix == '':
prefix = self.buildout_prefix = buildout['buildout'].get('prefix', '').strip()
if 'cygwin' != sys.platform:
self.buildout_prefix = ''
else:
self.buildout_prefix = '' self.buildout_prefix = ''
prefix = options.get('prefix')
if not prefix:
prefix = buildout['buildout'].get('prefix')
if prefix and 'cygwin' == sys.platform:
self.buildout_prefix = prefix
options['prefix'] = prefix or location options['prefix'] = prefix or location
options['url'] = options.get('url', '').strip()
options['path'] = options.get('path', '').strip()
options['promises'] = options.get('promises', '')
options['strip-top-level-dir'] = options.get('strip-top-level-dir', 'false').strip()
if options['url'] and options['path']: url = options.get('url')
raise UserError('You must use either "url" or "path", not both!') path = options.get('path')
if not (options['url'] or options['path']): if url:
if path:
raise UserError('You must provide either "url" or "path".') raise UserError('You must provide either "url" or "path".')
if options['url']:
options['compile-directory'] = os.path.join(location, '.build') options['compile-directory'] = os.path.join(location, '.build')
elif path:
options['compile-directory'] = path
else: else:
options['compile-directory'] = options['path'] raise UserError('You must use either "url" or "path", not both!')
for k, v in list(options.items()): for k, v in list(options.items()):
if '@@LOCATION@@' in v: if '@@LOCATION@@' in v:
...@@ -205,7 +198,7 @@ class Recipe(object): ...@@ -205,7 +198,7 @@ class Recipe(object):
def check_promises(self): def check_promises(self):
result = True result = True
for path in self.options['promises'].splitlines(): for path in self.options.get('promises', '').splitlines():
if path and not os.path.exists(path): if path and not os.path.exists(path):
result = False result = False
self.logger.warning('could not find promise %r', path) self.logger.warning('could not find promise %r', path)
...@@ -298,6 +291,7 @@ class Recipe(object): ...@@ -298,6 +291,7 @@ class Recipe(object):
log.info('[ENV] %s = %s', key, self.environ[key]) log.info('[ENV] %s = %s', key, self.environ[key])
current_dir = os.getcwd() current_dir = os.getcwd()
url = self.options.get('url')
compile_dir = self.options['compile-directory'] compile_dir = self.options['compile-directory']
location = self.options['location'] location = self.options['location']
# Clean the install directory if it already exists as it is # Clean the install directory if it already exists as it is
...@@ -308,13 +302,15 @@ class Recipe(object): ...@@ -308,13 +302,15 @@ class Recipe(object):
try: try:
os.makedirs(location) os.makedirs(location)
# Download the source using slapos.recipe.downloadunpacked # Download the source using slapos.recipe.downloadunpacked
if self.options['url']: if url:
os.mkdir(compile_dir) os.mkdir(compile_dir)
self.options.get('md5sum') # so that buildout does not complain "unused option md5sum" self.options.get('md5sum') # so that buildout does not complain "unused option md5sum"
opt = self.options.copy() opt = self.options.copy()
opt['destination'] = compile_dir opt['destination'] = compile_dir
# no need to shared build for compile dir # no need to shared build for compile dir
opt['shared'] = 'false' opt['shared'] = 'false'
opt['strip-top-level-dir'] = opt.get(
'strip-top-level-dir') or 'false'
downloadunpacked.Recipe(self.buildout, self.name, opt).install() downloadunpacked.Recipe(self.buildout, self.name, opt).install()
else: else:
log.info('Using local source directory: %s', compile_dir) log.info('Using local source directory: %s', compile_dir)
...@@ -408,7 +404,7 @@ echo %s ...@@ -408,7 +404,7 @@ echo %s
finally: finally:
os.chdir(current_dir) os.chdir(current_dir)
if self.options['url']: if url:
if (self.options.get('keep-compile-dir') or if (self.options.get('keep-compile-dir') or
self.buildout['buildout'].get('keep-compile-dir') or self.buildout['buildout'].get('keep-compile-dir') or
'').lower() not in ('true', 'yes', '1', 'on'): '').lower() not in ('true', 'yes', '1', 'on'):
......
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