From fca5f12aa2cad7f6d4a885da34be66700fb18c12 Mon Sep 17 00:00:00 2001 From: brent s Date: Wed, 17 Jun 2020 13:46:58 -0400 Subject: [PATCH] suppress a specific warning if we're running from cron, otherwise there's a lot of cron alerts. --- repomirror/sync.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/repomirror/sync.py b/repomirror/sync.py index 4da4286..3f0d643 100644 --- a/repomirror/sync.py +++ b/repomirror/sync.py @@ -4,6 +4,7 @@ import pwd import grp import os import socket +import sys import warnings ## import psutil @@ -17,6 +18,12 @@ from . import logger _logger = logging.getLogger() +if os.isatty(sys.stdin.fileno()): + _is_cron = False +else: + _is_cron = True + + def get_owner(owner_xml): owner = {} user = owner_xml.find('user') @@ -269,7 +276,15 @@ class Distro(object): _logger.warning(warnmsg) if proc: _logger.warning('PID information: {0}'.format(vars(proc))) - warnings.warn(warnmsg) + # This is *really* annoying if you're running from cron and get emailed output. + # So we suppress it if in cron. + if not _is_cron: + warnings.warn(warnmsg) + if proc: + proc_info = {k.lstrip('_'):v for k, v in vars(proc) if k not in ('_lock', '_proc')} + import pprint + print('Process information:') + pprint.pprint(proc_info) return(False) if not self.mount.is_mounted: _logger.error(('The mountpoint {0} for distro {1} is not mounted; '