/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.
This commit is contained in:
jgoerzen 2002-08-08 21:03:36 +01:00
parent 60ea05cf98
commit a6e85174fe
7 changed files with 60 additions and 15 deletions

View 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 offlineimap (3.2.2) unstable; urgency=low
* Updated manual to show new Gray color. * Updated manual to show new Gray color.

View File

@ -33,7 +33,7 @@ OfflineIMAP \- Powerful IMAP/Maildir synchronization and reader support
] ]
.\".br .\".br
[ [
.BI \-d .BI \-d \ debugtype[,debugtype...]
] ]
[ [
.BI \-o .BI \-o
@ -249,15 +249,25 @@ that you normally prefer not to.
Specifies a configuration file to use in lieu of the default, Specifies a configuration file to use in lieu of the default,
.I ~/.offlineimaprc. .I ~/.offlineimaprc.
.TP .TP
.BI \-d .BI \-d \ debugtype[,debugtype...]
Enables IMAP protocol stream and parsing debugging. This is useful if Enables debugging for OfflineIMAP. This is useful if
you are trying to track down a malfunction or figure out what is going 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 on under the hood. I suggest that you use this with
.BI \-1 .BI \-1
in order to make the results more sensible. Note that this output in order to make the results more sensible.
will contain full IMAP protocol in plain text, including passwords, so .IP
take care to remove that from the debugging output before sending it -d now requires one or more debugtypes, separated by commas. These
to anyone else. 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 .TP
.B \-o .B \-o
Run only once, ignoring any autorefresh setting in the config file. Run only once, ignoring any autorefresh setting in the config file.

View File

@ -19,6 +19,7 @@
from offlineimap import imaplib, imaputil, imapserver, repository, folder, mbnames, threadutil, version from offlineimap import imaplib, imaputil, imapserver, repository, folder, mbnames, threadutil, version
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
from offlineimap.ui import UIBase
import re, os, os.path, offlineimap, sys import re, os, os.path, offlineimap, sys
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from threading import * from threading import *
@ -29,11 +30,9 @@ if '--help' in sys.argv[1:]:
sys.stdout.write(version.cmdhelp + "\n") sys.stdout.write(version.cmdhelp + "\n")
sys.exit(0) 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] options[optlist[0]] = optlist[1]
if '-d' in options:
imaplib.Debug = 5
if '-h' in options: if '-h' in options:
sys.stdout.write(version.cmdhelp) sys.stdout.write(version.cmdhelp)
sys.stdout.write("\n") sys.stdout.write("\n")
@ -65,6 +64,12 @@ else:
ui = offlineimap.ui.detector.findUI(config) ui = offlineimap.ui.detector.findUI(config)
ui.init_banner() 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"): if '-o' in options and config.has_option("general", "autorefresh"):
config.remove_option("general", "autorefresh") config.remove_option("general", "autorefresh")

View File

@ -22,6 +22,7 @@ Public functions: Internaldate2tuple
__version__ = "2.52" __version__ = "2.52"
import binascii, re, socket, time, random, sys, os import binascii, re, socket, time, random, sys, os
import __main__
__all__ = ["IMAP4", "Internaldate2tuple", __all__ = ["IMAP4", "Internaldate2tuple",
"Int2AP", "ParseFlags", "Time2Internaldate"] "Int2AP", "ParseFlags", "Time2Internaldate"]
@ -987,8 +988,7 @@ class IMAP4:
if secs is None: if secs is None:
secs = time.time() secs = time.time()
tm = time.strftime('%M:%S', time.localtime(secs)) tm = time.strftime('%M:%S', time.localtime(secs))
sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s)) __main__.ui.debug('imap', ' %s.%02d %s' % (tm, (secs*100)%100, s))
sys.stderr.flush()
def _dump_ur(self, dict): def _dump_ur(self, dict):
# Dump untagged responses (in `dict'). # Dump untagged responses (in `dict').

View File

@ -58,7 +58,7 @@ class MaildirRepository(BaseRepository):
# makedirs will fail because the higher-up dir already exists. # makedirs will fail because the higher-up dir already exists.
# So, check to see if this is indeed the case. # 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. # Already exists. Sanity-check that it's not a Maildir.
for subdir in ['cur', 'new', 'tmp']: for subdir in ['cur', 'new', 'tmp']:
assert not os.path.isdir(os.path.join(foldername, subdir)), \ assert not os.path.isdir(os.path.join(foldername, subdir)), \

View File

@ -23,8 +23,7 @@ from threading import *
class TTYUI(UIBase): class TTYUI(UIBase):
def __init__(s, config, verbose = 0): def __init__(s, config, verbose = 0):
s.config = config UIBase.__init__(s, config, verbose)
s.verbose = verbose
s.iswaiting = 0 s.iswaiting = 0
def isusable(s): def isusable(s):

View File

@ -21,10 +21,14 @@ import offlineimap.version
import re, time, sys, traceback import re, time, sys, traceback
from StringIO import StringIO from StringIO import StringIO
debugtypes = {'imap': 'IMAP protocol debugging',
'maildir': 'Maildir repository debugging'}
class UIBase: class UIBase:
def __init__(s, config, verbose = 0): def __init__(s, config, verbose = 0):
s.verbose = verbose s.verbose = verbose
s.config = config s.config = config
s.debuglist = []
################################################## UTILS ################################################## UTILS
def _msg(s, msg): def _msg(s, msg):
@ -34,6 +38,26 @@ class UIBase:
def warn(s, msg): def warn(s, msg):
s._msg("WARNING: " + 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): def getnicename(s, object):
prelimname = str(object.__class__).split('.')[-1] prelimname = str(object.__class__).split('.')[-1]
# Strip off extra stuff. # Strip off extra stuff.