Back to index

plone3  3.1.7
modulealiases.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 General 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 """Module aliases for unpickling
00020 
00021 The dotted class path of most persistent classes were changed before version 1.0
00022 beta. This module creates aliases using sys.modules for unpickling old objects.
00023 """
00024 __author__  = ''
00025 __docformat__ = 'restructuredtext'
00026 
00027 import sys
00028 from types import ModuleType
00029 
00030 from Products.ATContentTypes import content
00031 from Products.ATContentTypes.content import link
00032 from Products.ATContentTypes.content import image
00033 from Products.ATContentTypes.content import document
00034 from Products.ATContentTypes.content import file
00035 from Products.ATContentTypes.content import event
00036 from Products.ATContentTypes.content import newsitem
00037 from Products.ATContentTypes.content import folder
00038 from Products.ATContentTypes.content import favorite
00039 from Products.ATContentTypes.content import topic
00040 
00041 from Products.ATContentTypes import criteria
00042 from Products.ATContentTypes.criteria import boolean
00043 from Products.ATContentTypes.criteria import date
00044 from Products.ATContentTypes.criteria import daterange
00045 # do not import the module with a builtin name 'list' as this makes a mess
00046 from Products.ATContentTypes.criteria import list as list_criteria
00047 from Products.ATContentTypes.criteria import portaltype
00048 from Products.ATContentTypes.criteria import reference
00049 from Products.ATContentTypes.criteria import selection
00050 from Products.ATContentTypes.criteria import simpleint
00051 from Products.ATContentTypes.criteria import simplestring
00052 from Products.ATContentTypes.criteria import sort
00053 from Products.ATContentTypes import interface
00054 
00055 def createModuleAliases():
00056     """Creates module aliases in sys.modules
00057 
00058     Aliases are created for Products.ATContentTypes.types and all modules below
00059     it which contain classes with persistent objects (content types) but for
00060     modules with base classes and schemata.
00061 
00062     It might look a little bit tricky but it's very easy. The method is
00063     iterating over all modules in the module name space (globals) and creating
00064     aliases only forthoses modules which are modules with the module name starting with
00065     Products.ATContentTypes. All these modules have a module level var called
00066     "__old_name__".
00067     """
00068     for module in globals().values():
00069         if type(module) is not ModuleType:
00070             # not a module
00071             continue
00072         name = module.__name__
00073         if not name.startswith('Products.ATContentTypes'):
00074             # not a module inside ATCT
00075             continue
00076         old_name = getattr(module, '__old_name__', None)
00077         if old_name is None:
00078             continue
00079         sys.modules[old_name] = module
00080 
00081 # Aliase for EXIF classes
00082 import exif
00083 sys.modules['Products.ATContentTypes.lib.exif'] = exif
00084 sys.modules['Products.ATContentTypes.z3.interfaces'] = interface
00085 
00086 createModuleAliases()