From 7922f5b4830e105dae5aea3345f69ea2bdc7d304 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sat, 13 Mar 2021 17:31:08 +0100 Subject: fetchmailconf: robustness fixes Make sure fetchmailconf -V can complete without finding fetchmail or Tkinter. Make sure fetchmailconf -d can complete without Tkinter. --- fetchmailconf.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'fetchmailconf.py') diff --git a/fetchmailconf.py b/fetchmailconf.py index 53434df6..1e9b2f84 100755 --- a/fetchmailconf.py +++ b/fetchmailconf.py @@ -26,10 +26,16 @@ import getopt import tempfile import ssl import subprocess -from tkinter import * -from tkinter.dialog import * +try: + from tkinter import * + from tkinter.dialog import * + have_tk=True +except: + have_tk=False + # define a dummy class to inherit from + class Frame: pass -VERSION = "1.63.3" +VERSION = "1.63.4" MIN_PY = (2, 7, 13) if sys.version_info < MIN_PY: @@ -495,7 +501,7 @@ def flag2str(value, string): res = "" if value != None: res = res + (" ") - if value == FALSE: + if not value: res = res + ("no ") res = res + string return res @@ -2183,7 +2189,7 @@ gUSiYASJpMEHhilJTEnhAlGoQqYAZQ1AiqEMZ0jDGtqQImhwwA13yMMevoQAGvGhEAWHGMOAAAA7 dump = rcfile = None for (switch, val) in options: if switch == '-d': - dump = TRUE + dump = True elif switch == '-f': rcfile = val elif switch == '-h' or switch == '--help': @@ -2207,8 +2213,7 @@ COPYING in the source or documentation directory for details.""") sys.exit(0) if "DISPLAY" not in os.environ: - print("fetchmailconf must be run under X") - sys.exit(1) + sys.exit("fetchmailconf must be run under X") # Get client host's FQDN hostname = socket.gethostname() @@ -2218,12 +2223,7 @@ COPYING in the source or documentation directory for details.""") if not '.' in hostname: sys.exit('Cannot qualify my own hostname, "{}".\nFix /etc/hosts, see man 5 hosts, or add the host to DNS.'.format(hostname)) - # Compute defaults - ConfigurationDefaults = Configuration() - ServerDefaults = Server() - UserDefaults = User() - - # Read the existing configuration. + # Read the existing configuration. cmd = ['fetchmail', '--configdump', '--nosyslog'] if rcfile: cmd += ['-f', rcfile] @@ -2242,6 +2242,11 @@ COPYING in the source or documentation directory for details.""") except Exception as e: sys.exit("Can't parse output of fetchmail --configdump:\n" + str(e)) + # Compute defaults + ConfigurationDefaults = Configuration() + ServerDefaults = Server() + UserDefaults = User() + # The tricky part -- initializing objects from the configuration global # `Configuration' is the top level of the object tree we're going to mung. # The dictmembers list is used to track the set of fields the dictionary @@ -2274,6 +2279,10 @@ COPYING in the source or documentation directory for details.""") if not rcfile and not dump: rcfile = os.environ["HOME"] + "/.fetchmailrc" + if not have_tk: + print("Python's tk (tkinter) module is missing. Please install it to use fetchmailconf.", file=sys.stderr) + sys.exit(1) + # OK, now run the configuration edit r = Tk() -- cgit v1.2.3