Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
CMFCore.exportimport.content.StructureFolderWalkingAdapter Class Reference

List of all members.

Public Member Functions

def __init__
def export
def import_

Public Attributes

 context

Private Member Functions

def _makeInstance

Detailed Description

Tree-walking exporter 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.
If the import step finds that any objects specified to be created by the
'structure' directory setup already exist, these objects will be deleted
and then recreated by the profile.  The existence of a '.preserve' file
within the 'structure' hierarchy allows specification of objects that
should not be deleted.  '.preserve' files should contain one preserve
rule per line, with shell-style globbing supported (i.e. 'b*' will match
all objects w/ id starting w/ 'b'.

Similarly, a '.delete' file can be used to specify the deletion of any
objects that exist in the site but are NOT in the 'structure' hierarchy,
and thus will not be recreated during the import process.

Definition at line 43 of file content.py.


Constructor & Destructor Documentation

Definition at line 73 of file content.py.

00073 
00074     def __init__(self, context):
00075         self.context = context


Member Function Documentation

def CMFCore.exportimport.content.StructureFolderWalkingAdapter._makeInstance (   self,
  id,
  portal_type,
  subdir,
  import_context 
) [private]

Definition at line 177 of file content.py.

00177 
00178     def _makeInstance(self, id, portal_type, subdir, import_context):
00179 
00180         context = self.context
00181         properties = import_context.readDataFile('.properties',
00182                                                  '%s/%s' % (subdir, id))
00183         tool = getToolByName(context, 'portal_types')
00184 
00185         try:
00186             tool.constructContent(portal_type, context, id)
00187         except ValueError: # invalid type
00188             return None
00189 
00190         content = context._getOb(id)
00191 
00192         if properties is not None:
00193             lines = properties.splitlines()
00194 
00195             stream = StringIO('\n'.join(lines))
00196             parser = ConfigParser(defaults={'title': '', 'description': 'NONE'})
00197             parser.readfp(stream)
00198 
00199             title = parser.get('DEFAULT', 'title')
00200             description = parser.get('DEFAULT', 'description')
00201 
00202             content.setTitle(title)
00203             content.setDescription(description)
00204 
00205         return content

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.exportimport.content.StructureFolderWalkingAdapter.export (   self,
  export_context,
  subdir,
  root = False 
)
See IFilesystemExporter.

Definition at line 76 of file content.py.

00076 
00077     def export(self, export_context, subdir, root=False):
00078         """ See IFilesystemExporter.
00079         """
00080         # Enumerate exportable children
00081         exportable = self.context.contentItems()
00082         exportable = [x + (IFilesystemExporter(x, None),) for x in exportable]
00083         exportable = [x for x in exportable if x[1] is not None]
00084 
00085         stream = StringIO()
00086         csv_writer = writer(stream)
00087 
00088         for object_id, object, ignored in exportable:
00089             csv_writer.writerow((object_id, object.getPortalTypeName()))
00090 
00091         if not root:
00092             subdir = '%s/%s' % (subdir, self.context.getId())
00093 
00094         export_context.writeDataFile('.objects',
00095                                      text=stream.getvalue(),
00096                                      content_type='text/comma-separated-values',
00097                                      subdir=subdir,
00098                                     )
00099 
00100         parser = ConfigParser()
00101 
00102         parser.set('DEFAULT', 'Title', self.context.Title())
00103         parser.set('DEFAULT', 'Description', self.context.Description())
00104         stream = StringIO()
00105         parser.write(stream)
00106 
00107         export_context.writeDataFile('.properties',
00108                                     text=stream.getvalue(),
00109                                     content_type='text/plain',
00110                                     subdir=subdir,
00111                                     )
00112 
00113         for id, object in self.context.objectItems():
00114 
00115             adapter = IFilesystemExporter(object, None)
00116 
00117             if adapter is not None:
00118                 adapter.export(export_context, subdir)

def CMFCore.exportimport.content.StructureFolderWalkingAdapter.import_ (   self,
  import_context,
  subdir,
  root = False 
)
See IFilesystemImporter.

Definition at line 119 of file content.py.

00119 
00120     def import_(self, import_context, subdir, root=False):
00121         """ See IFilesystemImporter.
00122         """
00123         context = self.context
00124         if not root:
00125             subdir = '%s/%s' % (subdir, context.getId())
00126 
00127         objects = import_context.readDataFile('.objects', subdir)
00128         if objects is None:
00129             return
00130 
00131         dialect = 'excel'
00132         stream = StringIO(objects)
00133 
00134         rowiter = reader(stream, dialect)
00135         ours = filter(None, tuple(rowiter))
00136         our_ids = set([item[0] for item in ours])
00137 
00138         prior = set(context.contentIds())
00139 
00140         preserve = import_context.readDataFile('.preserve', subdir)
00141         if not preserve:
00142             preserve = set()
00143         else:
00144             preservable = prior.intersection(our_ids)
00145             preserve = set(_globtest(preserve, preservable))
00146 
00147         delete = import_context.readDataFile('.delete', subdir)
00148         if not delete:
00149             delete= set()
00150         else:
00151             deletable = prior.difference(our_ids)
00152             delete = set(_globtest(delete, deletable))
00153 
00154         # if it's in our_ids and NOT in preserve, or if it's not in
00155         # our_ids but IS in delete, we're gonna delete it
00156         delete = our_ids.difference(preserve).union(delete)
00157 
00158         for id in prior.intersection(delete):
00159             context._delObject(id)
00160 
00161         existing = context.objectIds()
00162 
00163         for object_id, portal_type in ours:
00164 
00165             if object_id not in existing:
00166                 object = self._makeInstance(object_id, portal_type,
00167                                             subdir, import_context)
00168                 if object is None:
00169                     logger = import_context.getLogger('SFWA')
00170                     logger.warning("Couldn't make instance: %s/%s" %
00171                                    (subdir, object_id))
00172                     continue
00173 
00174             wrapped = context._getOb(object_id)
00175 
00176             IFilesystemImporter(wrapped).import_(import_context, subdir)

Here is the call graph for this function:


Member Data Documentation

Definition at line 74 of file content.py.


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