Back to index

plone3  3.1.7
metadata.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ GenericSetup profile metadata
00014 
00015 $Id: metadata.py 81996 2007-11-27 21:46:16Z yuppie $
00016 """
00017 import os
00018 
00019 from utils import ImportConfiguratorBase, _getProductPath
00020 from utils import CONVERTER, DEFAULT, KEY
00021 
00022 METADATA_XML = 'metadata.xml'
00023 
00024 class ProfileMetadata( ImportConfiguratorBase ):
00025     """ Extracts profile metadata from metadata.xml file.
00026     """
00027 
00028     def __init__( self, path, encoding=None, product=None ):
00029 
00030         # don't call the base class __init__ b/c we don't have (or need)
00031         # a site
00032 
00033         self._path = path
00034         if product is not None:
00035             # Handle relative paths
00036             try:
00037                 product_path = _getProductPath(product)
00038             except ValueError:
00039                 pass
00040             else:
00041                 self._path = os.path.join(product_path, path)
00042 
00043         self._encoding = encoding
00044 
00045     def __call__( self ):
00046         
00047         full_path = os.path.join( self._path, METADATA_XML )
00048         if not os.path.exists( full_path ):
00049             return {}
00050 
00051         file = open( full_path, 'r' )
00052         return self.parseXML( file.read() )
00053 
00054     def _getImportMapping( self ):
00055 
00056         return {
00057             'metadata':
00058             {'description': { CONVERTER: self._convertToUnique },
00059              'version': { CONVERTER: self._convertToUnique },
00060              'dependencies': { CONVERTER: self._convertToUnique },
00061              },
00062             'description':
00063             { '#text': { KEY: None, DEFAULT: '' },
00064               },
00065             'version':
00066             { '#text': { KEY: None },
00067               },
00068             'dependencies':
00069             {'dependency': { KEY: None },},
00070             'dependency':
00071             { '#text': { KEY: None },
00072               },
00073             }