Back to index

plone3  3.1.7
Classes | Functions
Archetypes.Extensions.utils Namespace Reference

Classes

class  Extra

Functions

def install_additional_templates
def install_subskin
def install_types
def _getFtiAndDataFor
def install_actions
def install_indexes
def isPloneSite
def filterTypes
def setupEnvironment
def doubleCheckDefaultTypeActions
def installTypes
 The master installer.
def refreshReferenceCatalog

Class Documentation

class Archetypes::Extensions::utils::Extra
indexes extra properties holder

Definition at line 20 of file utils.py.


Function Documentation

def Archetypes.Extensions.utils._getFtiAndDataFor (   tool,
  typename,
  klassname,
  package_name 
) [private]
helper method for type info setting
   returns fti object from the types tool and the data created
   by process_types for the fti

Definition at line 158 of file utils.py.

00158 
00159 def _getFtiAndDataFor(tool, typename, klassname, package_name):
00160     """helper method for type info setting
00161        returns fti object from the types tool and the data created
00162        by process_types for the fti
00163     """
00164     t = getattr(tool, typename, None)
00165     if t is None:
00166         return None, None
00167     all_ftis = process_types(listTypes(package_name),
00168                              package_name)[2]
00169     for fti in all_ftis:
00170         if fti['id'] == klassname:
00171             fti['content_meta_type'] = fti['meta_type']
00172             return t, fti
00173     return t, None
00174     

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 353 of file utils.py.

00353 
00354 def doubleCheckDefaultTypeActions(self, ftypes):
00355     # rr: for some reason, AT's magic wrt adding the default type actions
00356     # stopped working when moving to CMF-2.0
00357     # Instead of trying to resurect the old way (which I tried but couldn't)
00358     # I make it brute force here
00359 
00360     typesTool = getToolByName(self, 'portal_types')
00361     defaultTypeActions = [ActionInformation(**action) for action in
00362                           base_factory_type_information[0]['actions']]
00363 
00364     for ftype in ftypes:
00365         portal_type = ftype.portal_type
00366         fti = typesTool.get(portal_type, None)
00367         if fti is None:
00368             continue
00369         actions = list(fti._actions)
00370         action_ids = [a.id for a in actions]
00371         prepend = []
00372         for a in defaultTypeActions:
00373             if a.id not in action_ids:
00374                 prepend.append(a.clone())
00375         if prepend:
00376             fti._actions = tuple(prepend + actions)
00377     

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.filterTypes (   self,
  out,
  types,
  package_name 
)

Definition at line 291 of file utils.py.

00291 
00292 def filterTypes(self, out, types, package_name):
00293     typesTool = getToolByName(self, 'portal_types')
00294 
00295     filtered_types = []
00296 
00297     for rti in types:
00298         t = rti['klass']
00299         name = rti['name']
00300         meta_type = rti['meta_type']
00301 
00302         isBaseObject = 0
00303         if IBaseObject.isImplementedByInstancesOf(t):
00304             isBaseObject = 1
00305         else:
00306             for k in t.__bases__:
00307                 if IBaseObject.isImplementedByInstancesOf(k):
00308                     isBaseObject = 1
00309                     break
00310 
00311         if isBaseObject:
00312             filtered_types.append(t)
00313         else:
00314             print >> out, ("%s doesnt implements IBaseObject. "
00315                            "Possible misconfiguration. "
00316                            "Check if your class has an "
00317                            "'__implements__ = IBaseObject' "
00318                            "(or IBaseContent, or IBaseFolder)" % repr(t))
00319 
00320     return filtered_types

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.install_actions (   self,
  out,
  types 
)

Definition at line 175 of file utils.py.

00175 
00176 def install_actions(self, out, types):
00177     typesTool = getToolByName(self, 'portal_types')
00178     for portal_type in types:
00179         ## rr: XXX TODO somehow the following doesn't do anymore what
00180         ## it used to do :-(
00181         fixActionsForType(portal_type, typesTool)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.install_additional_templates (   self,
  out,
  types 
)
Registers additionals templates for TemplateMixin classes.

Definition at line 23 of file utils.py.

