rev 308 - in offlineimap/head/offlineimap: . repository folder ui

[email protected] Sun, 5 Jan 2003 11:07:59 -0600 (CST)
Newsgroups gmane.mail.imap.offlineimap.subversion
Message-ID <[email protected]>
Author: jgoerzen
Date: 2003-01-05 11:07:58 -0600 (Sun, 05 Jan 2003)
New Revision: 308

Modified:
   offlineimap/head/offlineimap/accounts.py
   offlineimap/head/offlineimap/folder/Base.py
   offlineimap/head/offlineimap/folder/IMAP.py
   offlineimap/head/offlineimap/folder/LocalStatus.py
   offlineimap/head/offlineimap/folder/Maildir.py
   offlineimap/head/offlineimap/repository/LocalStatus.py
   offlineimap/head/offlineimap/repository/Maildir.py
   offlineimap/head/offlineimap/ui/Curses.py
   offlineimap/head/offlineimap/ui/UIBase.py
Log:
More progress at debugging.  The curses blinkenlights is now working well,
though it still has an occasional tendency to corrupt the light display with
comments from the log.  I suspect a locking problem -- need to be more
strict with iolock I suspect.

Updated various modules to register the threads' account names, etc.



Modified: offlineimap/head/offlineimap/repository/LocalStatus.py
==============================================================================
--- offlineimap/head/offlineimap/repository/LocalStatus.py	(original)
+++ offlineimap/head/offlineimap/repository/LocalStatus.py	Sun Jan  5 11:07:59 2003
@@ -21,9 +21,10 @@
 import os
 
 class LocalStatusRepository(BaseRepository):
-    def __init__(self, directory):
+    def __init__(self, directory, accountname):
         self.directory = directory
         self.folders = None
+        self.accountname = accountname
 
     def getsep(self):
         return '.'
@@ -42,12 +43,12 @@
         retval = []
         for folder in os.listdir(self.directory):
             retval.append(folder.LocalStatus.LocalStatusFolder(self.directory,
-                                                               folder, self))
+                                                               folder, self, self.accountname))
         return retval
 
     def getfolder(self, foldername):
         return folder.LocalStatus.LocalStatusFolder(self.directory, foldername,
-                                                    self)
+                                                    self, self.accountname)
 
 
     

Modified: offlineimap/head/offlineimap/repository/Maildir.py
==============================================================================
--- offlineimap/head/offlineimap/repository/Maildir.py	(original)
+++ offlineimap/head/offlineimap/repository/Maildir.py	Sun Jan  5 11:07:59 2003
@@ -87,7 +87,7 @@
 
     def getfolder(self, foldername):
         return folder.Maildir.MaildirFolder(self.root, foldername,
-                                            self.getsep(), self)
+                                            self.getsep(), self, self.accountname)
     
     def _getfolders_scandir(self, root, extension = None):
         self.debug("_GETFOLDERS_SCANDIR STARTING. root = %s, extension = %s" \
@@ -131,7 +131,7 @@
                 self.debug("  foldername = %s" % foldername)
 
                 retval.append(folder.Maildir.MaildirFolder(self.root, foldername,
-                                                           self.getsep(), self))
+                                                           self.getsep(), self, self.accountname))
             if self.getsep() == '/':
                 # Check sub-directories for folders.
                 retval.extend(self._getfolders_scandir(root, foldername))

Modified: offlineimap/head/offlineimap/accounts.py
==============================================================================
--- offlineimap/head/offlineimap/accounts.py	(original)
+++ offlineimap/head/offlineimap/accounts.py	Sun Jan  5 11:07:59 2003
@@ -81,6 +81,7 @@
             
 class AccountSynchronizationMixin:
     def syncrunner(self):
+        self.ui.registerthread(self.name)
         self.ui.acct(self.name)
         if not self.refreshperiod:
             self.sync()
@@ -109,7 +110,7 @@
             localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(self.config.get(self.name, "localfolders")), self.name, self.config)
 
             # Connect to the local cache.
