[Zope-Checkins] CVS: Zope/lib/python/App - config.py:1.1 ApplicationManager.py:1.86 Extensions.py:1.21 ImageFile.py:1.19 Product.py:1.60 special_dtml.py:1.25 version_txt.py:1.9

Fred L. Drake, Jr. fred@zope.com
Tue, 11 Feb 2003 12:17:36 -0500


Update of /cvs-repository/Zope/lib/python/App
In directory cvs.zope.org:/tmp/cvs-serv22003/lib/python/App

Modified Files:
	ApplicationManager.py Extensions.py ImageFile.py Product.py 
	special_dtml.py version_txt.py 
Added Files:
	config.py 
Log Message:
Add the App.config module and use the API it exports to get configuration
values.


=== Added File Zope/lib/python/App/config.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

"""Simple access to configuration values.

The configuration values are represented as a single object with
attributes for each bit of information.
"""

_config = None

def getConfiguration():
    """Return the global Zope configuration object.

    If a configuration hasn't been set yet, generates a simple
    configuration object and uses that.  Once generated, it may not be
    overridden by calling ``setConfiguration()``.
    """
    if _config is None:
        setConfiguration(DefaultConfiguration())
    return _config

def setConfiguration(cfg):
    """Set the global configuration object.

    Legacy sources of common configuraiton values are updated to
    reflect the new configuration; this may be removed in some future
    version.
    """
    global _config
    _config = cfg

    from App import FindHomes
    import __builtin__
    __builtin__.CLIENT_HOME = FindHomes.CLIENT_HOME = cfg.clienthome
    __builtin__.INSTANCE_HOME = FindHomes.INSTANCE_HOME = cfg.instancehome
    __builtin__.SOFTWARE_HOME = FindHomes.SOFTWARE_HOME = cfg.softwarehome
    __builtin__.ZOPE_HOME = FindHomes.ZOPE_HOME = cfg.zopehome

    import sys
    if "Globals" in sys.modules:
        # XXX We *really* want to avoid this if Globals hasn't already
        # been imported, due to circular imports.  ;-(
        import Globals
        Globals.data_dir = cfg.clienthome
        # Globals does not export CLIENT_HOME
        Globals.INSTANCE_HOME = cfg.instancehome
        Globals.SOFTWARE_HOME = cfg.softwarehome
        Globals.ZOPE_HOME = cfg.zopehome

class DefaultConfiguration:
    def __init__(self):
        from App import FindHomes
        self.clienthome = FindHomes.CLIENT_HOME
        self.instancehome = FindHomes.INSTANCE_HOME
        self.softwarehome = FindHomes.SOFTWARE_HOME
        self.zopehome = FindHomes.ZOPE_HOME


=== Zope/lib/python/App/ApplicationManager.py 1.85 => 1.86 ===
--- Zope/lib/python/App/ApplicationManager.py:1.85	Wed Nov 13 05:38:38 2002
+++ Zope/lib/python/App/ApplicationManager.py	Tue Feb 11 12:17:04 2003
@@ -22,6 +22,7 @@
 from DavLockManager import DavLockManager
 from DateTime.DateTime import DateTime
 from OFS import SimpleItem
+from App.config import getConfiguration
 from App.Dialogs import MessageDialog
 from Product import ProductFolder
 from version_txt import version_txt
@@ -374,7 +375,8 @@
         isdir=os.path.isdir
         exists=os.path.exists
 
-        product_dir=path_join(SOFTWARE_HOME,'Products')
+        cfg = getConfiguration()
+        product_dir=path_join(cfg.softwarehome,'Products')
         product_names=os.listdir(product_dir)
         product_names.sort()
         info=[]
@@ -424,16 +426,16 @@
             REQUEST['RESPONSE'].redirect(REQUEST['URL1']+'/manage_main')
 
     def getSOFTWARE_HOME(self):
-        return SOFTWARE_HOME
+        return getConfiguration().softwarehome
 
     def getZOPE_HOME(self):
-        return ZOPE_HOME
+        return getConfiguration().zopehome
 
     def getINSTANCE_HOME(self):
-        return INSTANCE_HOME
+        return getConfiguration().instancehome
 
     def getCLIENT_HOME(self):
-        return CLIENT_HOME
+        return getConfiguration().clienthome
 
     def objectIds(self, spec=None):
         """ this is a patch for pre-2.4 Zope installations. Such


=== Zope/lib/python/App/Extensions.py 1.20 => 1.21 ===
--- Zope/lib/python/App/Extensions.py:1.20	Mon Feb 10 13:26:03 2003
+++ Zope/lib/python/App/Extensions.py	Tue Feb 11 12:17:04 2003
@@ -69,9 +69,9 @@
       suffixes -- a sequences of file suffixes to check.
         By default, the name is used without a suffix.
 
-    The search takes on multiple homes which are INSTANCE_HOME,
-    the directory containing the directory containing SOFTWARE_HOME, and
-    possibly product areas.
+    The search takes on multiple homes which are the instance home,
+    the directory containing the directory containing the software
+    home, and possibly product areas.
     """
     d,n = path_split(name)
     if d: raise ValueError, (
@@ -86,8 +86,10 @@
                 r = _getPath(product_dir, os.path.join(p, prefix), n, suffixes)
                 if r is not None: return r
 
-    sw=path_split(path_split(SOFTWARE_HOME)[0])[0]
-    for home in (INSTANCE_HOME, sw):
+    import App.config
+    cfg = App.config.getConfiguration()
+    sw=os.path.dirname(os.path.dirname(cfg.softwarehome))
+    for home in (cfg.instancehome, sw):
         r=_getPath(home, prefix, name, suffixes)
         if r is not None: return r
 
@@ -98,7 +100,7 @@
               ):
 
     # The use of modules here is not thread safe, however, there is
