Commit cf95df81 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

style: import UserError and use Recipe().install()

- import UserError from zc.buildout for shorter usage
- use Recipe(...).install() one-liner when recipe varible is uncessary
parent cb8165cb
......@@ -8,10 +8,10 @@ import os
import re
import stat
import subprocess
import zc.buildout
import six.moves.urllib as urllib
from zc.buildout import UserError
from zc.buildout.easy_install import allow_picked_versions
from slapos.recipe import rmtree
from slapos.recipe.downloadunpacked import Recipe as Download
......@@ -42,13 +42,12 @@ class Recipe(object):
if self.gems:
self.gems = self.gems.split()
else:
raise zc.buildout.UserError(
"Configuration error, 'gems' option is missing")
raise UserError("Configuration error, 'gems' option is missing")
self.url = options.get('url')
if(self.url and options.get('version')):
raise zc.buildout.UserError(
"Configuration error, 'url' and 'version' options are mutually exclusive")
raise UserError("Configuration error, "
"'url' and 'version' options are mutually exclusive")
# Allow to define specific ruby executable. If not, take just 'ruby'
self.ruby_executable = options.get('ruby-executable', 'ruby')
......@@ -67,17 +66,14 @@ class Recipe(object):
try:
return subprocess.check_output(cmd, env=env, universal_newlines=True)
except OSError as e:
raise zc.buildout.UserError(
'System error, command failed: %s: %s' % (e, cmd))
raise UserError('System error, command failed: %s: %s' % (e, cmd))
except subprocess.CalledProcessError as e:
self.log.error(e.output)
if e.returncode < 0:
raise zc.buildout.UserError(
'System error, command received signal %s: %s'
% (-e.returncode, e.cmd)
)
raise UserError('System error, command received signal %s: %s'
% (-e.returncode, e.cmd))
elif e.returncode > 0:
raise zc.buildout.UserError(
raise UserError(
'System error, command failed with exit code %s: %s'
% (e.returncode, e.cmd)
)
......@@ -124,7 +120,7 @@ class Recipe(object):
% (' '.join(cons_dict.values()), dep_dict['gemname'], gemname)
)
raise zc.buildout.UserError(
raise UserError(
'Configuration error, version %s for gem %s '
'does not satisfy dependency constraint %s of gem %s'
% (dep_dict['version'], dep_dict['gemname'],
......@@ -141,10 +137,8 @@ class Recipe(object):
map(strip, line.split('=', 1)) for line in env
]])
except ValueError: # Unpacking impossible
raise zc.buildout.UserError(
'Configuration error, '
'every environment line should contain a "=" sign'
)
raise UserError('Configuration error, '
'every environment line should contain a "=" sign')
return env
def _get_env(self):
......@@ -195,7 +189,7 @@ class Recipe(object):
f.close()
if r:
return url or r.group(0), r.group(1)
raise zc.buildout.UserError("Can't find rubygems version.")
raise UserError("Can't find rubygems version.")
def _install_rubygems(self, url, version):
srcdir = os.path.join(self.buildout['buildout']['parts-directory'],
......@@ -204,8 +198,7 @@ class Recipe(object):
'url': url,
'destination': srcdir,
}
recipe = Download(self.buildout, self.name, options)
recipe.install()
Download(self.buildout, self.name, options).install()
current_dir = os.getcwd()
os.chdir(srcdir)
......@@ -313,7 +306,7 @@ class Recipe(object):
url, version = self._get_rubygems_url_and_version()
if int(version.split(".")[0]) < 2:
raise zc.buildout.UserError("Rubygems version must be >= 2.0.0")
raise UserError("Rubygems version must be >= 2.0.0")
self._install_rubygems(url, version)
gem_executable = glob.glob(os.path.join(bindir, 'gem*'))[0]
......@@ -322,7 +315,7 @@ class Recipe(object):
for gem_dict in gem_dict_list:
if self.deployment:
if 'version' not in gem_dict:
raise zc.buildout.UserError(
raise UserError(
'Configuration error, '
'version for gem %s is missing' % gem_dict['gemname']
)
......@@ -333,7 +326,7 @@ class Recipe(object):
match = [gem_d for gem_d in gem_dict_list
if dep_dict['gemname'] == gem_d['gemname']]
if not match:
raise zc.buildout.UserError(
raise UserError(
'Configuration error, '
'version for dependency %s is missing'
% dep_dict['gemname']
......
This diff is collapsed.
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