Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
GenericSetup.content.FolderishExporterImporter Class Reference

List of all members.

Public Member Functions

def __init__
def listExportableItems
def export
def import_

Public Attributes

 context

Private Member Functions

def _makeInstance
def _mustPreserve

Detailed Description

Tree-walking exporter / importer for "folderish" types.

Folderish instances are mapped to directories within the 'structure'
portion of the profile, where the folder's relative path within the site
corresponds to the path of its directory under 'structure'.

The subobjects of a folderish instance are enumerated in the '.objects'
file in the corresponding directory.  This file is a CSV file, with one
row per subobject, with the following wtructure::

 "<subobject id>","<subobject portal_type>"

Subobjects themselves are represented as individual files or
subdirectories within the parent's directory.

Definition at line 51 of file content.py.


Constructor & Destructor Documentation

Definition at line 70 of file content.py.

00070 
00071     def __init__(self, context):
00072         self.context = context


Member Function Documentation

def GenericSetup.content.FolderishExporterImporter._makeInstance (   self,
  instance_id,
  type_name,
  subdir,
  import_context 
) [private]

Definition at line 184 of file content.py.

00184 
00185     def _makeInstance(self, instance_id, type_name, subdir, import_context):
00186 
00187         context = self.context
00188         class _OldStyleClass:
00189             pass
00190 
00191         if '.' in type_name:
00192 
00193             factory = _resolveDottedName(type_name)
00194 
00195             if getattr(factory, '__bases__', None) is not None:
00196 
00197                 def _factory(instance_id,
00198                              container=self.context,
00199                              klass=factory):
00200                     try:
00201                         instance = klass(instance_id)
00202                     except (TypeError, ValueError):
00203                         instance = klass()
00204                     instance._setId(instance_id)
00205                     container._setObject(instance_id, instance)
00206 
00207                     return instance
00208 
00209                 factory = _factory
00210 
00211         else:
00212             factory = queryAdapter(self.context,
00213                                    IContentFactory,
00214                                    name=type_name,
00215                                    )
00216         if factory is None:
00217             return None
00218 
00219         try:
00220             instance = factory(instance_id)
00221         except ValueError: # invalid type
00222             return None
00223 
00224         if context._getOb(instance_id, None) is None:
00225             context._setObject(instance_id, instance) 
00226 
00227         return context._getOb(instance_id)

Here is the caller graph for this function:

Definition at line 228 of file content.py.

00228 
00229     def _mustPreserve(self):
00230         return [x for x in self.context.objectItems()
00231                         if ISetupTool.providedBy(x[1])]
00232  

Here is the caller graph for this function:

def GenericSetup.content.FolderishExporterImporter.export (   self,
  export_context,
  subdir,
  root = False 
)
See IFilesystemExporter.

Definition at line 83 of file content.py.

00083 
00084     def export(self, export_context, subdir, root=False):
00085         """ See IFilesystemExporter.
00086         """
00087         context = self.context
00088 
00089         if not root:
00090             subdir = '%s/%s' % (subdir, context.getId())
00091 
00092         exportable = self.listExportableItems()
00093 
00094         stream = StringIO()
00095         csv_writer = writer(stream)
00096 
00097         for object_id, object, adapter in exportable:
00098 
00099             factory_namer = IContentFactoryName(object, None)
00100             if factory_namer is None:
00101                 factory_name = _getDottedName(object.__class__)
00102             else:
00103                 factory_name = factory_namer()
00104 
00105             csv_writer.writerow((object_id, factory_name))
00106 
00107         export_context.writeDataFile('.objects',
00108                                     text=stream.getvalue(),
00109                                     content_type='text/comma-separated-values',
00110                                     subdir=subdir,
00111                                    )
00112 
00113         prop_adapter = IINIAware(context, None)
00114 
00115         if prop_adapter is not None:
00116             export_context.writeDataFile('.properties',
00117                                          text=prop_adapter.as_ini(),
00118                                          content_type='text/plain',
00119                                          subdir=subdir,
00120                                         )
00121 
00122         for object_id, object, adapter in exportable:
00123             if adapter is not None:
00124                 adapter.export(export_context, subdir)

Here is the call graph for this function:

def GenericSetup.content.FolderishExporterImporter.import_ (   self,
  import_context,
  subdir,
  root = False 
)
See IFilesystemImporter.

Definition at line 125 of file content.py.

00125 
00126     def import_(self, import_context, subdir, root=False):
00127         """ See IFilesystemImporter.
00128         """
00129         context = self.context
00130         if not root:
00131             subdir = '%s/%s' % (subdir, context.getId())
00132 
00133         prop_adapter = IINIAware(context, None)
00134 
00135         if prop_adapter is not None:
00136             prop_text = import_context.readDataFile('.properties',
00137                                                     subdir=subdir,
00138                                                    )
00139             if prop_text is not None:
00140                 prop_adapter.put_ini(prop_text)
00141 
00142         preserve = import_context.readDataFile('.preserve', subdir)
00143         must_preserve = self._mustPreserve()
00144 
00145         prior = context.objectIds()
00146 
00147         if not preserve:
00148             preserve = []
00149         else:
00150             preserve = _globtest(preserve, prior)
00151 
00152         preserve.extend([x[0] for x in must_preserve])
00153 
00154         for id in prior:
00155             if id not in preserve:
00156                 context._delObject(id)
00157 
00158         objects = import_context.readDataFile('.objects', subdir)
00159         if objects is None:
00160             return
00161 
00162         dialect = 'excel'
00163         stream = StringIO(objects)
00164 
00165         rowiter = reader(stream, dialect)
00166         rows = filter(None, tuple(rowiter))
00167 
00168         existing = context.objectIds()
00169 
00170         for object_id, type_name in rows:
00171 
00172             if object_id not in existing:
00173                 object = self._makeInstance(object_id, type_name,
00174                                             subdir, import_context)
00175                 if object is None:
00176                     logger = import_context.getLogger('SFWA')
00177                     logger.warning("Couldn't make instance: %s/%s" %
00178                                    (subdir, object_id))
00179                     continue
00180 
00181             wrapped = context._getOb(object_id)
00182 
00183             IFilesystemImporter(wrapped).import_(import_context, subdir)

Here is the call graph for this function:

See IFilesystemExporter.

Definition at line 73 of file content.py.

00073 
00074     def listExportableItems(self):
00075         """ See IFilesystemExporter.
00076         """
00077         exportable = self.context.objectItems()
00078         exportable = [x for x in exportable
00079                         if not ISetupTool.providedBy(x[1])]
00080         exportable = [x + (IFilesystemExporter(x[1], None),)
00081                         for x in exportable]
00082         return exportable

Here is the caller graph for this function:


Member Data Documentation

Definition at line 71 of file content.py.


The documentation for this class was generated from the following file: