Commit e1078967 authored by Łukasz Nowak's avatar Łukasz Nowak

Java installation recipe.

parent bc1024a6
Changelog
=========
0.0.2
----------------
Adapting to use auto-extracting packages, and not rpms.
[Cedric de Saint Martin]
0.0.1
----------------
Initial Commit
[Cedric de Saint Martin]
\ No newline at end of file
include CHANGES.txt
\ No newline at end of file
Metadata-Version: 1.0
Name: slapos.recipe.java
Version: 0.0.2
Summary: zc.buildout recipe that downloads and installs Java
Home-page: http://www.slapos.org
Author: Cedric de Saint Martin
Author-email: cedric.dsm@tiolive.com
License: ZPL 2.1
Description: slapos.recipe.java
=====================
This recipe downloads and installs java in your buildout.
Buildout configuration:
-----------------------
Add this section to your buildout configuration::
[buildout]
parts =
... your other parts ...
java
...
[java]
recipe = slapos.recipe.java
By default it will fetch Java 6u25, but you might want to install from another location or another version like this::
[java]
recipe = slapos.recipe.java
download-url = ftp://location/to/self-extracting/java.bin
Or you can install openjdk instead.
[java]
recipe = slapos.recipe.java
flavour = openjdk
Notes:
------
This recipe only works with linux at the moment
This recipe requires rpm2cpio and cpio to be installed on your system.
Authors:
--------
Original author: Cedric de Saint Martin - cedric.dsm [ at ] tiolive [ dot ] com
Inspired by : z3c.recipe.openoffice made by Jean-Francois Roche - jfroche@affinitic.be
Keywords: buildout java slapos
Platform: UNKNOWN
slapos.recipe.java
=====================
This recipe downloads and installs java in your buildout.
Buildout configuration:
-----------------------
Add this section to your buildout configuration::
[buildout]
parts =
... your other parts ...
java
...
[java]
recipe = slapos.recipe.java
By default it will fetch Java 6u25, but you might want to install from another location or another version like this::
[java]
recipe = slapos.recipe.java
download-url = ftp://location/to/self-extracting/java.bin
Or you can install openjdk instead.
[java]
recipe = slapos.recipe.java
flavour = openjdk
Notes:
------
This recipe only works with linux at the moment
This recipe requires rpm2cpio and cpio to be installed on your system.
Authors:
--------
Original author: Cedric de Saint Martin - cedric.dsm [ at ] tiolive [ dot ] com
Inspired by : z3c.recipe.openoffice made by Jean-Francois Roche - jfroche@affinitic.be
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
from setuptools import setup, find_packages
import os
version = '0.0.2'
name='slapos.recipe.java'
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description=( read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = "Cedric de Saint Martin",
author_email = "cedric.dsm@tiolive.com",
description = "zc.buildout recipe that downloads and installs Java",
long_description = long_description,
license ='ZPL 2.1',
keywords = "buildout java slapos",
url ='http://www.slapos.org/',
packages = find_packages('src'),
include_package_data = True,
package_dir = {'': 'src'},
namespace_packages = ['slapos', 'slapos.recipe'],
install_requires = ['zc.buildout', 'setuptools'],
entry_points = {'zc.buildout': ['default = %s.recipe:Recipe' % name]},
)
# namespace package boilerplate
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
import logging
import os
import shutil
import zc.buildout.easy_install
import zc.buildout.download
from platform import uname
import subprocess
JAVA_URLS = {
'x86': "http://javadl.sun.com/webapps/download/AutoDL?BundleId=48334",
'x86-64': "http://javadl.sun.com/webapps/download/AutoDL?BundleId=48338"
}
# See http://java.com/en/download/manual.jsp
ARCH_MAP = {
'i386': 'x86',
'i586': 'x86',
'i686': 'x86',
'x86_64': 'x86-64'
}
ARCH_DIR_MAP = {
'x86':'x86',
'x86-64': 'x86_64'
}
class Recipe(object):
def __init__(self, buildout, name, options):
self.buildout = buildout
self.name = name
self.options = options
self.logger = logging.getLogger(self.name)
options['location'] = os.path.join(
buildout['buildout']['parts-directory'],
self.name)
options.setdefault('cpio', 'cpio')
options.setdefault('tmp-storage', options['location'] + '__unpack__')
if not options.get('download-url'):
options.setdefault('platform', self._guessPackagePlatform())
options.setdefault(
'flavour',
'oracle-jdk') # or 'openjdk'
if options['flavour'] == 'openjdk':
raise Exception('OpenJDK is not yet supported.')
else:
options['download-url'] = JAVA_URLS[options['platform']]
def _guessPackagePlatform(self):
arch = uname()[-2]
target = ARCH_MAP.get(arch)
assert target, 'Unknown architecture'
return target
def install(self):
location = self.options['location']
if os.path.exists(location):
return location
storage = self.options['tmp-storage']
download_file, is_temp = self.download()
self.extract(storage, download_file)
self.copy(storage)
shutil.rmtree(storage)
return [location,]
def download(self):
"""Download tarball. Caching if required.
"""
url = self.options['download-url']
namespace = self.options['recipe']
download = zc.buildout.download.Download(self.buildout['buildout'],
namespace=namespace,
logger=self.logger)
return download(url)
def extract(self, storage, download_file):
# Creates parts/java__something temp dir
if os.path.exists(storage):
shutil.rmtree(storage)
os.mkdir(storage)
os.chdir(storage)
# Move downloaded file into temp dir
(download_dir, filename) = os.path.split(download_file)
auto_extract_bin = os.path.join(storage, filename)
shutil.move(download_file, auto_extract_bin)
# Run auto-extract bin file
os.chmod(auto_extract_bin, 0777)
subprocess.call([auto_extract_bin])
def copy(self, storage):
"""Copy java installation into parts directory.
"""
location = self.options['location']
if os.path.exists(location):
self.logger.info('No need to re-install java part')
return False
self.logger.info("Copying unpacked contents")
java_dir = ''
for java_dir in ('java', 'jre1.6.0_25'):
if os.path.isdir(os.path.join(storage, java_dir)):
break
assert java_dir, 'Java directory seems missing.'
ignore_dir_list = []
if 'ignore' in shutil.copytree.func_code.co_varnames:
shutil.copytree(os.path.join(storage, java_dir),
location,
ignore=lambda src,names:ignore_dir_list)
else:
shutil.copytree(os.path.join(storage, java_dir),
location)
for ignore_dir in ignore_dir_list:
ignore_dir = os.path.join(location, ignore_dir)
if os.path.exists(ignore_dir):
shutil.rmtree(ignore_dir)
return True
def update(self):
pass
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