Commit 4f14e1ff authored by Julien Muchembled's avatar Julien Muchembled

Clean up usage of logging module

parent 9c0113de
......@@ -330,7 +330,7 @@ default build options.
configure --prefix=/sample_buildout/parts/packagex
building package
installing package
packagex: could not find promise "/usr/bin/myfoo"
packagex: could not find promise '/usr/bin/myfoo'
<BLANKLINE>
As we can see the configure script was called with the ``--prefix``
......
......@@ -46,7 +46,7 @@ class Recipe(object):
self.options = options
self.buildout = buildout
self.name = name
log = logging.getLogger(self.name)
self.logger = logging.getLogger(self.name)
# Merge options if there is a matched platform section
platform_options = buildout.get(
"%s:%s:%s" % (name, sys.platform, self.get_machine()),
......@@ -90,7 +90,7 @@ class Recipe(object):
signature_digest)
if os.path.exists(shared):
break
log.info('shared at %s', shared)
self.logger.info('shared at %s', shared)
else:
shared = ''
......@@ -212,23 +212,21 @@ class Recipe(object):
# in this path which create time is newer than ref_file.
# Exclude directory and don't follow link.
assert self.buildout_prefix
log = logging.getLogger(self.name)
args = ['find', self.buildout_prefix, '-cnewer', ref_file, '!', '-type', 'd']
try:
files = subprocess.check_output(args,
universal_newlines=True, close_fds=True)
except Exception as e:
log.error(e)
self.logger.error(e)
raise zc.buildout.UserError('System error')
return files.splitlines()
def check_promises(self, log=None):
def check_promises(self):
result = True
log = logging.getLogger(self.name)
for path in self.options['promises'].splitlines():
if path and not os.path.exists(path):
result = False
log.warning('could not find promise "%s"' % path)
self.logger.warning('could not find promise %r', path)
return result
def call_script(self, script):
......@@ -255,16 +253,15 @@ class Recipe(object):
def run(self, cmd):
"""Run the given ``cmd`` in a child process."""
log = logging.getLogger(self.name)
try:
subprocess.check_call('set -e;' + cmd, shell=True,
env=self.augmented_environment(), close_fds=True)
except Exception as e:
log.error(e)
self.logger.error(e)
raise zc.buildout.UserError('System error')
def install(self):
log = logging.getLogger(self.name)
log = self.logger
parts = []
# In shared mode, do nothing if package has been installed.
......@@ -312,7 +309,7 @@ class Recipe(object):
compile_dir = self.options['compile-directory']
if os.path.exists(compile_dir):
# leftovers from a previous failed attempt, removing it.
log.warning('Removing already existing directory %s' % compile_dir)
log.warning('Removing already existing directory %s', compile_dir)
shutil.rmtree(compile_dir)
os.makedirs(compile_dir)
try:
......@@ -327,7 +324,7 @@ class Recipe(object):
shutil.rmtree(compile_dir)
raise
else:
log.info('Using local source directory: %s' % self.options['path'])
log.info('Using local source directory: %s', self.options['path'])
compile_dir = self.options['path']
current_dir = os.getcwd()
......@@ -420,7 +417,8 @@ echo %s
log.error('Compilation error. The package is left as is at %s where '
'you can inspect what went wrong.\n'
'A shell script slapos.recipe.build.env.sh has been generated. '
'You can source it in your shell to reproduce build environment.' % os.getcwd())
'You can source it in your shell to reproduce build environment.',
os.getcwd())
# Delete shared directory if not correctly installed
if self.options.get('shared'):
......@@ -433,7 +431,7 @@ echo %s
self._signature.save(self.options["shared"])
# Check promises
self.check_promises(log)
self.check_promises()
if self.options['url']:
if self.options.get('keep-compile-dir',
......
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