Back to index

plone3  3.1.7
Classes | Functions | Variables
GenericSetup.utils Namespace Reference

Classes

class  HandlerBase
class  ImportConfiguratorBase
class  ExportConfiguratorBase
class  _LineWrapper
class  _Element
class  PrettyDocument
class  NodeAdapterBase
class  BodyAdapterBase
class  XMLAdapterBase
class  ObjectManagerHelpers
class  PropertyManagerHelpers
class  MarkerInterfaceHelpers

Functions

def _getDottedName
def _resolveDottedName
def _extractDocstring
def exportObjects
def importObjects
def _computeTopologicalSort
def _getProductPath

Variables

tuple _pkgdir = package_home( globals() )
tuple _wwwdir = os.path.join( _pkgdir, 'www' )
tuple _xmldir = os.path.join( _pkgdir, 'xml' )
string I18NURI = 'http://xml.zope.org/namespaces/i18n'

Function Documentation

def GenericSetup.utils._computeTopologicalSort (   steps) [private]

Definition at line 827 of file utils.py.

00827 
00828 def _computeTopologicalSort( steps ):
00829     result = []
00830     graph = [ ( x[ 'id' ], x[ 'dependencies' ] ) for x in steps ]
00831 
00832     unresolved = []
00833 
00834     while 1:
00835         for node, edges in graph:
00836 
00837             after = -1
00838             resolved = 0
00839 
00840             for edge in edges:
00841 
00842                 if edge in result:
00843                     resolved += 1
00844                     after = max( after, result.index( edge ) )
00845             
00846             if len(edges) > resolved:
00847                 unresolved.append((node, edges))
00848             else:
00849                 result.insert( after + 1, node )
00850 
00851         if not unresolved:
00852             break
00853         if len(unresolved) == len(graph):
00854             # Nothing was resolved in this loop. There must be circular or
00855             # missing dependencies. Just add them to the end. We can't
00856             # raise an error, because checkComplete relies on this method.
00857             for node, edges in unresolved:
00858                 result.append(node)
00859             break
00860         graph = unresolved
00861         unresolved = []
00862     
00863     return result

Here is the caller graph for this function:

def GenericSetup.utils._extractDocstring (   func,
  default_title,
  default_description 
) [private]

Definition at line 134 of file utils.py.

00134 
00135 def _extractDocstring( func, default_title, default_description ):
00136 
00137     try:
00138         doc = getdoc( func )
00139         lines = doc.split( '\n' )
00140 
00141     except AttributeError:
00142 
00143         title = default_title
00144         description = default_description
00145 
00146     else:
00147         title = lines[ 0 ]
00148 
00149         if len( lines ) > 1 and lines[ 1 ].strip() == '':
00150             del lines[ 1 ]
00151 
00152         description = '\n'.join( lines[ 1: ] )
00153 
00154     return title, description
00155 
00156 
00157 deprecated('HandlerBase',
00158            'SAX based XML parsing is no longer supported by GenericSetup. '
00159            'HandlerBase will be removed in GenericSetup 1.5.')

Here is the call graph for this function:

Here is the caller graph for this function:

def GenericSetup.utils._getDottedName (   named) [private]

Definition at line 63 of file utils.py.

00063 
00064 def _getDottedName( named ):
00065 
00066     if isinstance( named, basestring ):
00067         return str( named )
00068 
00069     try:
00070         dotted = '%s.%s' % (named.__module__, named.__name__)
00071     except AttributeError:
00072         raise ValueError('Cannot compute dotted name: %s' % named)
00073 
00074     # remove leading underscore names if possible
00075 
00076     # Step 1: check if there is a short version
00077     short_dotted = '.'.join([ n for n in dotted.split('.')
00078                               if not n.startswith('_') ])
00079     if short_dotted == dotted:
00080         return dotted
00081 
00082     # Step 2: check if short version can be resolved
00083     try:
00084         short_resolved = _resolveDottedName(short_dotted)
00085     except (ValueError, ImportError):
00086         return dotted
00087 
00088     # Step 3: check if long version resolves to the same object
00089     try:
00090         resolved = _resolveDottedName(dotted)
00091     except (ValueError, ImportError):
00092         raise ValueError('Cannot compute dotted name: %s' % named)
00093     if short_resolved is not resolved:
00094         return dotted
00095 
00096     return short_dotted