00023 
00024 def install_additional_templates(self, out, types):
00025     """Registers additionals templates for TemplateMixin classes.
00026     """
00027     at = getToolByName(self, 'archetype_tool')
00028     
00029     for t in types:
00030         klass = t['klass']
00031         if ITemplateMixin.isImplementedByInstancesOf(klass):
00032             portal_type = klass.portal_type
00033             default_view = getattr(klass, 'default_view', 'base_view')
00034             suppl_views = getattr(klass, 'suppl_views', ())
00035             views = []
00036 
00037             if not default_view:
00038                 default_view = 'base_view'
00039 
00040             at.registerTemplate(default_view)
00041             views.append(default_view)
00042 
00043             for view in suppl_views:
00044                 at.registerTemplate(view)
00045                 views.append(view)
00046 
00047             at.bindTemplate(portal_type, views)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.install_indexes (   self,
  out,
  types 
)

Definition at line 182 of file utils.py.

00182 
00183 def install_indexes(self, out, types):
00184     portal_catalog = catalog = getToolByName(self, 'portal_catalog')
00185     for cls in types:
00186         if 'indexes' not in cls.installMode:
00187             continue
00188 
00189         for field in cls.schema.fields():
00190             if not field.index:
00191                 continue
00192 
00193             if isinstance(field.index, basestring):
00194                 index = (field.index,)
00195             elif isinstance(field.index, (tuple, list)):
00196                 index = field.index
00197             else:
00198                 raise SyntaxError("Invalid Index Specification %r"
00199                                   % field.index)
00200 
00201             for alternative in index:
00202                 installed = None
00203                 index_spec = alternative.split(':', 1)
00204                 use_column  = 0
00205                 if len(index_spec) == 2 and index_spec[1] in ('schema', 'brains'):
00206                     use_column = 1
00207                 index_spec = index_spec[0]
00208 
00209                 accessor = field.getIndexAccessorName()
00210 
00211                 parts = index_spec.split('|')
00212                 # we want to be able to specify which catalog we want to use
00213                 # for each index. syntax is
00214                 # index=('member_catalog/:schema',)
00215                 # portal catalog is used by default if not specified
00216                 if parts[0].find('/') > 0:
00217                     str_idx = parts[0].find('/')
00218                     catalog_name = parts[0][:str_idx]
00219                     parts[0] = parts[0][str_idx+1:]
00220                     catalog = getToolByName(self, catalog_name)
00221                 else:
00222                     catalog = portal_catalog
00223                 
00224                 #####################
00225                 # add metadata column 
00226                 
00227                 # lets see if the catalog is itself an Archetype:
00228                 isArchetype = IBaseObject.isImplementedBy(catalog)
00229                 # archetypes based zcatalogs need to provide a different method 
00230                 # to list its schema-columns to not conflict with archetypes 
00231                 # schema                
00232                 hasNewWayMethod = hasattr(catalog, 'zcschema')
00233                 hasOldWayMethod = not isArchetype and hasattr(catalog, 'schema')
00234                 notInNewWayResults = hasNewWayMethod and accessor not in catalog.zcschema()
00235                 notInOldWayResults = hasOldWayMethod and accessor not in catalog.schema()
00236                 if use_column and (notInNewWayResults or notInOldWayResults):
00237                     try:
00238                         catalog.addColumn(accessor)
00239                     except:
00240                         import traceback
00241                         traceback.print_exc(file=out)
00242 
00243                 ###########
00244                 # add index
00245                 
00246                 # if you want to add a schema field without an index
00247                 #if not parts[0]:
00248                 #    continue
00249 
00250                 for itype in parts:
00251                     extras = itype.split(',')
00252                     if len(extras) > 1:
00253                         itype = extras[0]
00254                         props = Extra()
00255                         for extra in extras[1:]:
00256                             name, value = extra.split('=')
00257                             setattr(props, name.strip(), value.strip())
00258                     else:
00259                         props = None
00260                     try:
00261                         #Check for the index and add it if missing
00262                         catalog.addIndex(accessor, itype,
00263                                          extra=props)
00264                         catalog.manage_reindexIndex(ids=(accessor,))
00265                     except:
00266                         # FIXME: should only catch "Index Exists"
00267                         # damned string exception !
00268                         pass
00269                     else:
00270                         installed = 1
00271                         break
00272 
00273                 if installed:
00274                     break
00275 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.install_subskin (   self,
  out,
  globals = types_globals,
  product_skins_dir = 'skins' 
)

Definition at line 48 of file utils.py.

