[PATCH 04/17] Move __version__ etc into __init__.py

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Nov 29 16:02:12 GMT 2010


Move central definitions into __init__.py and do away with version.py.
Some minor cleanup in command line option help.
More slight tweaks to version and help text strings

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/__init__.py    |   21 ++++++++++++++++++++-
 offlineimap/folder/IMAP.py |    4 ++--
 offlineimap/init.py        |   42 ++++++++++++++++++++++--------------------
 offlineimap/ui/Curses.py   |   13 +++++++------
 offlineimap/ui/UIBase.py   |    6 +++---
 offlineimap/version.py     |   35 -----------------------------------
 setup.py                   |   12 ++++++------
 7 files changed, 60 insertions(+), 73 deletions(-)
 delete mode 100644 offlineimap/version.py

diff --git a/offlineimap/__init__.py b/offlineimap/__init__.py
index c36246c..660dd16 100644
--- a/offlineimap/__init__.py
+++ b/offlineimap/__init__.py
@@ -1,5 +1,24 @@
 from offlineimap.init import OfflineImap
+__all__ = ['OfflineImap']
+#__all__ = ['ui', 'folder', 'repository', 'mbnames', 'threadutil', 'init']
+
+__productname__ = 'OfflineIMAP'
+__version__     = "6.3.0"
+__copyright__   = "Copyright (C) 2002 - 2010 John Goerzen"
+__author__      = "John Goerzen"
+__author_email__= "john at complete.org"
+__description__ = "Disconnected Universal IMAP Mail Synchronization/Reader Support"
+__bigcopyright__ = """%(__productname__)s %(__version__)s
+%(__copyright__)s <%(__author_email__)s>""" % locals()
+
+banner = __bigcopyright__ + """
+
+This software comes with ABSOLUTELY NO WARRANTY; see the file
+COPYING for details.  This is free software, and you are welcome
+to distribute it under the conditions laid out in COPYING."""
+
+__homepage__ = "http://github.com/spaetz/offlineimap"
+__license__  = "Licensed under the GNU GPL v2+ (v2 or any later version)."
 
-__all__ = ['ui', 'folder', 'repository', 'mbnames', 'threadutil', 'init']
 
 
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 1f63de1..7569781 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -18,9 +18,9 @@
 
 from Base import BaseFolder
 import imaplib
+import offlineimap
 from offlineimap import imaputil, imaplibutil
 from offlineimap.ui import UIBase
-from offlineimap.version import versionstr
 import rfc822, time, string, random, binascii, re
 from StringIO import StringIO
 from copy import copy
@@ -226,7 +226,7 @@ class IMAPFolder(BaseFolder):
         headervalue += binascii.hexlify(self.getname())
         headervalue += '-%d-' % long(time.time())
         headervalue += str(self.randomgenerator.random()).replace('.', '')
-        headervalue += '-v' + versionstr
+        headervalue += '-v' + offlineimap.__version__
         return (headername, headervalue)
 
     def savemessage_addheader(self, content, headername, headervalue):
diff --git a/offlineimap/init.py b/offlineimap/init.py
index 05bcec9..56667ce 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -56,11 +56,14 @@ class OfflineImap:
     def parse_commandline(self):
         """Parse the commandline and invoke everything"""
 
-        parser = OptionParser()
+        parser = OptionParser(version=offlineimap.banner,
+                              description="%s.\n\n%s" % 
+                              (offlineimap.__copyright__,
+                               offlineimap.__license__))
         parser.add_option("-1",
                   action="store_true", dest="singlethreading",
                   default=False,
-                  help="Disable all multithreading  operations and use "
+                  help="Disable all multithreading operations and use "
               "solely a single-thread sync. This effectively sets the "
               "maxsyncaccounts and all maxconnections configuration file "
               "variables to 1.")
@@ -69,25 +72,25 @@ class OfflineImap:
                   help="Sets OfflineIMAP into profile mode. The program "
               "will create DIR (it must not already exist). "
               "As it runs, Python profiling information about each "
-              "thread  is  logged  into  profiledir.  Please note: "
+              "thread is logged into profiledir. Please note: "
               "This option is present for debugging and optimization "
               "only, and should NOT be used unless you have a "