Here is the call graph for this function:

Here is the caller graph for this function:

def GenericSetup.utils._getProductPath (   product_name) [private]
Return the absolute path of the product's directory.

Definition at line 864 of file utils.py.

00864 
00865 def _getProductPath(product_name):
00866 
00867     """ Return the absolute path of the product's directory.
00868     """
00869     try:
00870         # BBB: for GenericSetup 1.1 style product names
00871         product = __import__('Products.%s' % product_name
00872                             , globals(), {}, ['initialize'])
00873     except ImportError:
00874         try:
00875             product = __import__(product_name
00876                                 , globals(), {}, ['initialize'])
00877         except ImportError:
00878             raise ValueError('Not a valid product name: %s'
00879                              % product_name)
00880 
00881     return product.__path__[0]
00882 

Here is the caller graph for this function:

def GenericSetup.utils._resolveDottedName (   dotted) [private]

Definition at line 97 of file utils.py.

00097 
00098 def _resolveDottedName( dotted ):
00099 
00100     __traceback_info__ = dotted
00101 
00102     parts = dotted.split( '.' )
00103 
00104     if not parts:
00105         raise ValueError, "incomplete dotted name: %s" % dotted
00106 
00107     parts_copy = parts[:]
00108 
00109     while parts_copy:
00110         try:
00111             module = __import__( '.'.join( parts_copy ) )
00112             break
00113 
00114         except ImportError:
00115             # Reraise if the import error was caused inside the imported file
00116             if sys.exc_info()[2].tb_next is not None: raise
00117 
00118             del parts_copy[ -1 ]
00119 
00120             if not parts_copy:
00121                 return None
00122 
00123     parts = parts[ 1: ] # Funky semantics of __import__'s return value
00124 
00125     obj = module
00126 
00127     for part in parts:
00128         try:
00129             obj = getattr( obj, part )
00130         except AttributeError:
00131             return None
00132 
00133     return obj

Here is the caller graph for this function:

def GenericSetup.utils.exportObjects (   obj,
  parent_path,
  context 
)
Export subobjects recursively.

Definition at line 790 of file utils.py.

00790 
00791 def exportObjects(obj, parent_path, context):
00792     """ Export subobjects recursively.
00793     """
00794     exporter = queryMultiAdapter((obj, context), IBody)
00795     path = '%s%s' % (parent_path, obj.getId().replace(' ', '_'))
00796     if exporter:
00797         if exporter.name:
00798             path = '%s%s' % (parent_path, exporter.name)
00799         filename = '%s%s' % (path, exporter.suffix)
00800         body = exporter.body
00801         if body is not None:
00802             context.writeDataFile(filename, body, exporter.mime_type)
00803 
00804     if getattr(obj, 'objectValues', False):
00805         for sub in obj.objectValues():
00806             exportObjects(sub, path+'/', context)

Here is the caller graph for this function:

def GenericSetup.utils.importObjects (   obj,
  parent_path,
  context 
)
Import subobjects recursively.

Definition at line 807 of file utils.py.

00807 
00808 def importObjects(obj, parent_path, context):
00809     """ Import subobjects recursively.
00810     """
00811     importer = queryMultiAdapter((obj, context), IBody)
00812     path = '%s%s' % (parent_path, obj.getId().replace(' ', '_'))
00813     __traceback_info__ = path
00814     if importer:
00815         if importer.name:
00816             path = '%s%s' % (parent_path, importer.name)
00817         filename = '%s%s' % (path, importer.suffix)
00818         body = context.readDataFile(filename)
00819         if body is not None:
00820             importer.filename = filename # for error reporting
00821             importer.body = body
00822 
00823     if getattr(obj, 'objectValues', False):
00824         for sub in obj.objectValues():
00825             importObjects(sub, path+'/', context)
00826 

Here is the caller graph for this function:


Variable Documentation

tuple GenericSetup.utils._pkgdir = package_home( globals() )

Definition at line 53 of file utils.py.

tuple GenericSetup.utils._wwwdir = os.path.join( _pkgdir, 'www' )

Definition at line 54 of file utils.py.

tuple GenericSetup.utils._xmldir = os.path.join( _pkgdir, 'xml' )

Definition at line 55 of file utils.py.

string GenericSetup.utils.I18NURI = 'http://xml.zope.org/namespaces/i18n'

Definition at line 60 of file utils.py.