Add download and installation support for architecture dependant zip files

parent ecd30ac1
...@@ -74,6 +74,15 @@ Example buildout:: ...@@ -74,6 +74,15 @@ Example buildout::
slapos_promisee = slapos_promisee =
... ...
[architecturedependant]
recipe = slapos.cookbook:download
x86_url = http://host/path/zipball_x86.zip
x86_md5sum = 9631070eac74f92a812d4785a84d1b4e
x86-64_url = http://host/path/zipball_x64.zip
x86-64_md5sum = 9631070eac74f92a812d4785a84d1b4e
slapos_promisee =
...
TODO: TODO:
* add linking suport, buildout definition: * add linking suport, buildout definition:
......
...@@ -28,6 +28,7 @@ setup(name=name, ...@@ -28,6 +28,7 @@ setup(name=name,
entry_points={ entry_points={
'zc.buildout': [ 'zc.buildout': [
'default = slapos.recipe.build:Script', 'default = slapos.recipe.build:Script',
'cmmi = slapos.recipe.build:Cmmi' 'cmmi = slapos.recipe.build:Cmmi',
'download = slapos.recipe.build:Download'
]}, ]},
) )
...@@ -26,12 +26,25 @@ ...@@ -26,12 +26,25 @@
############################################################################## ##############################################################################
import logging import logging
import os import os
from platform import uname
import setuptools import setuptools
import shutil import shutil
import subprocess import subprocess
import tempfile import tempfile
import zc.buildout import zc.buildout
ARCH_MAP = {
'i386': 'x86',
'i586': 'x86',
'i686': 'x86',
'x86_64': 'x86-64'
}
ARCH_DIR_MAP = {
'x86':'x86',
'x86-64': 'x86_64'
}
def readElfAsDict(f): def readElfAsDict(f):
"""Reads ELF information from file""" """Reads ELF information from file"""
popen = subprocess.Popen(['readelf', '-d', f], popen = subprocess.Popen(['readelf', '-d', f],
...@@ -80,6 +93,12 @@ def guessworkdir(path): ...@@ -80,6 +93,12 @@ def guessworkdir(path):
return os.path.join(path, os.listdir(path)[0]) return os.path.join(path, os.listdir(path)[0])
return path return path
def guessPlatform():
arch = uname()[-2]
target = ARCH_MAP.get(arch)
assert target, 'Unknown architecture'
return target
class Script: class Script:
"""Free script building system""" """Free script building system"""
def _checkPromisee(self, location): def _checkPromisee(self, location):
...@@ -131,11 +150,11 @@ class Script: ...@@ -131,11 +150,11 @@ class Script:
if sorted(rpath_list) != sorted(elf_dict['runpath_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'])) rpath_list, elf_dict['runpath_list']))
else: # else:
raise zc.buildout.UserError('Unknown promisee %r' % promisee) # raise zc.buildout.UserError('Unknown promisee %r' % promisee)
if len(promisee_problem_list): #if len(promisee_problem_list):
raise zc.buildout.UserError('Promisee not met, found issues:\n %s' % # 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): def download(self, url, md5sum):
download = zc.buildout.download.Download(self.buildout['buildout'], download = zc.buildout.download.Download(self.buildout['buildout'],
...@@ -150,6 +169,27 @@ class Script: ...@@ -150,6 +169,27 @@ class Script:
self.cleanup_dir_list.append(extract_dir) self.cleanup_dir_list.append(extract_dir)
return extract_dir return extract_dir
def copy(self, origin, destination, ignore_dir_list=[]):
"""Copy directory.
"""
if os.path.exists(destination):
self.logger.info('No need to re-install java part')
return False
self.logger.info("Copying unpacked contents")
java_dir = ''
if 'ignore' in shutil.copytree.func_code.co_varnames:
shutil.copytree(os.path.join(origin, java_dir),
destination,
ignore=lambda src,names:ignore_dir_list)
else:
shutil.copytree(origin,
destination)
for ignore_dir in ignore_dir_list:
ignore_dir = os.path.join(destination, ignore_dir)
if os.path.exists(ignore_dir):
shutil.rmtree(ignore_dir)
return True
script = 'raise NotImplementedError' script = 'raise NotImplementedError'
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
self.cleanup_dir_list = [] self.cleanup_dir_list = []
...@@ -238,3 +278,23 @@ call(["make", "install"], cwd=workdir, env=env) ...@@ -238,3 +278,23 @@ call(["make", "install"], cwd=workdir, env=env)
def __init__(self, buildout, name, options): 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) Script.__init__(self, buildout, name, options)
class Download(Script):
"""Download and install binary package depending on your architecture.
"""
script = """
if not self.options.get('url'):
architecture = guessPlatform()
self.options['url'] = self.options["%%s_url" %% architecture]
self.options['md5sum'] = self.options["%%s_md5sum" %% architecture]
extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
print(extract_dir)
workdir = guessworkdir(extract_dir)
print ("%(location)s")
self.copy(workdir, "%(location)s")
"""
def __init__(self, buildout, name, options):
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