Commit a5b62f3d authored by sirex's avatar sirex

Updated documentation and did small refactoring to increase code readability.

parent c66433ea
Change History Change History
************** **************
0.1.8 (2014-01-25)
==================
- Feature: added 'gem-options' and 'environment' options.
- Fix: add quotes to values of environment variables.
0.1.7 (2012-05-24) 0.1.7 (2012-05-24)
================== ==================
......
...@@ -39,3 +39,17 @@ version ...@@ -39,3 +39,17 @@ version
ruby-executable ruby-executable
A path to a Ruby executable. Gems will be installed using this executable. A path to a Ruby executable. Gems will be installed using this executable.
gem-options
Extra options, that will be passed to gem executable. Example::
gem-options =
--with-icu-lib=${icu:location}/lib/
--with-icu-dir=${icu:location}/
environment
Possibility to add or override environment variables. Example::
environment =
LDFLAGS = -L${icu:location}/lib -Wl,-rpath=${icu:location}/lib
CFLAGS = -I${icu:location}/include
...@@ -9,6 +9,8 @@ import subprocess ...@@ -9,6 +9,8 @@ import subprocess
import urllib import urllib
import zc.buildout import zc.buildout
from string import strip
class Recipe(object): class Recipe(object):
"""zc.buildout recipe for compiling and installing software""" """zc.buildout recipe for compiling and installing software"""
...@@ -59,6 +61,15 @@ class Recipe(object): ...@@ -59,6 +61,15 @@ class Recipe(object):
def _join_paths(self, *paths): def _join_paths(self, *paths):
return ':'.join(filter(None, paths)) return ':'.join(filter(None, paths))
def _get_env_override(self, env):
env = filter(None, map(strip, env.splitlines()))
try:
env = [map(strip, line.split('=', 1)) for line in env]
except ValueError: # Unpacking impossible
self.log.error("Every environment line should contain a '=' sign")
zc.buildout.UserError('Configuration error')
return env
def _get_env(self): def _get_env(self):
s = { s = {
'PATH': os.environ.get('PATH', ''), 'PATH': os.environ.get('PATH', ''),
...@@ -78,16 +89,9 @@ class Recipe(object): ...@@ -78,16 +89,9 @@ class Recipe(object):
'%(PREFIX)s/bin', '%(PREFIX)s/bin',
) % s, ) % s,
} }
try: env_override = self.options.get('environment', '')
env_override = self.options.get('environment', '') env_override = self._get_env_override(env_override)
env = {k: v % env env = {k: v % env for k, v in env_override}
for k, v in [[i.strip() for i in line.split('=', 1)]
for line in env_override.split('\n')
if line.strip()]
}
except ValueError: # Unpacking impossible
self.log.error("Every environment line should contain a '=' sign")
zc.buildout.UserError('Configuration error')
return env return env
def _get_latest_rubygems(self): def _get_latest_rubygems(self):
...@@ -176,6 +180,8 @@ class Recipe(object): ...@@ -176,6 +180,8 @@ class Recipe(object):
gem_executable = self.get_gem_executable(bindir) gem_executable = self.get_gem_executable(bindir)
for gemname in self.gems: for gemname in self.gems:
extra = self.options.get('gem-options', '')
extra = ' '.join(filter(None, map(strip, extra.splitlines())))
s = { s = {
'GEM': gem_executable, 'GEM': gem_executable,
'OPTIONS': ' '.join([ 'OPTIONS': ' '.join([
...@@ -183,12 +189,12 @@ class Recipe(object): ...@@ -183,12 +189,12 @@ class Recipe(object):
'--no-ri', '--no-ri',
'--bindir=%s' % bindir, '--bindir=%s' % bindir,
]), ]),
'EXTRA': self.options.get('gem-options', ''), 'EXTRA': extra,
} }
if '==' in gemname: if '==' in gemname:
gemname, version = gemname.split('==', 1) gemname, version = map(strip, gemname.split('==', 1))
s['GEMNAME'] = gemname.strip() s['GEMNAME'] = gemname
s['OPTIONS'] += ' --version %s' % version.strip() s['OPTIONS'] += ' --version %s' % version
else: else:
s['GEMNAME'] = gemname s['GEMNAME'] = gemname
self.run('%(GEM)s install %(OPTIONS)s %(GEMNAME)s -- %(EXTRA)s' % s, self.run('%(GEM)s install %(OPTIONS)s %(GEMNAME)s -- %(EXTRA)s' % s,
......
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