aboutsummaryrefslogtreecommitdiffstats
path: root/fetchmailconf.py
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2021-03-13 17:31:08 +0100
committerMatthias Andree <matthias.andree@gmx.de>2021-03-13 17:31:08 +0100
commit7922f5b4830e105dae5aea3345f69ea2bdc7d304 (patch)
tree832f7b1a6db54aefc9209e95886e5ad0e0db72a8 /fetchmailconf.py
parent3b83ab934e79910d276485db99dbfc805e0fbac8 (diff)
downloadfetchmail-7922f5b4830e105dae5aea3345f69ea2bdc7d304.tar.gz
fetchmail-7922f5b4830e105dae5aea3345f69ea2bdc7d304.tar.bz2
fetchmail-7922f5b4830e105dae5aea3345f69ea2bdc7d304.zip
fetchmailconf: robustness fixes
Make sure fetchmailconf -V can complete without finding fetchmail or Tkinter. Make sure fetchmailconf -d can complete without Tkinter.
Diffstat (limited to 'fetchmailconf.py')
-rwxr-xr-xfetchmailconf.py35
1 files changed, 22 insertions, 13 deletions
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()