rev 325 - in offlineimap/head: . debian offlineimap offlineimap/ui

[email protected] Mon, 6 Jan 2003 15:15:25 -0600 (CST)
Newsgroups gmane.mail.imap.offlineimap.subversion
Message-ID <[email protected]>
Author: jgoerzen
Date: 2003-01-06 15:15:22 -0600 (Mon, 06 Jan 2003)
New Revision: 325

Modified:
   offlineimap/head/debian/copyright
   offlineimap/head/offlineimap.conf
   offlineimap/head/offlineimap/CustomConfig.py
   offlineimap/head/offlineimap/accounts.py
   offlineimap/head/offlineimap/imapserver.py
   offlineimap/head/offlineimap/init.py
   offlineimap/head/offlineimap/mbnames.py
   offlineimap/head/offlineimap/ui/Curses.py
   offlineimap/head/offlineimap/ui/Tk.py
   offlineimap/head/offlineimap/ui/detector.py
Log:
Touched up the isactive tests.

Added defaults for many more options.


Modified: offlineimap/head/debian/copyright
==============================================================================
--- offlineimap/head/debian/copyright	(original)
+++ offlineimap/head/debian/copyright	Mon Jan  6 15:15:24 2003
@@ -4,7 +4,7 @@
 The original source can always be found at:
         ftp://ftp.debian.org/dists/unstable/main/source/
 
-Copyright (C) 2002  John Goerzen
+Copyright (C) 2002, 2003  John Goerzen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by

Modified: offlineimap/head/offlineimap/imapserver.py
==============================================================================
--- offlineimap/head/offlineimap/imapserver.py	(original)
+++ offlineimap/head/offlineimap/imapserver.py	Mon Jan  6 15:15:24 2003
@@ -266,7 +266,7 @@
         port = None
         if config.has_option(accountname, "remoteport"):
             port = config.getint(accountname, "remoteport")
-        ssl = config.getboolean(accountname, "ssl")
+        ssl = config.getdefaultboolean(accountname, "ssl", 0)
         usetunnel = config.has_option(accountname, "preauthtunnel")
         reference = '""'
         if config.has_option(accountname, "reference"):
@@ -292,5 +292,5 @@
                     passfile.close()
             IMAPServer.__init__(self, config, accountname,
                                 user, password, host, port, ssl,
-                                config.getint(accountname, "maxconnections"),
+                                config.getdefaultint(accountname, "maxconnections", 1),
                                 reference = reference)

Modified: offlineimap/head/offlineimap/accounts.py
==============================================================================
--- offlineimap/head/offlineimap/accounts.py	(original)
+++ offlineimap/head/offlineimap/accounts.py	Mon Jan  6 15:15:24 2003
@@ -130,7 +130,7 @@
             threadutil.threadsreset(folderthreads)
             mbnames.write()
             if not self.hold:
-                server.close()
+                self.server.close()
         finally:
             pass
     

Modified: offlineimap/head/offlineimap/CustomConfig.py
==============================================================================
--- offlineimap/head/offlineimap/CustomConfig.py	(original)
+++ offlineimap/head/offlineimap/CustomConfig.py	Mon Jan  6 15:15:24 2003
@@ -28,6 +28,19 @@
         else:
             return default
     
+    def getdefaultint(self, section, option, default, *args, **kwargs):
+        if self.has_option(section, option):
+            return apply(self.getint, [section, option] + list(args), kwargs)
+        else:
+            return default
+
+    def getdefaultboolean(self, section, option, default, *args, **kwargs):
+        if self.has_option(section, option):
+            return apply(self.getboolean, [section, option] + list(args),
+                         kwargs)
+        else:
+            return default
+
     def getmetadatadir(self):
         metadatadir = os.path.expanduser(self.getdefault("general", "metadata", "~/.offlineimap"))
         if not os.path.exists(metadatadir):

Modified: offlineimap/head/offlineimap/mbnames.py
==============================================================================
--- offlineimap/head/offlineimap/mbnames.py	(original)
+++ offlineimap/head/offlineimap/mbnames.py	Mon Jan  6 15:15:24 2003
@@ -50,7 +50,7 @@
     mblock.acquire()
     try:
         localeval = config.getlocaleval()
-        if not config.getboolean("mbnames", "enabled"):
+        if not config.getdefaultboolean("mbnames", "enabled", 0):
             return
         file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
         file.write(localeval.eval(config.get("mbnames", "header")))

Modified: offlineimap/head/offlineimap/init.py
==============================================================================
--- offlineimap/head/offlineimap/init.py	(original)
+++ offlineimap/head/offlineimap/init.py	Mon Jan  6 15:15:24 2003
@@ -86,7 +86,7 @@
         threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
     else:
         threadutil.initInstanceLimit("ACCOUNTLIMIT",
-                                     config.getint("general", "maxsyncaccounts"))
+                                     config.getdefaultint("general", "maxsyncaccounts", 1))
 
     for account in accounts:
         for instancename in ["FOLDER_" + account, "MSGCOPY_" + account]:
