Commit 6ad77e34 authored by Łukasz Nowak's avatar Łukasz Nowak

Pep8ification.

parent ea098efa
......@@ -40,6 +40,7 @@ ARCH_MAP = {
'x86_64': 'x86-64'
}
def readElfAsDict(f):
"""Reads ELF information from file"""
popen = subprocess.Popen(['readelf', '-d', f],
......@@ -54,9 +55,11 @@ def readElfAsDict(f):
if '(NEEDED)' in l:
library_list.append(l.split(':')[1].strip(' []'))
elif '(RPATH)' in l:
rpath_list = [q.rstrip('/') for q in l.split(':',1)[1].strip(' []').split(':')]
rpath_list = [q.rstrip('/') for q in l.split(':', 1)[1].strip(' []'
).split(':')]
elif '(RUNPATH)' in l:
runpath_list = [q.rstrip('/') for q in l.split(':',1)[1].strip(' []').split(':')]
runpath_list = [q.rstrip('/') for q in l.split(':', 1)[1].strip(' []'
).split(':')]
if len(runpath_list) == 0:
runpath_list = rpath_list
elif len(rpath_list) != 0 and runpath_list != rpath_list:
......@@ -66,6 +69,7 @@ def readElfAsDict(f):
runpath_list=sorted(runpath_list)
)
def call(*args, **kwargs):
"""Subprocess call with closed file descriptors and stdin"""
kwargs.update(
......@@ -79,21 +83,25 @@ def call(*args, **kwargs):
if popen.returncode != 0:
raise subprocess.CalledProcessError(popen.returncode, ' '.join(args[0]))
def calls(call_string, **kwargs):
"""Subprocesser caller which allows to pass arguments as string"""
call(call_string.split(), **kwargs)
def guessworkdir(path):
if len(os.listdir(path)) == 1:
return os.path.join(path, os.listdir(path)[0])
return path
def guessPlatform():
arch = uname()[-2]
target = ARCH_MAP.get(arch)
assert target, 'Unknown architecture'
return target
class Script:
"""Free script building system"""
def _checkPromisee(self, location):
......@@ -140,16 +148,16 @@ class Script:
else:
elf_dict = readElfAsDict(os.path.join(location, path))
if sorted(link_list) != sorted(elf_dict['library_list']):
a('Promisee library list not met (wanted: %r, found: %r)'%(
a('Promisee library list not met (wanted: %r, found: %r)' % (
link_list, elf_dict['library_list']))
if sorted(rpath_list) != sorted(elf_dict['runpath_list']):
a('Promisee rpath list not met (wanted: %r, found: %r)'%(
a('Promisee rpath list not met (wanted: %r, found: %r)' % (
rpath_list, elf_dict['runpath_list']))
else:
raise zc.buildout.UserError('Unknown promisee %r' % promisee)
if len(promisee_problem_list):
raise zc.buildout.UserError('Promisee not met, found issues:\n %s' %
' '.join([q+'\n' for q in promisee_problem_list]))
' '.join([q + '\n' for q in promisee_problem_list]))
def download(self, url, md5sum):
download = zc.buildout.download.Download(self.buildout['buildout'],
......@@ -166,7 +174,7 @@ class Script:
def copyTree(self, origin, destination, ignore_dir_list=None):
"""Recursively Copy directory.
ignore_dir_list is a list of relative directories you want to exclude.
Example :
copytree("/from", "/to", ignore_dir_list=["a_private_dir"])
......@@ -180,17 +188,19 @@ class Script:
ignore_dir_list = []
try:
shutil.copytree(origin, destination,
ignore=lambda src,names:ignore_dir_list)
ignore=lambda src, names: ignore_dir_list)
except (shutil.Error, OSError) as error:
# Cleanup in case of failure
try:
shutil.rmtree(destination, ignore_errors=True)
except (shutil.Error, OSError), strerror:
self.logger.error("Error occurred when cleaning after error: %s", strerror)
self.logger.error("Error occurred when cleaning after error: %s",
strerror)
raise error
return True
script = 'raise NotImplementedError'
def __init__(self, buildout, name, options):
self.cleanup_dir_list = []
self.options = options
......@@ -204,7 +214,8 @@ class Script:
# cleanup some variables
for k in ['location', 'url', 'md5sum']:
self.options[k] = self.options.get(k, '').strip()
self.options['script'] = self.options.get('script', self.script) % self.options
self.options['script'] = self.options.get('script', self.script) % \
self.options
def getEnvironment(self):
# prepare cool dictionary
......@@ -214,7 +225,8 @@ class Script:
if not line:
continue
if not '=' in line:
raise zc.buildout.UserError('Line %r in environment is incorrect' % line)
raise zc.buildout.UserError('Line %r in environment is incorrect' %
line)
key, value = line.split('=')
key = key.strip()
......@@ -223,14 +235,14 @@ class Script:
raise zc.buildout.UserError('Key %r is repeated' % key)
wanted_env[key] = value
env = {}
for k,v in os.environ.iteritems():
for k, v in os.environ.iteritems():
change = wanted_env.pop(k, None)
if change is not None:
env[k] = change % os.environ
self.logger.info('Environment %r setup to %r' % (k, env[k]))
else:
env[k] =v
for k,v in wanted_env.iteritems():
env[k] = v
for k, v in wanted_env.iteritems():
self.logger.info('Environment %r added with %r' % (k, v))
env[k] = v
return env
......@@ -243,7 +255,8 @@ class Script:
self._checkPromisee(self.options['location'])
except Exception:
if os.path.exists(self.options['location']):
self.logger.info('Removing location %r because of error' % self.options['location'])
self.logger.info('Removing location %r because of error' %
self.options['location'])
shutil.rmtree(self.options['location'])
raise
finally:
......@@ -257,13 +270,16 @@ class Script:
def update(self):
pass
class Cmmi(Script):
"""Simple configure-make-make-insall compatible with hexagonit.recipe.cmmi
Compatibility on parameter level, without bug-to-bug, hack-to-hack"""
script = """
extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
url = self.download(self.options['url']
md5sum = self.options.get('md5sum')
extract_dir = self.extract(url, md5sum)
workdir = guessworkdir(extract_dir)
configure_command = ["./configure", "--prefix=%(location)s"]
configure_command.extend(%(configure-options)r.split())
......@@ -276,5 +292,6 @@ call(["make", "install"], cwd=workdir, env=env)
"""
def __init__(self, buildout, name, options):
options['configure-options'] = ' '.join(options.get('configure-options', '').strip().splitlines())
options['configure-options'] = ' '.join(options.get('configure-options',
'').strip().splitlines())
Script.__init__(self, buildout, name, options)
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