-            statusrepos = repository.LocalStatus.LocalStatusRepository(accountmetadata)
+            statusrepos = repository.LocalStatus.LocalStatusRepository(accountmetadata, self.name)
 
             self.ui.syncfolders(remoterepos, localrepos)
             remoterepos.syncfoldersto(localrepos)
@@ -139,6 +140,7 @@
                statusrepos):
     global mailboxes
     ui = UIBase.getglobalui()
+    ui.registerthread(accountname)
     # Load local folder.
     localfolder = localrepos.\
                   getfolder(remotefolder.getvisiblename().\

Modified: offlineimap/head/offlineimap/folder/Base.py
==============================================================================
--- offlineimap/head/offlineimap/folder/Base.py	(original)
+++ offlineimap/head/offlineimap/folder/Base.py	Sun Jan  5 11:07:59 2003
@@ -186,12 +186,14 @@
                 # Did not find any server to take this message.  Ignore.
                 pass
 
-    def copymessageto(self, uid, applyto):
+    def copymessageto(self, uid, applyto, register = 1):
         # Sometimes, it could be the case that if a sync takes awhile,
         # a message might be deleted from the maildir before it can be
         # synced to the status cache.  This is only a problem with
         # self.getmessage().  So, don't call self.getmessage unless
         # really needed.
+        if register:
+            UIBase.getglobalui().registerthread(self.getaccountname())
         UIBase.getglobalui().copyingmessage(uid, self, applyto)
         message = ''
         # If any of the destinations actually stores the message body,
@@ -233,7 +235,7 @@
                     thread.start()
                     threads.append(thread)
                 else:
-                    self.copymessageto(uid, applyto)
+                    self.copymessageto(uid, applyto, register = 0)
         for thread in threads:
             thread.join()
 

Modified: offlineimap/head/offlineimap/folder/LocalStatus.py
==============================================================================
--- offlineimap/head/offlineimap/folder/LocalStatus.py	(original)
+++ offlineimap/head/offlineimap/folder/LocalStatus.py	Sun Jan  5 11:07:59 2003
@@ -1,5 +1,5 @@
 # Local status cache virtual folder
-# Copyright (C) 2002 John Goerzen
+# Copyright (C) 2002 - 2003 John Goerzen
 # <[email protected]>
 #
 #    This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,7 @@
 magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
 
 class LocalStatusFolder(BaseFolder):
-    def __init__(self, root, name, repository):
+    def __init__(self, root, name, repository, accountname):
         self.name = name
         self.root = root
         self.sep = '.'
@@ -31,6 +31,10 @@
         self.repository = repository
         self.savelock = threading.Lock()
         self.doautosave = 1
+        self.accountname = accountname
+
+    def getaccountname(self):
+        return self.accountname
 
     def storesmessages(self):
         return 0

Modified: offlineimap/head/offlineimap/folder/Maildir.py
==============================================================================
--- offlineimap/head/offlineimap/folder/Maildir.py	(original)
+++ offlineimap/head/offlineimap/folder/Maildir.py	Sun Jan  5 11:07:59 2003
@@ -39,13 +39,17 @@
         return timeseq
 
 class MaildirFolder(BaseFolder):
-    def __init__(self, root, name, sep, repository):
+    def __init__(self, root, name, sep, repository, accountname):
         self.name = name
         self.root = root
         self.sep = sep
         self.uidfilename = os.path.join(self.getfullname(), "offlineimap.uidvalidity")
         self.messagelist = None
         self.repository = repository
+        self.accountname = accountname
+
+    def getaccountname(self):
+        return self.accountname
 
     def getfullname(self):
         return os.path.join(self.getroot(), self.getname())

Modified: offlineimap/head/offlineimap/folder/IMAP.py
==============================================================================
--- offlineimap/head/offlineimap/folder/IMAP.py	(original)
+++ offlineimap/head/offlineimap/folder/IMAP.py	Sun Jan  5 11:07:59 2003
@@ -39,6 +39,9 @@
         self.accountname = accountname
         self.repository = repository
 
+    def getaccountname(self):
+        return self.accountname
+
     def suggeststhreads(self):
         return 1
 

Modified: offlineimap/head/offlineimap/ui/UIBase.py
==============================================================================
--- offlineimap/head/offlineimap/ui/UIBase.py	(original)
+++ offlineimap/head/offlineimap/ui/UIBase.py	Sun Jan  5 11:07:59 2003
@@ -55,8 +55,9 @@
         """Provides a hint to UIs about which account this particular
         thread is processing."""
         if s.threadaccounts.has_key(threading.currentThread()):
-            raise ValueError, "Thread already registered (old %s, new %s)" % \
-                  (s.getthreadaccount(s), account)
+            raise ValueError, "Thread %s already registered (old %s, new %s)" %\
+                  (threading.currentThread().getName(),
+                   s.getthreadaccount(s), account)
         s.threadaccounts[threading.currentThread()] = account
 
     def unregisterthread(s, thr):
@@ -69,7 +70,7 @@
             thr = threading.currentThread()
         if s.threadaccounts.has_key(thr):
             return s.threadaccounts[thr]
-        return None
+        return '*Control'
 
     def debug(s, debugtype, msg):
         thisthread = threading.currentThread()

Modified: offlineimap/head/offlineimap/ui/Curses.py
==============================================================================
--- offlineimap/head/offlineimap/ui/Curses.py	(original)
+++ offlineimap/head/offlineimap/ui/Curses.py	Sun Jan  5 11:07:59 2003
@@ -84,19 +84,23 @@
         self.start()
 
 class CursesAccountFrame:
-    def __init__(s, master):
+    def __init__(s, master, accountname):
         s.c = master
         s.children = []
+        s.accountname = accountname
 
     def setwindow(s, window):
         s.window = window
-        location = 0
+        acctstr = '%15.15s: ' % s.accountname
+        s.window.addstr(0, 0, acctstr)
+        s.location = len(acctstr)
         for child in s.children:
-            child.update(window, 0, location)
-            location += 1
+            child.update(window, 0, s.location)
+            s.location += 1
 
     def getnewthreadframe(s):
-        tf = CursesThreadFrame(s.c, s.window, 0, len(s.children))
+        tf = CursesThreadFrame(s.c, s.window, 0, s.location)
+        s.location += 1
         s.children.append(tf)
         return tf
 
@@ -120,21 +124,32 @@
                          'orange': s.c.getpair(curses.COLOR_YELLOW, bg),
                          'yellow': curses.A_BOLD | s.c.getpair(curses.COLOR_YELLOW, bg),
                          'pink': curses.A_BOLD | s.c.getpair(curses.COLOR_RED, bg)}
-        s.setcolor('gray')
+        #s.setcolor('gray')
+        s.setcolor('black')
 
     def setcolor(self, color):
         self.color = self.colormap[color]
+        self.display()
+
+    def display(self):
         self.window.addstr(self.y, self.x, '.', self.color)
         self.window.refresh()
 
     def getcolor(self):
         return self.color
 
+    def update(self, window, y, x):
+        self.window = window
+        self.y = y
+        self.x = x
+        self.display()
+
     def setthread(self, newthread):
-        if newthread:
-            self.setcolor('gray')
-        else:
-            self.setcolor('black')
+        self.setcolor('black')
+        #if newthread:
+        #    self.setcolor('gray')
+        #else:
+        #    self.setcolor('black')
 
 class InputHandler:
     def __init__(s, util):
@@ -293,7 +308,7 @@
                 return s.af[accountname]
 
             # New one.
-            s.af[accountname] = CursesAccountFrame(s.c)
+            s.af[accountname] = CursesAccountFrame(s.c, accountname)
             #s.iolock.acquire()
             s.c.reset()
             s.setupwindows(dolock = 0)