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() self.buildout_prefix = ''
if prefix == '': prefix = options.get('prefix')
prefix = self.buildout_prefix = buildout['buildout'].get('prefix', '').strip() if not prefix:
if 'cygwin' != sys.platform: prefix = buildout['buildout'].get('prefix')
self.buildout_prefix = '' if prefix and 'cygwin' == sys.platform:
else: self.buildout_prefix = prefix
self.buildout_prefix = '' options['prefix'] = prefix or location
options['prefix'] = prefix or location
options['url'] = options.get('url', '').strip() url = options.get('url')
options['path'] = options.get('path', '').strip() path = options.get('path')
options['promises'] = options.get('promises', '') if url:
options['strip-top-level-dir'] = options.get('strip-top-level-dir', 'false').strip() if path:
raise UserError('You must provide either "url" or "path".')
if options['url'] and options['path']:
raise UserError('You must use either "url" or "path", not both!')
if not (options['url'] or options['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