@@ -94,7 +94,7 @@
                 threadutil.initInstanceLimit(instancename, 1)
             else:
                 threadutil.initInstanceLimit(instancename,
-                                             config.getint(account, "maxconnections"))
+                                             config.getdefaultint(account, "maxconnections", 1))
 
     threadutil.initexitnotify()
     t = ExitNotifyThread(target=syncmaster.syncitall,

Modified: offlineimap/head/offlineimap/ui/detector.py
==============================================================================
--- offlineimap/head/offlineimap/ui/detector.py	(original)
+++ offlineimap/head/offlineimap/ui/detector.py	Mon Jan  6 15:15:24 2003
@@ -20,7 +20,8 @@
 import sys
 
 def findUI(config, chosenUI=None):
-    uistrlist = ['Tk.Blinkenlights', 'Tk.VerboseUI', 'TTY.TTYUI',
+    uistrlist = ['Tk.Blinkenlights', 'Tk.VerboseUI',
+                 'Curses.Blinkenlights', 'TTY.TTYUI',
                  'Noninteractive.Basic', 'Noninteractive.Quiet']
     namespace={}
     for ui in dir(offlineimap.ui):

Modified: offlineimap/head/offlineimap/ui/Tk.py
==============================================================================
--- offlineimap/head/offlineimap/ui/Tk.py	(original)
+++ offlineimap/head/offlineimap/ui/Tk.py	Mon Jan  6 15:15:24 2003
@@ -29,6 +29,8 @@
 from UIBase import UIBase
 from offlineimap.ui.Blinkenlights import BlinkenBase
 
+usabletest = None
+
 class PasswordDialog:
     def __init__(self, accountname, config, master=None, errmsg = None):
         self.top = Toplevel(master)
@@ -148,12 +150,17 @@
 
 class VerboseUI(UIBase):
     def isusable(s):
+        global usabletest
+        if usabletest != None:
+            return usabletest
+
         try:
             Tk().destroy()
-            return 1
+            usabletest = 1
         except TclError:
-            return 0
-
+            usabletest = 0
+        return usabletest
+    
     def _createTopWindow(self, doidlevac = 1):
         self.notdeleted = 1
         self.created = threading.Event()
@@ -414,20 +421,19 @@
         if config.has_option('ui.Tk.Blinkenlights', 'fontsize'):
             s.fontsize = config.getint('ui.Tk.Blinkenlights', 'fontsize')
 
+    def isusable(s):
+        return VerboseUI.isusable(s)
+
     def _createTopWindow(self):
         VerboseUI._createTopWindow(self, 0)
         #self.top.resizable(width = 0, height = 0)
         self.top.configure(background = 'black', bd = 0)
 
         widthmetric = tkFont.Font(family = self.fontfamily, size = self.fontsize).measure("0")
-        self.loglines = 5
-        if self.config.has_option("ui.Tk.Blinkenlights", "loglines"):
-            self.loglines = self.config.getint("ui.Tk.Blinkenlights",
-                                               "loglines")
-        self.bufferlines = 500
-        if self.config.has_option("ui.Tk.Blinkenlights", "bufferlines"):
-            self.bufferlines = self.config.getint("ui.Tk.Blinkenlights",
-                                                  "bufferlines")
+        self.loglines = self.config.getdefaultint("ui.Tk.Blinkenlights",
+                                                  "loglines", 5)
+        self.bufferlines = self.config.getdefaultint("ui.Tk.Blinkenlights",
+                                                     "bufferlines", 500)
         self.text = ScrolledText(self.top, bg = 'black', #scrollbar = 'y',
                                  font = (self.fontfamily, self.fontsize),
                                  bd = 0, highlightthickness = 0, setgrid = 0,
@@ -457,8 +463,7 @@
         s.top.config(menu = menubar)
         s.menubar = menubar
         s.text.see(END)
-        if s.config.has_option("ui.Tk.Blinkenlights", "showlog") and \
-           s.config.getboolean("ui.Tk.Blinkenlights", "showlog"):
+        if s.config.getdefaultboolean("ui.Tk.Blinkenlights", "showlog", 1):
             s._togglelog()
         s.gettf().setcolor('red')
         s.top.resizable(width = 0, height = 0)

Modified: offlineimap/head/offlineimap/ui/Curses.py
==============================================================================
--- offlineimap/head/offlineimap/ui/Curses.py	(original)
+++ offlineimap/head/offlineimap/ui/Curses.py	Mon Jan  6 15:15:24 2003
@@ -19,7 +19,7 @@
 from Blinkenlights import BlinkenBase
 from UIBase import UIBase
 from threading import *
-import thread, time
+import thread, time, sys, os
 from offlineimap import version, threadutil
 from offlineimap.threadutil import MultiLock
 
@@ -308,6 +308,32 @@
         s.gettf().setcolor('red')
         s._msg(version.banner)
         s.inputhandler.set_bgchar(s.keypress)
+
+    def isusable(s):
+        # Not a terminal?  Can't use curses.
+        if not sys.stdout.isatty() and sys.stdin.isatty():
+            return 0
+
+        # No TERM specified?  Can't use curses.
+        try:
+            if not len(os.environ['TERM']):
+                return 0
+        except: return 0
+
+        # ncurses doesn't want to start?  Can't use curses.
+        # This test is nasty because initscr() actually EXITS on error.
+        # grr.
+
+        pid = os.fork()
+        if pid:
+            # parent
+            return not os.WEXITSTATUS(os.waitpid(pid, 0)[1])
+        else:
+            # child
+            curses.initscr()
+            curses.endwin()
+            # If we didn't die by here, indicate success.
+            sys.exit(0)
 
     def keypress(s, key):
         if key > 255:

Modified: offlineimap/head/offlineimap.conf
==============================================================================
--- offlineimap/head/offlineimap.conf	(original)
+++ offlineimap/head/offlineimap.conf	Mon Jan  6 15:15:24 2003
@@ -38,7 +38,7 @@
 # Offlineimap can synchronize more the one account at a time.  If you
 # want to enable this feature, set the below value to something
 # greater than 1.  To force it to synchronize only one account at a
-# time, leave it at 1.
+# time, set it to 1.
 #
 
 maxsyncaccounts = 1