From a6e85174fe7c69d79c8dac54451e7a7661df3f9d Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Thu, 8 Aug 2002 21:03:36 +0100 Subject: [PATCH] /offlineimap/head: changeset 217 -d now takes a parameter to specify what kind of debugging to do. imaplib now does debugging through the UI system. UIBase now has a debugging process. --- offlineimap/head/debian/changelog | 7 ++++++ offlineimap/head/offlineimap.1 | 24 +++++++++++++------ offlineimap/head/offlineimap.py | 11 ++++++--- offlineimap/head/offlineimap/imaplib.py | 4 ++-- .../head/offlineimap/repository/Maildir.py | 2 +- offlineimap/head/offlineimap/ui/TTY.py | 3 +-- offlineimap/head/offlineimap/ui/UIBase.py | 24 +++++++++++++++++++ 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/offlineimap/head/debian/changelog b/offlineimap/head/debian/changelog index a13a109..5a4240f 100644 --- a/offlineimap/head/debian/changelog +++ b/offlineimap/head/debian/changelog @@ -1,3 +1,10 @@ +offlineimap (3.2.3) unstable; urgency=low + + * -d now takes a parameter: imap or maildir (or both) to specify + what type of debugging to do. + + -- John Goerzen Thu, 8 Aug 2002 10:02:36 -0500 + offlineimap (3.2.2) unstable; urgency=low * Updated manual to show new Gray color. diff --git a/offlineimap/head/offlineimap.1 b/offlineimap/head/offlineimap.1 index 38d3d3a..eeaf856 100644 --- a/offlineimap/head/offlineimap.1 +++ b/offlineimap/head/offlineimap.1 @@ -33,7 +33,7 @@ OfflineIMAP \- Powerful IMAP/Maildir synchronization and reader support ] .\".br [ -.BI \-d +.BI \-d \ debugtype[,debugtype...] ] [ .BI \-o @@ -249,15 +249,25 @@ that you normally prefer not to. Specifies a configuration file to use in lieu of the default, .I ~/.offlineimaprc. .TP -.BI \-d -Enables IMAP protocol stream and parsing debugging. This is useful if +.BI \-d \ debugtype[,debugtype...] +Enables debugging for OfflineIMAP. This is useful if you are trying to track down a malfunction or figure out what is going on under the hood. I suggest that you use this with .BI \-1 -in order to make the results more sensible. Note that this output -will contain full IMAP protocol in plain text, including passwords, so -take care to remove that from the debugging output before sending it -to anyone else. +in order to make the results more sensible. +.IP +-d now requires one or more debugtypes, separated by commas. These +define what exactly will be debugged, and so far include two options: +.B imap +and +.B maildir. +The +.B imap +option will enable IMAP protocol stream and parsing debugging. Note +that the output may contain passwords, so take care to remove that +from the debugging output before sending it to anyone else. The +.B maildir +option will enable debugging for certain Maildir operations. .TP .B \-o Run only once, ignoring any autorefresh setting in the config file. diff --git a/offlineimap/head/offlineimap.py b/offlineimap/head/offlineimap.py index 8cb80de..6f8659e 100644 --- a/offlineimap/head/offlineimap.py +++ b/offlineimap/head/offlineimap.py @@ -19,6 +19,7 @@ from offlineimap import imaplib, imaputil, imapserver, repository, folder, mbnames, threadutil, version from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread +from offlineimap.ui import UIBase import re, os, os.path, offlineimap, sys from ConfigParser import ConfigParser from threading import * @@ -29,11 +30,9 @@ if '--help' in sys.argv[1:]: sys.stdout.write(version.cmdhelp + "\n") sys.exit(0) -for optlist in getopt(sys.argv[1:], 'P:1oa:c:du:h')[0]: +for optlist in getopt(sys.argv[1:], 'P:1oa:c:d:u:h')[0]: options[optlist[0]] = optlist[1] -if '-d' in options: - imaplib.Debug = 5 if '-h' in options: sys.stdout.write(version.cmdhelp) sys.stdout.write("\n") @@ -65,6 +64,12 @@ else: ui = offlineimap.ui.detector.findUI(config) ui.init_banner() +if '-d' in options: + for debugtype in options['-d'].split(','): + ui.add_debug(debugtype.strip()) + if debugtype == 'imap': + imaplib.Debug = 5 + if '-o' in options and config.has_option("general", "autorefresh"): config.remove_option("general", "autorefresh") diff --git a/offlineimap/head/offlineimap/imaplib.py b/offlineimap/head/offlineimap/imaplib.py index 6ac8d08..7768f6a 100644 --- a/offlineimap/head/offlineimap/imaplib.py +++ b/offlineimap/head/offlineimap/imaplib.py @@ -22,6 +22,7 @@ Public functions: Internaldate2tuple __version__ = "2.52" import binascii, re, socket, time, random, sys, os +import __main__ __all__ = ["IMAP4", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate"] @@ -987,8 +988,7 @@ class IMAP4: if secs is None: secs = time.time() tm = time.strftime('%M:%S', time.localtime(secs)) - sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s)) - sys.stderr.flush() + __main__.ui.debug('imap', ' %s.%02d %s' % (tm, (secs*100)%100, s)) def _dump_ur(self, dict): # Dump untagged responses (in `dict'). diff --git a/offlineimap/head/offlineimap/repository/Maildir.py b/offlineimap/head/offlineimap/repository/Maildir.py index 4471d8c..24c6fae 100644 --- a/offlineimap/head/offlineimap/repository/Maildir.py +++ b/offlineimap/head/offlineimap/repository/Maildir.py @@ -58,7 +58,7 @@ class MaildirRepository(BaseRepository): # makedirs will fail because the higher-up dir already exists. # So, check to see if this is indeed the case. - if os.path.isdir(foldername): + if self.getsep() == '/' and os.path.isdir(foldername): # Already exists. Sanity-check that it's not a Maildir. for subdir in ['cur', 'new', 'tmp']: assert not os.path.isdir(os.path.join(foldername, subdir)), \ diff --git a/offlineimap/head/offlineimap/ui/TTY.py b/offlineimap/head/offlineimap/ui/TTY.py index 5d6ffb6..e88991c 100644 --- a/offlineimap/head/offlineimap/ui/TTY.py +++ b/offlineimap/head/offlineimap/ui/TTY.py @@ -23,8 +23,7 @@ from threading import * class TTYUI(UIBase): def __init__(s, config, verbose = 0): - s.config = config - s.verbose = verbose + UIBase.__init__(s, config, verbose) s.iswaiting = 0 def isusable(s): diff --git a/offlineimap/head/offlineimap/ui/UIBase.py b/offlineimap/head/offlineimap/ui/UIBase.py index 2fd665b..e2550f1 100644 --- a/offlineimap/head/offlineimap/ui/UIBase.py +++ b/offlineimap/head/offlineimap/ui/UIBase.py @@ -21,10 +21,14 @@ import offlineimap.version import re, time, sys, traceback from StringIO import StringIO +debugtypes = {'imap': 'IMAP protocol debugging', + 'maildir': 'Maildir repository debugging'} + class UIBase: def __init__(s, config, verbose = 0): s.verbose = verbose s.config = config + s.debuglist = [] ################################################## UTILS def _msg(s, msg): @@ -34,6 +38,26 @@ class UIBase: def warn(s, msg): s._msg("WARNING: " + msg) + def debug(s, debugtype, msg): + if debugtype in s.debuglist: + s._msg("DEBUG[%s]: %s" % (debugtype, msg)) + + def add_debug(s, debugtype): + global debugtypes + if debugtype in debugtypes: + if not debugtype in s.debuglist: + s.debuglist.append(debugtype) + s.debugging(debugtype) + else: + s.invaliddebug(debugtype) + + def debugging(s, debugtype): + global debugtypes + s._msg("Now debugging for %s: %s" % (debugtype, debugtypes[debugtype])) + + def invaliddebug(s, debugtype): + s.warn("Invalid debug type: %s" % debugtype) + def getnicename(s, object): prelimname = str(object.__class__).split('.')[-1] # Strip off extra stuff.