Back to index

plone3  3.1.7
config.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU Gefneral Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ATCT ZConfig loader
00020 
00021 """
00022 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 import os
00026 
00027 from ZConfig.loader import ConfigLoader
00028 from Globals import INSTANCE_HOME
00029 from Products.ATContentTypes.configuration.schema import atctSchema
00030 
00031 # directories
00032 INSTANCE_ETC = os.path.join(INSTANCE_HOME, 'etc')
00033 _here = os.path.dirname(__file__)
00034 ATCT_HOME = os.path.dirname(os.path.abspath(os.path.join(_here)))
00035 ATCT_ETC = os.path.join(ATCT_HOME, 'etc')
00036 
00037 # files
00038 CONFIG_NAME = 'atcontenttypes.conf'
00039 INSTANCE_CONFIG = os.path.join(INSTANCE_ETC, CONFIG_NAME)
00040 ATCT_CONFIG = os.path.join(ATCT_ETC, CONFIG_NAME)
00041 ATCT_CONFIG_IN = os.path.join(ATCT_ETC, CONFIG_NAME+'.in')
00042 
00043 # check files for existence
00044 if not os.path.isfile(INSTANCE_CONFIG):
00045     INSTANCE_CONFIG = None
00046 if not os.path.isfile(ATCT_CONFIG):
00047     ATCT_CONFIG = None
00048 if not os.path.isfile(ATCT_CONFIG_IN):
00049     raise RuntimeError("Unable to find configuration file at %s" % 
00050                         ATCT_CONFIG_IN)
00051 FILES = (INSTANCE_CONFIG, ATCT_CONFIG, ATCT_CONFIG_IN,)
00052 
00053 # config
00054 zconf, handler, conf_file = None, None, None
00055 def loadConfig(files, schema=atctSchema, overwrite=False):
00056     """Config loader
00057     
00058     The config loader tries to load the first existing file
00059     """
00060     global zconf, handler, conf_file
00061     if not isinstance(files, (tuple, list)):
00062         files = (files, )
00063     if zconf is not None and not overwrite:
00064         raise RuntimeError, 'Configuration is already loaded'
00065     for file in files:
00066         if file is not None:
00067             if not os.path.exists(file):
00068                 raise RuntimeError, '%s does not exist' % file
00069             conf_file = file
00070             zconf, handler = ConfigLoader(schema).loadURL(conf_file)
00071             break
00072 
00073 
00074 loadConfig(FILES)
00075 
00076 __all__ = ('zconf', 'handler', 'conf_file')