diff --git a/ebuildtester/main.py b/ebuildtester/main.py index ed89a5b..29df720 100644 --- a/ebuildtester/main.py +++ b/ebuildtester/main.py @@ -1,7 +1,6 @@ from ebuildtester.docker import Docker, ExecuteFailure from ebuildtester.parse import parse_commandline import ebuildtester.options as options -import logging import os.path import sys @@ -9,11 +8,14 @@ def main(): """The main function.""" - options.init() - - options.log.setLevel(logging.DEBUG) - options.options = parse_commandline(sys.argv[1:]) + if len(options.options.atom) > 0: + options.set_logfile('ebuildtester-' + + ':'.join([f'{atom.category}-{atom.package}' + for atom in options.options.atom]) + + '.log') + else: + options.set_logfile('ebuildtester-manual.log') options.log.info("creating container") container = Docker( diff --git a/ebuildtester/options.py b/ebuildtester/options.py index a9019ab..691ef43 100644 --- a/ebuildtester/options.py +++ b/ebuildtester/options.py @@ -1,23 +1,31 @@ +"""Options and some initializations.""" + from ebuildtester.atom import Atom import logging +import os + +base_packages = list(map(Atom, ["app-portage/gentoolkit", + "app-portage/flaggie"])) +options = None +log = logging.getLogger("test-package") +log_ch = logging.StreamHandler() +log_ch.setLevel(logging.INFO) +log_ch.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) +log.addHandler(log_ch) +log.setLevel(logging.DEBUG) +logdir = os.getenv('XDG_STATE_HOME', '/tmp') +_logfile = None +_log_filehandle = None -def init(): - global base_packages - global log - global log_ch - global options - base_packages = list(map(Atom, ["app-portage/gentoolkit", - "app-portage/flaggie"])) - options = None - log = logging.getLogger("test-package") - log_ch = logging.StreamHandler() - log_ch.setLevel(logging.INFO) - log_ch.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) - log.addHandler(log_ch) +def set_logfile(logfile): + """Add a logfile to logging.""" - fh = logging.FileHandler("/tmp/ebuildtester.log", "a") - fh.setLevel(logging.INFO) - fh.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) - log.addHandler(fh) + _logfile = os.path.join(logdir, logfile) + _log_filehandle = logging.FileHandler(_logfile, "a") + _log_filehandle.setLevel(logging.INFO) + _log_filehandle.setFormatter( + logging.Formatter("%(asctime)s - %(message)s")) + log.addHandler(_log_filehandle) + log.info("logging at %s", _logfile)