Commit 84a8ce94 authored by Julien Muchembled's avatar Julien Muchembled

default: 'script' renamed to 'install', new 'update', clean up globals/locals

parent 9ff1a5a3
...@@ -88,6 +88,8 @@ def guessworkdir(path): ...@@ -88,6 +88,8 @@ def guessworkdir(path):
def guessPlatform(): def guessPlatform():
return ARCH_MAP[uname()[-2]] return ARCH_MAP[uname()[-2]]
GLOBALS = (lambda *x: {x.__name__: x for x in x})(
call, guessPlatform, guessworkdir)
TRUE_LIST = ('y', 'on', 'yes', 'true', '1') TRUE_LIST = ('y', 'on', 'yes', 'true', '1')
...@@ -231,37 +233,45 @@ class Script(EnvironMixin): ...@@ -231,37 +233,45 @@ class Script(EnvironMixin):
except KeyError: except KeyError:
self.options['location'] = os.path.join( self.options['location'] = os.path.join(
buildout['buildout']['parts-directory'], self.name) buildout['buildout']['parts-directory'], self.name)
format = options.get('format', 'yes') in TRUE_LIST self._format = options.get('format', 'yes') in TRUE_LIST
init = options.get('init') missing = True
self.script = options.get('script') keys = 'init', 'install', 'update'
if self.script: for option in keys:
if format: script = options.get(option)
self.script = self.script % self.options setattr(self, '_' + option, script)
elif not init: if script:
raise zc.buildout.UserError('either init or script is required') missing = False
if missing:
raise zc.buildout.UserError(
'at least one of the following option is required: ' + ', '.join(keys))
if self.options.get('keep-on-error', '').strip().lower() in TRUE_LIST: if self.options.get('keep-on-error', '').strip().lower() in TRUE_LIST:
self.logger.debug('Keeping directories in case of errors') self.logger.debug('Keeping directories in case of errors')
self.keep_on_error = True self.keep_on_error = True
else: else:
self.keep_on_error = False self.keep_on_error = False
EnvironMixin.__init__(self, False) EnvironMixin.__init__(self, False)
if init: if self._init:
if format: self._exec(self._init)
init = init % options
exec(init, {'self': self, 'options': options, 'env': self.environ}) def _exec(self, script):
options = self.options
exec(script % options if self._format else script, dict(GLOBALS,
self=self,
options=options,
location=options['location'],
))
def install(self): def install(self):
if not self.script: if not self._install:
self.update()
return "" return ""
location = self.options['location'] location = self.options['location']
if os.path.lexists(location): if os.path.lexists(location):
self.logger.warning('Removing already existing path %r', location) self.logger.warning('Removing already existing path %r', location)
rmtree(location) rmtree(location)
# env is used in script exec'ed below
env = self.environ
self.cleanup_list = [] self.cleanup_list = []
try: try:
exec(self.script) self._exec(self._install)
self._checkPromise('slapos_promise', location) self._checkPromise('slapos_promise', location)
except: except:
self.cleanup_list.append(location) self.cleanup_list.append(location)
...@@ -277,7 +287,8 @@ class Script(EnvironMixin): ...@@ -277,7 +287,8 @@ class Script(EnvironMixin):
return location return location
def update(self): def update(self):
pass if self._update:
self._exec(self._update)
def applyPatchList(self, patch_string, patch_options=None, patch_binary=None, cwd=None): def applyPatchList(self, patch_string, patch_options=None, patch_binary=None, cwd=None):
if patch_string is not None: if patch_string is not None:
......
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