/offlineimap/head: changeset 218

Added maildir repository debug code
This commit is contained in:
jgoerzen 2002-08-08 21:15:30 +01:00
parent a6e85174fe
commit 09ed5e2fcc

View File

@ -20,6 +20,7 @@ from Base import BaseRepository
from offlineimap import folder, imaputil
from mailbox import Maildir
import os
import __main__
class MaildirRepository(BaseRepository):
def __init__(self, root, accountname, config):
@ -30,6 +31,11 @@ class MaildirRepository(BaseRepository):
self.folders = None
self.accountname = accountname
self.config = config
self.ui = __main__.ui
self.debug("MaildirRepository initialized, sep is " + repr(self.getsep()))
def debug(self, msg):
self.ui.debug('maildir', msg)
def getsep(self):
if self.config.has_option(self.accountname, 'sep'):
@ -38,6 +44,7 @@ class MaildirRepository(BaseRepository):
return '.'
def makefolder(self, foldername):
self.debug("makefolder called with arg " + repr(foldername))
# Do the chdir thing so the call to makedirs does not make the
# self.root directory (we'd prefer to raise an error in that case),
# but will make the (relative) paths underneath it. Need to use
@ -59,13 +66,16 @@ class MaildirRepository(BaseRepository):
# So, check to see if this is indeed the case.
if self.getsep() == '/' and os.path.isdir(foldername):
self.debug("makefolder: %s already is a directory" % 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)), \
"Tried to create folder %s but it already had dir %s" %\
(foldername, subdir)
else:
self.debug("makefolder: calling makedirs %s" % foldername)
os.makedirs(foldername, 0700)
self.debug("makefolder: creating cur, new, tmp")
for subdir in ['cur', 'new', 'tmp']:
os.mkdir(os.path.join(foldername, subdir), 0700)
# Invalidate the cache
@ -73,13 +83,15 @@ class MaildirRepository(BaseRepository):
os.chdir(oldcwd)
def deletefolder(self, foldername):
print "NOT YET IMPLEMENTED: DELETE FOLDER %s" % foldername
self.ui.warn("NOT YET IMPLEMENTED: DELETE FOLDER %s" % foldername)
def getfolder(self, foldername):
return folder.Maildir.MaildirFolder(self.root, foldername,
self.getsep())
def _getfolders_scandir(self, root, extension = None):
self.debug("_GETFOLDERS_SCANDIR STARTING. root = %s, extension = %s" \
% (root, extension))
# extension willl only be non-None when called recursively when
# getsep() returns '/'.
retval = []
@ -91,31 +103,40 @@ class MaildirRepository(BaseRepository):
else:
toppath = os.path.join(root, extension)
self.debug(" toppath = %s" % toppath)
# Iterate over directories in top.
for dirname in os.listdir(toppath):
self.debug(" *** top of loop")
self.debug(" dirname = %s" % dirname)
if dirname in ['cur', 'new', 'tmp', 'offlineimap.uidvalidity']:
self.debug(" skipping this dir (Maildir special)")
# Bypass special files.
continue
fullname = os.path.join(toppath, dirname)
self.debug(" fullname = %s" % fullname)
if not os.path.isdir(fullname):
self.debug(" skipping this entry (not a directory)")
# Not a directory -- not a folder.
continue
if not (os.path.isdir(os.path.join(fullname, 'cur')) and
os.path.isdir(os.path.join(fullname, 'new')) and
os.path.isdir(os.path.join(fullname, 'tmp'))):
# Doesn't have maildir stuff -- not a folder.
self.debug(" skipping this entry (doesn't have cur, new, tmp)")
continue
foldername = dirname
if extension != None:
foldername = os.path.join(extension, dirname)
self.debug(" foldername = %s" % foldername)
retval.append(folder.Maildir.MaildirFolder(self.root, foldername,
self.getsep()))
if self.getsep() == '/':
# Check sub-directories for folders.
retval.extend(self._getfolders_scandir(root, foldername))
return retval
def getfolders(self):