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