-    # no real harm in a rece condition here.  If two threads
+    # no real harm in a race condition here.  If two threads
     # update the cache, then one will have simply worked a little
     # harder than need be.  So, in this case, we won't incur
     # the expense of a lock.
@@ -117,7 +119,6 @@
             "The specified module, <em>%s</em>, couldn't be found." % module)
 
     __traceback_info__=p, module
-
 
     base, ext = os.path.splitext(p)
     if ext=='.pyc':


=== Zope/lib/python/App/ImageFile.py 1.18 => 1.19 ===
--- Zope/lib/python/App/ImageFile.py:1.18	Wed Aug 14 17:31:40 2002
+++ Zope/lib/python/App/ImageFile.py	Tue Feb 11 12:17:04 2003
@@ -14,21 +14,23 @@
 
 __version__='$Revision$'[11:-2]
 
+import os
+import time
+
+from App.config import getConfiguration
 from OFS.content_types import guess_content_type
 from Globals import package_home
 from Common import rfc1123_date
 from DateTime import DateTime
-from time import time
-from os import stat
 import Acquisition
 import Globals
-import  os
 
 class ImageFile(Acquisition.Explicit):
     """Image objects stored in external files."""
 
     def __init__(self,path,_prefix=None):
-        if _prefix is None: _prefix=SOFTWARE_HOME
+        if _prefix is None:
+            _prefix=getConfiguration().softwarehome
         elif type(_prefix) is not type(''):
             _prefix=package_home(_prefix)
         path = os.path.join(_prefix, path)
@@ -50,7 +52,7 @@
         else:
             self.content_type='image/%s' % path[path.rfind('.')+1:]
         self.__name__=path[path.rfind('/')+1:]
-        self.lmt=float(stat(path)[8]) or time()
+        self.lmt=float(os.stat(path)[8]) or time.time()
         self.lmh=rfc1123_date(self.lmt)
 
 


=== Zope/lib/python/App/Product.py 1.59 => 1.60 ===
--- Zope/lib/python/App/Product.py:1.59	Tue Aug 20 15:37:52 2002
+++ Zope/lib/python/App/Product.py	Tue Feb 11 12:17:04 2003
@@ -47,6 +47,7 @@
 from HelpSys.HelpSys import ProductHelp
 import RefreshFuncs
 from AccessControl import Unauthorized
+from App.config import getConfiguration
 
 
 class ProductFolder(Folder):
@@ -207,7 +208,7 @@
         # Extensions
         pp=id+'.'
         lpp=len(pp)
-        ed=os.path.join(INSTANCE_HOME,'Extensions')
+        ed=os.path.join(getConfiguration().instancehome,'Extensions')
         if os.path.exists(ed):
             for name in os.listdir(ed):
                 suffix=''


=== Zope/lib/python/App/special_dtml.py 1.24 => 1.25 ===
--- Zope/lib/python/App/special_dtml.py:1.24	Wed Aug 14 17:31:41 2002
+++ Zope/lib/python/App/special_dtml.py	Tue Feb 11 12:17:04 2003
@@ -14,6 +14,7 @@
 import DocumentTemplate, Common, Persistence, MethodObject, Globals, os, sys
 from types import InstanceType
 from zLOG import LOG,WARNING
+from App.config import getConfiguration
 
 class HTML(DocumentTemplate.HTML,Persistence.Persistent,):
     "Persistent HTML Document Templates"
@@ -29,7 +30,7 @@
     _v_last_read=0
 
     def __init__(self,name,_prefix=None, **kw):
-        if _prefix is None: _prefix=SOFTWARE_HOME
+        if _prefix is None: _prefix=getConfiguration().softwarehome
         elif type(_prefix) is not type(''):
             _prefix=Common.package_home(_prefix)
         args=(self, os.path.join(_prefix, name + '.dtml'))


=== Zope/lib/python/App/version_txt.py 1.8 => 1.9 ===
--- Zope/lib/python/App/version_txt.py:1.8	Wed Aug 14 17:31:41 2002
+++ Zope/lib/python/App/version_txt.py	Tue Feb 11 12:17:04 2003
@@ -13,6 +13,8 @@
 
 import os,sys,re
 
+from App.config import getConfiguration
+
 v=sys.version_info
 
 _version_string = None
@@ -38,7 +40,8 @@
     global _version_string, _zope_version
     if _version_string is None:
         try:
-            s = open(os.path.join(SOFTWARE_HOME,'version.txt')).read()
+            cfg = getConfiguration()
+            s = open(os.path.join(cfg.softwarehome,'version.txt')).read()
             ss = re.sub("\(.*?\)\?","",s)
             ss = '%s, python %d.%d.%d, %s' % (ss,v[0],v[1],v[2],sys.platform)
             _version_string = ss