diff options
-rwxr-xr-x | ybd/__main__.py | 4 | ||||
-rw-r--r-- | ybd/app.py | 21 | ||||
-rw-r--r-- | ybd/assembly.py | 6 | ||||
-rw-r--r-- | ybd/cache.py | 10 | ||||
-rw-r--r-- | ybd/morphs.py | 14 | ||||
-rw-r--r-- | ybd/repos.py | 20 | ||||
-rw-r--r-- | ybd/sandbox.py | 8 | ||||
-rw-r--r-- | ybd/splitting.py | 6 |
8 files changed, 43 insertions, 46 deletions
diff --git a/ybd/__main__.py b/ybd/__main__.py index d76e7e2..73a0958 100755 --- a/ybd/__main__.py +++ b/ybd/__main__.py @@ -21,7 +21,7 @@ import os import sys import fcntl import app -from app import cleanup, config, exit, log, RetryException, setup, spawn, timer +from app import cleanup, config, log, RetryException, setup, spawn, timer from assembly import compose from deployment import deploy from pots import Pots @@ -75,7 +75,7 @@ with timer('TOTAL'): if config['total'] == 0 or (config['total'] == 1 and target.get('kind') == 'cluster'): - exit('ARCH', 'ERROR: no definitions found for', config['arch']) + log('ARCH', 'No definitions for', config['arch'], exit=True) app.defs.save_trees() if config.get('mode', 'normal') == 'keys-only': @@ -77,9 +77,13 @@ def lockfile(dn): return os.path.join(config['tmp'], cache_key(dn) + '.lock') -def log(dn, message='', data='', verbose=False): +def log(dn, message='', data='', verbose=False, exit=False): ''' Print a timestamped log. ''' + if exit: + print('\n\n') + message = 'ERROR: ' + message + if verbose is True and config.get('log-verbose', False) is False: return @@ -101,6 +105,10 @@ def log(dn, message='', data='', verbose=False): print(entry), sys.stdout.flush() + if exit: + print('\n\n') + os._exit(1) + def log_env(log, env, message=''): with open(log, "a") as logfile: @@ -111,13 +119,6 @@ def log_env(log, env, message=''): logfile.flush() -def exit(dn, message, data): - print('\n\n') - log(dn, message, data) - print('\n\n') - os._exit(1) - - def warning_handler(message, category, filename, lineno, file=None, line=None): '''Output messages from warnings.warn() - default output is a bit ugly.''' @@ -193,8 +194,8 @@ def setup(args): os.makedirs(config[directory]) except OSError: if not os.path.isdir(config[directory]): - exit('SETUP', 'ERROR: Can not find or create', - config[directory]) + log('SETUP', 'Cannot find or create', config[directory], + exit=True) log('SETUP', '%s is directory for' % config[directory], directory) diff --git a/ybd/assembly.py b/ybd/assembly.py index 9ecdbdc..2c051e7 100644 --- a/ybd/assembly.py +++ b/ybd/assembly.py @@ -21,7 +21,7 @@ import fcntl import errno import app -from app import config, exit, timer, elapsed +from app import config, timer, elapsed from app import log, log_riemann, lockfile, RetryException from cache import cache, cache_key, get_cache, get_remote import repos @@ -211,7 +211,7 @@ def claim(dn): log(dn, 'ERROR: surprise exception in assembly', '') import traceback traceback.print_exc() - exit(dn, 'ERROR: sandbox debris is at', dn['sandbox']) + log(dn, 'Sandbox debris at', dn['sandbox'], exit=True) try: yield finally: @@ -250,7 +250,7 @@ def get_build_commands(dn): bs = app.defs.defaults.detect_build_system(files) if bs == 'manual' and 'install-commands' not in dn: if dn.get('kind', 'chunk') == 'chunk': - exit(dn, 'ERROR: no install-commands, manual build system', '') + log(dn, 'No install-commands, manual build-system', exit=True) log(dn, 'WARNING: Assumed build system is', bs) for build_step in app.defs.defaults.build_steps: diff --git a/ybd/cache.py b/ybd/cache.py index fdb685b..a8b5a16 100644 --- a/ybd/cache.py +++ b/ybd/cache.py @@ -32,13 +32,13 @@ import re def cache_key(dn): if dn is None: - app.exit(dn, 'ERROR: No definition found for', dn) + app.log(dn, 'No definition found for', dn, exit=True) if type(dn) is not dict: dn = app.defs.get(dn) if dn.get('cache') == 'calculating': - app.exit(dn, 'ERROR: recursion loop for', dn) + app.log(dn, 'Recursion loop for', dn, exit=True) if dn.get('cache'): return dn['cache'] @@ -188,7 +188,7 @@ def unpack(dn, tmpfile): path = os.path.join(app.config['artifacts'], cache_key(dn)) shutil.move(os.path.dirname(tmpfile), path) if not os.path.isdir(path): - app.exit(dn, 'ERROR: problem creating cache artifact', path) + app.log(dn, 'Problem creating artifact', path, exit=True) size = os.path.getsize(get_cache(dn)) size = re.sub("(\d)(?=(\d{3})+(?!\d))", r"\1,", "%d" % size) @@ -331,8 +331,8 @@ def cull(artifact_dir): stat = os.statvfs(artifact_dir) free = stat.f_frsize * stat.f_bavail / 1000000000 if free < app.config.get('min-gigabytes', 10): - app.exit('SETUP', 'ERROR: %sGB is less than min-gigabytes:' % free, - app.config.get('min-gigabytes', 10)) + app.log('SETUP', '%sGB is less than min-gigabytes:' % free, + app.config.get('min-gigabytes', 10), exit=True) def check(artifact): diff --git a/ybd/morphs.py b/ybd/morphs.py index 00798e0..6889baa 100644 --- a/ybd/morphs.py +++ b/ybd/morphs.py @@ -16,7 +16,7 @@ import yaml import os -from app import chdir, config, log, exit +from app import chdir, config, log from defaults import Defaults @@ -57,7 +57,7 @@ class Morphs(object): text = f.read() contents = yaml.safe_load(text) except yaml.YAMLError, exc: - exit('DEFINITIONS', 'ERROR: could not parse %s' % path, exc) + log('DEFINITIONS', 'Could not parse %s' % path, exc, exit=True) except: log('DEFINITIONS', 'WARNING: Unexpected error loading', path) return None @@ -132,7 +132,7 @@ class Morphs(object): if 'path' not in dn: if 'name' not in dn: - exit(dn, 'ERROR: no path, no name?') + log(dn, 'No path, no name?', exit=True) if config.get('artifact-version') in range(0, 4): dn['path'] = dn['name'] else: @@ -152,12 +152,8 @@ class Morphs(object): n = self._demorph(os.path.basename(dn['name'])) p = self._demorph(os.path.basename(dn['path'])) if os.path.splitext(p)[0] not in n: - if config.get('check-definitions') == 'warn': - log('DEFINITIONS', - 'WARNING: %s has wrong name' % dn['path'], dn['name']) - if config.get('check-definitions') == 'exit': - exit('DEFINITIONS', - 'ERROR: %s has wrong name' % dn['path'], dn['name']) + exit = True if config.get('check-definitions') == 'exit' else False + log('MORPHS', '%s wrong name' % dn['path'], dn['name'], exit=exit) for system in (dn.get('systems', []) + dn.get('subsystems', [])): self._fix_keys(system) diff --git a/ybd/repos.py b/ybd/repos.py index 23bbb8e..926ea79 100644 --- a/ybd/repos.py +++ b/ybd/repos.py @@ -93,7 +93,7 @@ def get_tree(dn): if dn['repo'].startswith('file://') or dn['repo'].startswith('/'): gitdir = dn['repo'].replace('file://', '') if not os.path.isdir(gitdir): - app.exit(dn, 'ERROR: git repo not found:', dn['repo']) + app.log(dn, 'Git repo not found:', dn['repo'], exit=True) if not os.path.exists(gitdir): try: @@ -121,7 +121,7 @@ def get_tree(dn): except: # either we don't have a git dir, or ref is not unique # or ref does not exist - app.exit(dn, 'ERROR: could not find tree for ref', (ref, gitdir)) + app.log(dn, 'No tree for ref', (ref, gitdir), exit=True) def mirror(name, repo): @@ -141,11 +141,11 @@ def mirror(name, repo): app.log(name, 'Try git clone from', repo_url) with open(os.devnull, "w") as fnull: if call(['git', 'clone', '--mirror', '-n', repo_url, tmpdir]): - app.exit(name, 'ERROR: failed to clone', repo) + app.log(name, 'Failed to clone', repo, exit=True) with app.chdir(tmpdir): if call(['git', 'rev-parse']): - app.exit(name, 'ERROR: problem mirroring git repo at', tmpdir) + app.log(name, 'Problem mirroring git repo at', tmpdir, exit=True) gitdir = os.path.join(app.config['gits'], get_repo_name(repo)) try: @@ -172,7 +172,7 @@ def update_mirror(name, repo, gitdir): repo_url = get_repo_url(repo) if call(['git', 'fetch', repo_url, '+refs/*:refs/*', '--prune'], stdout=fnull, stderr=fnull): - app.exit(name, 'ERROR: git update mirror failed', repo) + app.log(name, 'Git update mirror failed', repo, exit=True) def checkout(dn): @@ -200,12 +200,12 @@ def _checkout(name, repo, ref, checkout): # removed --no-hardlinks, though. if call(['git', 'clone', '--no-hardlinks', gitdir, checkout], stdout=fnull, stderr=fnull): - app.exit(name, 'ERROR: git clone failed for', ref) + app.log(name, 'Git clone failed for', ref, exit=True) with app.chdir(checkout): if call(['git', 'checkout', '--force', ref], stdout=fnull, stderr=fnull): - app.exit(name, 'ERROR: git checkout failed for', ref) + app.log(name, 'Git checkout failed for', ref, exit=True) app.log(name, 'Git checkout %s in %s' % (repo, checkout)) app.log(name, 'Upstream version %s' % get_version(checkout, ref)) @@ -235,10 +235,10 @@ def extract_commit(name, repo, ref, target_dir): app.log(name, 'Extracting commit', ref) if call(['git', 'read-tree', ref], env=git_env, cwd=gitdir): - app.exit(name, 'ERROR: git read-tree failed for', ref) + app.log(name, 'git read-tree failed for', ref, exit=True) app.log(name, 'Then checkout index', ref) if call(['git', 'checkout-index', '--all'], env=git_env, cwd=gitdir): - app.exit(name, 'ERROR: git checkout-index failed for', ref) + app.log(name, 'Git checkout-index failed for', ref, exit=True) app.log(name, 'Done', ref) utils.set_mtime_recursively(target_dir) @@ -286,7 +286,7 @@ def checkout_submodules(dn): fields) except: - app.exit(dn, "ERROR: git submodules problem", "") + app.log(dn, "Git submodules problem", exit=True) @contextlib.contextmanager diff --git a/ybd/sandbox.py b/ybd/sandbox.py index 958c8b5..f04f4e0 100644 --- a/ybd/sandbox.py +++ b/ybd/sandbox.py @@ -63,7 +63,7 @@ def setup(dn): import traceback app.log(dn, 'ERROR: surprise exception in sandbox', '') traceback.print_exc() - app.exit(dn, 'ERROR: sandbox debris is at', dn['sandbox']) + app.log(dn, 'Sandbox debris is at', dn['sandbox'], exit=True) finally: pass @@ -78,7 +78,7 @@ def install(dn, component): return app.log(dn, 'Sandbox: installing %s' % component['cache'], verbose=True) if cache.get_cache(component) is False: - app.exit(dn, 'ERROR: unable to get cache for', component['name']) + app.log(dn, 'Unable to get cache for', component['name'], exit=True) unpackdir = cache.get_cache(component) + '.unpacked' if dn.get('kind') is 'system': utils.copy_all_files(unpackdir, dn['sandbox']) @@ -179,7 +179,7 @@ def run_sandboxed(dn, command, env=None, allow_parallel=False): os.getcwd(), argv_to_string(argv)) call(['tail', '-n', '200', dn['log']]) app.log(dn, 'ERROR: log file is at', dn['log']) - app.exit(dn, 'ERROR: sandbox debris is at', dn['sandbox']) + app.log(dn, 'Sandbox debris is at', dn['sandbox'], exit=True) finally: if cur_makeflags is not None: env['MAKEFLAGS'] = cur_makeflags @@ -192,7 +192,7 @@ def run_logged(dn, cmd_list): app.log(dn, 'ERROR: command failed in directory %s:\n\n' % os.getcwd(), argv_to_string(cmd_list)) call(['tail', '-n', '200', dn['log']]) - app.exit(dn, 'ERROR: log file is at', dn['log']) + app.log(dn, 'Log file is at', dn['log'], exit=True) def run_extension(dn, deployment, step, method): diff --git a/ybd/splitting.py b/ybd/splitting.py index ffa98db..6c8e5fe 100644 --- a/ybd/splitting.py +++ b/ybd/splitting.py @@ -15,7 +15,7 @@ # =*= License: GPL-2 =*= import app -from app import config, exit, log +from app import config, log from cache import get_cache import os import re @@ -113,7 +113,7 @@ def move_required_files(dn, stratum, artifacts): except: import traceback traceback.print_exc() - exit(dn, 'ERROR: failed to install split components', '') + log(dn, 'Failed to install split components', exit=True) def check_overlaps(dn): @@ -133,7 +133,7 @@ def check_overlaps(dn): overlaps_found = True break if config.get('check-overlaps') == 'exit': - exit(dn, 'ERROR: overlaps found', config['new-overlaps']) + log(dn, 'Overlaps found', config['new-overlaps'], exit=True) config['overlaps'] = list(set(config['new-overlaps'] + config['overlaps'])) config['new-overlaps'] = [] |