-              "specific reason to do so. It  will  significantly "
-              "slow  program  performance, may reduce reliability, "
+              "specific reason to do so. It will significantly "
+              "slow program performance, may reduce reliability, "
               "and can generate huge amounts of  data. This option "
-              "implies the -1 option.")
+              "implies the singlethreading option (-1).")
 
         parser.add_option("-a", dest="accounts", metavar="ACCOUNTS",
-                  help="""Overrides  the accounts section in the config file.
-              Lets you specify a particular  account  or  set  of
-              accounts  to sync without having to edit the config
-              file. You  might  use  this  to  exclude  certain accounts,
-              or to sync some accounts that you normally prefer not to.""")
+                  help="Overrides the accounts section in the config file. "
+              "Lets you specify a particular account or set of "
+              "accounts to sync without having to edit the config "
+              "file. You might use this to exclude certain accounts, "
+              "or to sync some accounts that you normally prefer not to.")
 
         parser.add_option("-c", dest="configfile", metavar="FILE",
                   default="~/.offlineimaprc",
                   help="Specifies a configuration file to use in lieu of "
-                       "the default, ~/.offlineimaprc.")
+                       "%default.")
 
         parser.add_option("-d", dest="debugtype", metavar="type1,[type2...]",
                   help=
@@ -98,7 +101,7 @@ class OfflineImap:
               "results more sensible. This option requires one or more "
               "debugtypes, separated by commas. "
               "These define what exactly  will be debugged, "
-              "and so far include two options: imap, "
+              "and so far include the options: imap, thread,"
               "maildir or ALL.  The imap option will enable IMAP protocol "
               "stream and parsing debugging.  Note that the output "
               "may contain passwords, so take care to remove  that "
@@ -111,11 +114,10 @@ class OfflineImap:
 
         parser.add_option("-f", dest="folders", metavar="folder1,[folder2...]",
                   help=
-              """Only sync the specified folders.  The "foldername"s
-              are    the   *untranslated*    foldernames.    This
-              command-line  option  overrides any  "folderfilter"
-              and "folderincludes" options  in the  configuration 
-              file.""")
+              "Only sync the specified folders. The 'folder's are the "
+              "*untranslated* foldernames. This command-line option "
+              "overrides any 'folderfilter' and 'folderincludes' options "
+              "in the configuration file.")
 
         parser.add_option("-k", dest="configoverride",
                   action="append",
@@ -124,7 +126,7 @@ class OfflineImap:
         """Override configuration file option.  If"section" is
               omitted, it defaults to "general".  Any underscores
               "_" in the section name are replaced with spaces:
-              for instance,  to override  option "autorefresh" in
+              for instance, to override option "autorefresh" in
               the "[Account Personal]" section in the config file
               one would use "-k Account_Personal:autorefresh=30".""")
 
