Update working with errors

This commit is contained in:
Mikhail Gordeev 2020-04-20 19:56:19 +03:00
parent 4ba1296d06
commit 839ac9e42a

View File

@ -10,7 +10,6 @@ import logging
import os import os
import re import re
import subprocess import subprocess
import sys
import yaml import yaml
@ -105,7 +104,9 @@ class CB:
try: try:
fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError: # already locked except OSError: # already locked
self.error(f'{PROG} already running') dd = self.data_dir
msg = f'Program {PROG} already running in `{dd}` directory'
self.error(msg)
@contextlib.contextmanager @contextlib.contextmanager
def pushd(self, new_dir): def pushd(self, new_dir):
@ -120,10 +121,9 @@ class CB:
try: try:
with open(config) as f: with open(config) as f:
cfg = yaml.safe_load(f) cfg = yaml.safe_load(f)
except FileNotFoundError as e: except OSError as e:
print(f'Could not find config file: `{e.filename}`', msg = f'Could not read config file `{e.filename}`: {e.strerror}'
file=sys.stdout) raise Error(msg)
sys.exit(1)
self.mkimage_profiles_git = self.expand_path( self.mkimage_profiles_git = self.expand_path(
cfg.get('mkimage_profiles_git', '') cfg.get('mkimage_profiles_git', '')
@ -156,8 +156,7 @@ class CB:
for k, v in branch['arches'].items()} for k, v in branch['arches'].items()}
except KeyError as e: except KeyError as e:
msg = f'Required parameter {e} does not set in config' msg = f'Required parameter {e} does not set in config'
print(msg, file=sys.stderr) raise Error(msg)
raise Exception(msg)
def info(self, msg: str) -> None: def info(self, msg: str) -> None:
self.log.info(msg) self.log.info(msg)