From b60d5a4e5c3e1816d743ca4a69b978c6c172c82b Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Tue, 9 Apr 2019 18:13:37 +0200 Subject: [PATCH] added more config options, among others an option to run depclean on gentoo --- bin/sau | 16 ++++++++++++++-- config.cfg | 13 +++++++++++++ sau/gentoo.py | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bin/sau b/bin/sau index 6a0605f..8990527 100755 --- a/bin/sau +++ b/bin/sau @@ -40,6 +40,16 @@ def main(): time.sleep(1) os.system('/sbin/reboot') +def _conf_level_to_logging_level(conf_level): + if conf_level.lower() == 'debug': + return logging.DEBUG + if conf_level.lower() == 'info': + return logging.INFO + if conf_level.lower() == 'warning': + return logging.WARNING + if conf_level.lower() == 'error': + return logging.error + return logging.DEBUG if __name__ == '__main__': sau.config = configparser.SafeConfigParser() @@ -58,16 +68,18 @@ if __name__ == '__main__': log = logging.getLogger(sau.LOGNAME) log.setLevel(logging.DEBUG) + conf_level = _conf_level_to_logging_level(conf.get('default', 'stderr_loglevel', fallback="debug")) handler = logging.StreamHandler() formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s') handler.setFormatter(formatter) - handler.setLevel(logging.DEBUG) + handler.setLevel(conf_level) log.addHandler(handler) + conf_level = _conf_level_to_logging_level(conf.get('default', 'syslog_loglevel', fallback="debug")) handler = logging.handlers.SysLogHandler(address=syslog_socket) formatter = logging.Formatter(fmt='{}[%(process)s] %(message)s'.format(sau.LOGNAME)) handler.setFormatter(formatter) - handler.setLevel(logging.INFO) + handler.setLevel(conf_level) log.addHandler(handler) sys.exit(main()) diff --git a/config.cfg b/config.cfg index c3b1843..ab53309 100644 --- a/config.cfg +++ b/config.cfg @@ -16,10 +16,23 @@ min_version_diff=2 # not close all deleted files (any platform) do_reboot=no +# FreeBSD system update (freebsd-update fetch install, not freebsd-update upgrade) do_system_upgrade=yes + +# upgrade packages do_package_upgrade=yes + +# restart services affected by previous upgrades do_service_restart=yes +# do depclean on Gentoo +do_depclean=yes + +# to only write to stderr when something unexpected happens or manual action is required +# set stderr_loglevel to warning +stderr_loglevel=debug +syslog_loglevel=info + # The packages section contains = pairs to override the # default min_version_diff. Note that package naming may differ depending on diff --git a/sau/gentoo.py b/sau/gentoo.py index 903c4d4..61a2080 100644 --- a/sau/gentoo.py +++ b/sau/gentoo.py @@ -255,3 +255,25 @@ def pkg_upgrade(): for line in out.splitlines(): if line.startswith(' * '): log.warning(line) + + if conf.getboolean('default', 'do_depclean', fallback=False): + cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ] + log.debug('Executing "{}"'.format(' '.join(cmd))) + proc = subprocess.Popen( + cmd, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE) + out, err = proc.communicate() + out = out.decode('utf-8') + err = err.decode('utf-8') + if proc.returncode != 0 or err: + log.error('depclean returned {}'.format(proc.returncode)) + for line in out.splitlines(): + log.error('stdout: {}'.format(line)) + for line in err.splitlines(): + log.error('stderr: {}'.format(line)) + else: + log.info('depclean complete') + for line in out.splitlines(): + if line.startswith(' * '): + log.warning(line)