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