diff --git a/dnf/automatic/emitter.py b/dnf/automatic/emitter.py index 4aea4b02aa..648f1a1d41 100644 --- a/dnf/automatic/emitter.py +++ b/dnf/automatic/emitter.py @@ -106,7 +106,7 @@ def commit(self): smtp = smtplib.SMTP(self._conf.email_host, timeout=300) smtp.sendmail(email_from, email_to, message.as_string()) smtp.close() - except smtplib.SMTPException as exc: + except OSError as exc: msg = _("Failed to send an email via '%s': %s") % ( self._conf.email_host, exc) logger.error(msg) diff --git a/dnf/automatic/main.py b/dnf/automatic/main.py index ccd9ab645c..3d73ffce1b 100644 --- a/dnf/automatic/main.py +++ b/dnf/automatic/main.py @@ -73,7 +73,7 @@ def build_emitters(conf): def parse_arguments(args): parser = argparse.ArgumentParser() - parser.add_argument('conf_path', nargs='?', default=dnf.const.CONF_AUTOMATIC_FILENAME) + parser.add_argument('conf_path', nargs='?') parser.add_argument('--timer', action='store_true') parser.add_argument('--installupdates', dest='installupdates', action='store_true') parser.add_argument('--downloadupdates', dest='downloadupdates', action='store_true') @@ -88,7 +88,17 @@ def parse_arguments(args): class AutomaticConfig(object): def __init__(self, filename=None, downloadupdates=None, installupdates=None): - if not filename: + if filename: + # Specific config file was explicitely requested. Check that it exists + # and is readable. + if os.access(filename, os.F_OK): + if not os.access(filename, os.R_OK): + raise dnf.exceptions.Error( + "Configuration file \"{}\" is not readable.".format(filename)) + else: + raise dnf.exceptions.Error( + "Configuration file \"{}\" not found.".format(filename)) + else: filename = dnf.const.CONF_AUTOMATIC_FILENAME self.commands = CommandsConfig() self.email = EmailConfig() @@ -295,6 +305,8 @@ def remote_address(url_list): def main(args): (opts, parser) = parse_arguments(args) + conf = None + emitters = None try: conf = AutomaticConfig(opts.conf_path, opts.downloadupdates,