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