]> code.delx.au - offlineimap/commitdiff
/offlineimap/head: changeset 217
authorjgoerzen <jgoerzen>
Thu, 8 Aug 2002 20:03:36 +0000 (21:03 +0100)
committerjgoerzen <jgoerzen>
Thu, 8 Aug 2002 20:03:36 +0000 (21:03 +0100)
-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
offlineimap/head/offlineimap.1
offlineimap/head/offlineimap.py
offlineimap/head/offlineimap/imaplib.py
offlineimap/head/offlineimap/repository/Maildir.py
offlineimap/head/offlineimap/ui/TTY.py
offlineimap/head/offlineimap/ui/UIBase.py

index a13a10991b42fd334b36d6be0726f86b4057f9d0..5a4240fe0803806a2206618251cb9e0d60f27e38 100644 (file)
@@ -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 <jgoerzen@complete.org>  Thu,  8 Aug 2002 10:02:36 -0500
+
 offlineimap (3.2.2) unstable; urgency=low
 
   * Updated manual to show new Gray color.
index 38d3d3ac4c8e8d247aeab2f6306afbeb054ce9f3..eeaf85621be69394c80e3bc567e71cc991ef0a56 100644 (file)
@@ -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.  
index 8cb80de9b5d7d781277573bf558b3295101e1c65..6f8659e610617d3d5494a17ce744fb5b702d82ce 100644 (file)
@@ -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")
 
index 6ac8d081d76263844c79df2c4b50e65f91115dfa..7768f6ab47125651759127c9b4dbdb9c05edc021 100644 (file)
@@ -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').
index 4471d8c955c00afd9e96d23f6d50da6fb0f6de1a..24c6faedcf297721893057d9563b471f887580b9 100644 (file)
@@ -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)), \
index 5d6ffb6b4e5c5ed8b12a687ac60cb800824d7a97..e88991cae41ed918ab0f46232d6c2658be2e2599 100644 (file)
@@ -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):
index 2fd665b42eb503fd38b2abb0203d1cf347a01f87..e2550f1ffd55720ed4acda416f6a7513dfe9b760 100644 (file)
@@ -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.