00048 
00049 def install_subskin(self, out, globals=types_globals, product_skins_dir='skins'):
00050     skinstool=getToolByName(self, 'portal_skins')
00051 
00052     product = getPackageName(globals)
00053     registry_key = "%s:%s" % (product, product_skins_dir)
00054     registered_directories = manage_listAvailableDirectories()
00055     if registry_key not in registered_directories:
00056         try:
00057             registerDirectory(product_skins_dir, globals)
00058         except OSError, ex:
00059             if ex.errno == 2: # No such file or directory
00060                 return
00061             raise
00062     try:
00063         addDirectoryViews(skinstool, product_skins_dir, globals)
00064     except BadRequestException, e:
00065         # TODO: find a better way to do this, but that seems not feasible
00066         #      until Zope stops using string exceptions
00067         if str(e).endswith(' is reserved.'):
00068             # trying to use a reserved identifier, let the user know
00069             #
00070             # remember the cmf reserve ids of objects in the root of the
00071             # portal !
00072             raise
00073         # directory view has already been added
00074         pass
00075 
00076     fullProductSkinsPath = os.path.join(package_home(globals), product_skins_dir)
00077     files = os.listdir(fullProductSkinsPath)
00078     for productSkinName in files:
00079         # skip directories with a dot or special dirs
00080         # or maybe just startswith('.')?
00081         if '.' in productSkinName or productSkinName in ('CVS', '_svn', '{arch}'):
00082             continue
00083         if isdir(join(fullProductSkinsPath, productSkinName)):
00084             for skinName in skinstool.getSkinSelections():
00085                 path = skinstool.getSkinPath(skinName)
00086                 path = [i.strip() for i in  path.split(',')]
00087                 try:
00088                     if productSkinName not in path:
00089                         path.insert(path.index('custom') +1, productSkinName)
00090                 except ValueError:
00091                     if productSkinName not in path:
00092                         path.append(productSkinName)
00093                 path = ','.join(path)
00094                 skinstool.addSkinSelection(skinName, path)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.install_types (   self,
  out,
  types,
  package_name 
)

Definition at line 95 of file utils.py.

00095 
00096 def install_types(self, out, types, package_name):
00097     typesTool = getToolByName(self, 'portal_types')
00098     folderish = []
00099     for klass in types:
00100         try:
00101             typesTool._delObject(klass.portal_type)
00102         except:
00103             pass
00104 
00105         typeinfo_name = "%s: %s (%s)" % (package_name, klass.__name__,
00106                                          klass.meta_type)
00107 
00108         # get the meta type of the FTI from the class, use the
00109         # default FTI as default
00110         fti_meta_type = getattr(klass, '_at_fti_meta_type', None)
00111         if not fti_meta_type or fti_meta_type == 'simple item':
00112             ## rr: explicitly catching 'simple item' because
00113             ## CMF 2.0 removed the meta_type from the basic TIs :-(
00114             ## seems to me, 'manage_addTypeInformation' is just broken
00115             fti_meta_type = 'Factory-based Type Information'
00116         try:
00117             typesTool.manage_addTypeInformation(fti_meta_type,
00118                                                 id=klass.portal_type,
00119                                                 typeinfo_name=typeinfo_name)
00120         except ValueError:
00121             print "failed to add '%s'" %  klass.portal_type
00122             print "fti_meta_type = %s" % fti_meta_type
00123         ## rr: from CMF-2.0 onward typeinfo_name from the call above
00124         ## is ignored and we have to do some more work
00125         t, fti = _getFtiAndDataFor(typesTool, klass.portal_type, klass.__name__, package_name)
00126         if t and fti:
00127             t.manage_changeProperties(**fti)
00128             if fti.has_key('aliases'):
00129                 t.setMethodAliases(fti['aliases'])
00130         
00131         # Set the human readable title explicitly
00132         if t:
00133             t.title = klass.archetype_name
00134 
00135         # If the class appears folderish and the 'use_folder_tabs' is
00136         # not set to a false value, then we add the portal_type to
00137         # Plone's 'use_folder_tabs' property
00138         use_folder_tabs = klass.isPrincipiaFolderish and \
00139                           getattr(klass, 'use_folder_tabs', 1)
00140         if use_folder_tabs:
00141             folderish.append(klass.portal_type)
00142     if folderish:
00143         pt = getToolByName(self, 'portal_properties', None)
00144         if pt is None:
00145             return
00146         sp = getattr(pt, 'site_properties', None)
00147         if sp is None:
00148             return
00149         props = ('use_folder_tabs', 'typesLinkToFolderContentsInFC')
00150         for prop in props:
00151             folders = sp.getProperty(prop, None)
00152             if folders is None:
00153                 continue
00154             folders = list(folders)
00155             folders.extend(folderish)
00156             folders = tuple(dict(zip(folders, folders)).keys())
00157             sp._updateProperty(prop, folders)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.utils.installTypes (   self,
  out,
  types,
  package_name,
  globals = types_globals,
  product_skins_dir = 'skins',
  require_dependencies = True,
  refresh_references = False,
  install_deps = True 
)

