diff --git a/timmy/conf.py b/timmy/conf.py index 6107d7d..fabe5c0 100644 --- a/timmy/conf.py +++ b/timmy/conf.py @@ -1,8 +1,7 @@ -import yaml import logging import sys from nodefilter import NodeFilter - +from tools import load_yaml_file class Conf(object): """Configuration parameters""" @@ -32,25 +31,8 @@ class Conf(object): @staticmethod def load_conf(filename): - try: - with open(filename, 'r') as f: - conf = yaml.load(f) - return Conf(**conf) - except IOError as e: - logging.error("load_conf: I/O error(%s): %s" % - (e.errno, e.strerror)) - sys.exit(1) - except ValueError: - logging.error("load_conf: Could not convert data") - sys.exit(1) - except yaml.parser.ParserError as e: - logging.error("load_conf: Could not parse %s:\n%s" % - (filename, str(e))) - sys.exit(1) - except: - logging.error("load_conf: Unexpected error: %s" % - sys.exc_info()[0]) - sys.exit(1) + conf = load_yaml_file(filename) + return Conf(**conf) if __name__ == '__main__': diff --git a/timmy/tools.py b/timmy/tools.py index c738858..f76ae5b 100644 --- a/timmy/tools.py +++ b/timmy/tools.py @@ -25,6 +25,7 @@ import sys import threading from multiprocessing import Process, Queue, BoundedSemaphore import subprocess +import yaml slowpipe = ''' @@ -137,6 +138,27 @@ def get_dir_structure(rootdir): return dir +def load_yaml_file(filename): + try: + with open(filename, 'r') as f: + return yaml.load(f) + except IOError as e: + logging.error("load_conf: I/O error(%s): %s" % + (e.errno, e.strerror)) + sys.exit(1) + except ValueError: + logging.error("load_conf: Could not convert data") + sys.exit(1) + except yaml.parser.ParserError as e: + logging.error("load_conf: Could not parse %s:\n%s" % + (filename, str(e))) + sys.exit(1) + except: + logging.error("load_conf: Unexpected error: %s" % + sys.exc_info()[0]) + sys.exit(1) + + def mdir(directory): if not os.path.exists(directory): logging.debug('creating directory %s' % directory)