@@ -137,7 +139,7 @@ class OfflineImap:
         parser.add_option("-q",
                   action="store_true", dest="quick",
                   default=False,
-                  help="Run  only quick synchronizations. Ignore any "
+                  help="Run only quick synchronizations. Ignore any "
                        "flag updates on IMAP servers.")
 
         parser.add_option("-u", dest="interface",
diff --git a/offlineimap/ui/Curses.py b/offlineimap/ui/Curses.py
index 285d3af..24c1534 100644
--- a/offlineimap/ui/Curses.py
+++ b/offlineimap/ui/Curses.py
@@ -20,7 +20,8 @@ from Blinkenlights import BlinkenBase
 from UIBase import UIBase
 from threading import *
 import thread, time, sys, os, signal, time
-from offlineimap import version, threadutil
+import offlineimap
+from offlineimap import threadutil
 from offlineimap.threadutil import MultiLock
 
 import curses, curses.panel, curses.textpad, curses.wrapper
@@ -321,7 +322,7 @@ class Blinkenlights(BlinkenBase, UIBase):
         s.setupwindows()
         s.inputhandler = InputHandler(s.c)
         s.gettf().setcolor('red')
-        s._msg(version.banner)
+        s._msg(offlineimap.banner)
         s.inputhandler.set_bgchar(s.keypress)
         signal.signal(signal.SIGWINCH, s.resizehandler)
         s.resizelock = Lock()
@@ -454,10 +455,10 @@ class Blinkenlights(BlinkenBase, UIBase):
         else:
             color = curses.A_REVERSE
         s.bannerwindow.bkgd(' ', color) # Fill background with that color
-        s.bannerwindow.addstr("%s %s" % (version.productname,
-                                         version.versionstr))
-        s.bannerwindow.addstr(0, s.bannerwindow.getmaxyx()[1] - len(version.copyright) - 1,
-                              version.copyright)
+        s.bannerwindow.addstr("%s %s" % (offlineimap.__productname__,
+                                         offlineimap.__version__))
+        s.bannerwindow.addstr(0, s.bannerwindow.getmaxyx()[1] - len(offlineimap.__copyright__) - 1,
+                              offlineimap.__copyright__)
         
         s.bannerwindow.noutrefresh()
 
diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py
index b1176fd..02e4202 100644
--- a/offlineimap/ui/UIBase.py
+++ b/offlineimap/ui/UIBase.py
@@ -61,8 +61,8 @@ class UIBase:
     def setlogfd(s, logfd):
         s.logfile = logfd
         logfd.write("This is %s %s\n" % \
-                    (offlineimap.version.productname,
-                     offlineimap.version.versionstr))
+                    (offlineimap.__productname__,
+                     offlineimap.__version__))
         logfd.write("Python: %s\n" % sys.version)
         logfd.write("Platform: %s\n" % sys.platform)
         logfd.write("Args: %s\n" % sys.argv)
@@ -174,7 +174,7 @@ class UIBase:
         where the UI should do its setup -- TK, for instance, would
         create the application window here."""
         if s.verbose >= 0:
-            s._msg(offlineimap.version.banner)
+            s._msg(offlineimap.banner)
 
     def connecting(s, hostname, port):
         if s.verbose < 0:
diff --git a/offlineimap/version.py b/offlineimap/version.py
deleted file mode 100644
index aca9310..0000000
--- a/offlineimap/version.py
+++ /dev/null
@@ -1,35 +0,0 @@
-productname = 'OfflineIMAP'
-versionstr = "6.2.0"
-
-versionlist = versionstr.split(".")
-major = versionlist[0]
-minor = versionlist[1]
-patch = versionlist[2]
-copyright = "Copyright (C) 2002 - 2009 John Goerzen"
-author = "John Goerzen"
-author_email = "jgoerzen at complete.org"
-description = "Disconnected Universal IMAP Mail Synchronization/Reader Support"
-bigcopyright = """%(productname)s %(versionstr)s
-%(copyright)s <%(author_email)s>""" % locals()
-
-banner = bigcopyright + """
-This software comes with ABSOLUTELY NO WARRANTY; see the file
-COPYING for details.  This is free software, and you are welcome
-to distribute it under the conditions laid out in COPYING."""
-
-homepage = "http://software.complete.org/offlineimap/"
-license = """Copyright (C) 2002 - 2009 John Goerzen <jgoerzen at complete.org>
-
-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
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA"""
diff --git a/setup.py b/setup.py
index 92fb1fd..f76a834 100644
--- a/setup.py
+++ b/setup.py
@@ -27,15 +27,15 @@ from distutils.core import setup
 import offlineimap.version
 
 setup(name = "offlineimap",
-      version = offlineimap.version.versionstr,
-      description = offlineimap.version.description,
-      author = offlineimap.version.author,
-      author_email = offlineimap.version.author_email,
-      url = offlineimap.version.homepage,
+      version = offlineimap.__version__,
+      description = offlineimap.__description__,
+      author = offlineimap.__author__,
+      author_email = offlineimap.__author_email__,
+      url = offlineimap.__homepage__,
       packages = ['offlineimap', 'offlineimap.folder',
                   'offlineimap.repository', 'offlineimap.ui'],
       scripts = ['bin/offlineimap'],
-      license = offlineimap.version.copyright + \
+      license = offlineimap.__copyright__ + \
                 ", Licensed under the GPL version 2"
 )
 
-- 
1.7.1





More information about the OfflineIMAP-project mailing list