The master installer.

Use this for your site with your types

Definition at line 382 of file utils.py.

00382 
00383                  install_deps=True):
00384     """Use this for your site with your types"""
00385     ftypes = filterTypes(self, out, types, package_name)
00386     install_types(self, out, ftypes, package_name)
00387     # Pass the unfiltered types into setup as it does that on its own
00388     setupEnvironment(self, out, types, package_name,
00389                      globals, product_skins_dir, require_dependencies,
00390                      install_deps)
00391     ## rr: sometimes the default actions are still missing
00392     doubleCheckDefaultTypeActions(self, ftypes)
00393     if refresh_references and ftypes:
00394         rc = getToolByName(self, REFERENCE_CATALOG)
00395         rc.manage_rebuildCatalog()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 276 of file utils.py.

00276 
00277 def isPloneSite(self):
00278     # we should just define a single attr for this
00279     if self.__class__.__name__ == "PloneSite":
00280         return 1
00281     for base in self.__class__.__bases__:
00282         if base.__name__ == "PloneSite":
00283             return 1
00284     if 'plone_utils' in self.objectIds():
00285         # Possibly older PloneSite
00286         # It may be risky to assert this, but the user should
00287         # have upgrade anyway, so its his fault :)
00288         return 1
00289     return 0
00290 

def Archetypes.Extensions.utils.refreshReferenceCatalog (   self,
  out,
  types = None,
  package_name = None,
  ftypes = None 
)
refresh the reference catalog to reindex objects after reinstalling a
AT based product.

This may take a very long time but it seems to be required under some
circumstances.

Definition at line 396 of file utils.py.

00396 
00397 def refreshReferenceCatalog(self, out, types=None, package_name=None, ftypes=None):
00398     """refresh the reference catalog to reindex objects after reinstalling a
00399     AT based product.
00400     
00401     This may take a very long time but it seems to be required under some
00402     circumstances.
00403     """
00404     assert package_name
00405 
00406     if ftypes is None:
00407         ftypes = filterTypes(self, out, types, package_name)
00408 
00409     if not ftypes and not types:
00410         # no types to install
00411         return
00412 
00413     rc = getToolByName(self, REFERENCE_CATALOG)
00414     mt = tuple([t.meta_type for t in ftypes])
00415     
00416     # because manage_catalogFoundItems sucks we have to do it on our own ...
00417     func    = rc.catalog_object
00418     obj     = self
00419     path    = '/'.join(obj.getPhysicalPath())
00420     REQUEST = self.REQUEST
00421 
00422     rc.ZopeFindAndApply(obj,
00423                         obj_metatypes=mt,
00424                         search_sub=1,
00425                         REQUEST=REQUEST,
00426                         apply_func=func,
00427                         apply_path=path)

Here is the call graph for this function:

def Archetypes.Extensions.utils.setupEnvironment (   self,
  out,
  types,
  package_name,
  globals = types_globals,
  product_skins_dir = 'skins',
  require_dependencies = True,
  install_deps = 1 
)

Definition at line 326 of file utils.py.

00326 
00327                      install_deps=1):
00328 
00329     if install_deps:
00330         qi=getToolByName(self, 'portal_quickinstaller', None)
00331         if require_dependencies:
00332             if not qi.isProductInstalled('CMFFormController'):
00333                 qi.installProduct('CMFFormController',locked=1)
00334                 print >>out, 'Installing CMFFormController'
00335             if not qi.isProductInstalled('MimetypesRegistry'):
00336                 qi.installProduct('MimetypesRegistry')
00337                 print >>out, 'Installing MimetypesRegistry'
00338             if not qi.isProductInstalled('PortalTransforms'):
00339                 qi.installProduct('PortalTransforms')
00340                 print >>out, 'Installing PortalTransforms'
00341             if not qi.isProductInstalled('Archetypes'):
00342                 qi.installProduct('Archetypes')
00343                 print >>out, 'Installing Archetypes'
00344 
00345     if product_skins_dir:
00346         install_subskin(self, out, globals, product_skins_dir)
00347 
00348     install_additional_templates(self, out, types)
00349 
00350     ftypes = filterTypes(self, out, types, package_name)
00351     install_indexes(self, out, ftypes)
00352     install_actions(self, out, ftypes)

Here is the call graph for this function:

Here is the caller graph for this function: