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