Commit 9ff1a5a3 authored by Julien Muchembled's avatar Julien Muchembled

default: clean up

parent d84cd397
...@@ -44,20 +44,10 @@ ARCH_MAP = { ...@@ -44,20 +44,10 @@ ARCH_MAP = {
'x86_64': 'x86-64' 'x86_64': 'x86-64'
} }
OS_MAP = {
'darwin': 'mac',
'linux2': 'linux'
#To be continued
}
def readElfAsDict(f): def readElfAsDict(f):
"""Reads ELF information from file""" """Reads ELF information from file"""
popen = subprocess.Popen(['readelf', '-d', f], result = subprocess.check_output(('readelf', '-d', f),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)[0]
result = popen.communicate()[0]
if popen.returncode != 0:
raise AssertionError(result)
library_list = [] library_list = []
rpath_list = [] rpath_list = []
runpath_list = [] runpath_list = []
...@@ -79,49 +69,25 @@ def readElfAsDict(f): ...@@ -79,49 +69,25 @@ def readElfAsDict(f):
runpath_list=sorted(runpath_list) runpath_list=sorted(runpath_list)
) )
def call(*args, **kwargs): def call(*args, **kwargs):
"""Subprocess call with closed file descriptors and stdin""" """Subprocess call with closed file descriptors and stdin"""
kwargs.update( kwargs.update(
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
close_fds=True) close_fds=True)
popen = subprocess.Popen(*args, **kwargs) popen = subprocess.Popen(*args, **kwargs)
popen.stdin.flush()
popen.stdin.close() popen.stdin.close()
popen.stdin = None popen.stdin = None
popen.communicate() popen.communicate()
if popen.returncode != 0: if popen.returncode != 0:
raise subprocess.CalledProcessError(popen.returncode, ' '.join(args[0])) raise subprocess.CalledProcessError(popen.returncode, ' '.join(args[0]))
def calls(call_string, **kwargs):
"""Subprocesser caller which allows to pass arguments as string"""
call(shlex.split(call_string), **kwargs)
def calli(*args, **kwargs):
"""Subprocesser call wich allow to pass stdin argument"""
popen = subprocess.Popen(*args, **kwargs)
popen.communicate()
if popen.returncode != 0:
raise subprocess.CalledProcessError(popen.returncode, ' '.join(args[0]))
def guessworkdir(path): def guessworkdir(path):
if len(os.listdir(path)) == 1: x = os.listdir(path)
return os.path.join(path, os.listdir(path)[0]) return os.path.join(path, *x) if len(x) == 1 else path
return path
def guessPlatform(): def guessPlatform():
arch = uname()[-2] return ARCH_MAP[uname()[-2]]
target = ARCH_MAP.get(arch)
assert target, 'Unknown architecture'
return target
def guessOperatingSystem():
platform = sys.platform
target = OS_MAP.get(platform)
assert target, 'Unknown architecture'
return target
TRUE_LIST = ('y', 'on', 'yes', 'true', '1') TRUE_LIST = ('y', 'on', 'yes', 'true', '1')
...@@ -217,15 +183,13 @@ class Script(EnvironMixin): ...@@ -217,15 +183,13 @@ class Script(EnvironMixin):
run_list.append(' '.join(command_list)) run_list.append(' '.join(command_list))
previous = p previous = p
self.logger.info('Running: %r' % ' | '.join(run_list)) self.logger.info('Running: %r' % ' | '.join(run_list))
subprocess_list.reverse() failed = []
[q[0].wait() for q in subprocess_list] for q in reversed(subprocess_list):
for q in subprocess_list: if q[0].wait():
if q[0].returncode != 0: failed.append(q[1])
raise zc.buildout.UserError('Failed while running command %r' % q[1]) if failed:
raise zc.buildout.UserError('Failed while running command:'
def failIfPathExists(self, path): + ''.join('\n ' + q for q in failed))
if os.path.lexists(path):
raise zc.buildout.UserError('Path %r exists, cannot continue' % path)
def copyTree(self, origin, destination, ignore_dir_list=None): def copyTree(self, origin, destination, ignore_dir_list=None):
"""Recursively Copy directory. """Recursively Copy directory.
...@@ -258,7 +222,6 @@ class Script(EnvironMixin): ...@@ -258,7 +222,6 @@ class Script(EnvironMixin):
lambda self: self.cleanup_list) lambda self: self.cleanup_list)
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
self.cleanup_list = []
self.options = options self.options = options
self.buildout = buildout self.buildout = buildout
self.name = name self.name = name
...@@ -296,6 +259,7 @@ class Script(EnvironMixin): ...@@ -296,6 +259,7 @@ class Script(EnvironMixin):
rmtree(location) rmtree(location)
# env is used in script exec'ed below # env is used in script exec'ed below
env = self.environ env = self.environ
self.cleanup_list = []
try: try:
exec(self.script) exec(self.script)
self._checkPromise('slapos_promise', location) self._checkPromise('slapos_promise', location)
...@@ -310,7 +274,7 @@ class Script(EnvironMixin): ...@@ -310,7 +274,7 @@ class Script(EnvironMixin):
else: else:
self.logger.debug('Removing %r', path) self.logger.debug('Removing %r', path)
rmtree(path) rmtree(path)
return [location] return location
def update(self): def update(self):
pass pass
...@@ -341,6 +305,7 @@ class Script(EnvironMixin): ...@@ -341,6 +305,7 @@ class Script(EnvironMixin):
if md5sum is not None and ' ' in md5sum: if md5sum is not None and ' ' in md5sum:
md5sum, patch_options = md5sum.split(' ', 1) md5sum, patch_options = md5sum.split(' ', 1)
patch_options = patch_options.split(' ') patch_options = patch_options.split(' ')
kwargs['stdin'] = open(self.download(patch, md5sum)) self.logger.info('Applying patch %r', patch)
self.logger.info('Applying patch %r' % patch) with open(self.download(patch, md5sum)) as stdin:
calli([patch_binary] + patch_options, **kwargs) subprocess.check_call([patch_binary] + patch_options,
stdin=stdin, **kwargs)
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