1 | from zope.interface import implements |
---|
2 | |
---|
3 | from collective.transmogrifier.interfaces import ITransmogrifier |
---|
4 | from collective.transmogrifier.transmogrifier import _load_config, constructPipeline |
---|
5 | |
---|
6 | from Products.GenericSetup.context import TarballExportContext, TarballImportContext |
---|
7 | from Products.GenericSetup.interfaces import IFilesystemImporter |
---|
8 | |
---|
9 | from quintagroup.transmogrifier.writer import WriterSection |
---|
10 | from quintagroup.transmogrifier.reader import ReaderSection |
---|
11 | |
---|
12 | EXPORT_CONFIG = 'export' |
---|
13 | IMPORT_CONFIG = 'import' |
---|
14 | |
---|
15 | def exportSiteStructure(context): |
---|
16 | transmogrifier = ITransmogrifier(context.getSite()) |
---|
17 | |
---|
18 | # we don't use transmogrifer's __call__ method, because we need to do |
---|
19 | # some modification in pipeline sections |
---|
20 | |
---|
21 | transmogrifier._raw = _load_config(EXPORT_CONFIG) |
---|
22 | transmogrifier._data = {} |
---|
23 | |
---|
24 | options = transmogrifier._raw['transmogrifier'] |
---|
25 | sections = options['pipeline'].splitlines() |
---|
26 | pipeline = constructPipeline(transmogrifier, sections) |
---|
27 | |
---|
28 | last_section = pipeline.gi_frame.f_locals['self'] |
---|
29 | |
---|
30 | # if 'quintagroup.transmogrifier.writer' section's export context is |
---|
31 | # tarball replace it with given function argument |
---|
32 | while hasattr(last_section, 'previous'): |
---|
33 | if isinstance(last_section, WriterSection) and \ |
---|
34 | isinstance(last_section.export_context, TarballExportContext): |
---|
35 | last_section.export_context = context |
---|
36 | last_section = last_section.previous |
---|
37 | # end cycle if we get empty starter section |
---|
38 | if type(last_section) == type(iter(())): |
---|
39 | break |
---|
40 | last_section = last_section.gi_frame.f_locals['self'] |
---|
41 | |
---|
42 | # Pipeline execution |
---|
43 | for item in pipeline: |
---|
44 | pass # discard once processed |
---|
45 | |
---|
46 | def importSiteStructure(context): |
---|
47 | # this function is also called when adding Plone site, so call standard handler |
---|
48 | if not context.readDataFile('.objects.xml', subdir='structure'): |
---|
49 | IFilesystemImporter(context.getSite()).import_(context, 'structure', True) |
---|
50 | return |
---|
51 | |
---|
52 | transmogrifier = ITransmogrifier(context.getSite()) |
---|
53 | |
---|
54 | # we don't use transmogrifer's __call__ method, because we need to do |
---|
55 | # some modification in pipeline sections |
---|
56 | |
---|
57 | transmogrifier._raw = _load_config(IMPORT_CONFIG) |
---|
58 | transmogrifier._data = {} |
---|
59 | |
---|
60 | options = transmogrifier._raw['transmogrifier'] |
---|
61 | sections = options['pipeline'].splitlines() |
---|
62 | pipeline = constructPipeline(transmogrifier, sections) |
---|
63 | |
---|
64 | last_section = pipeline.gi_frame.f_locals['self'] |
---|
65 | |
---|
66 | # if 'quintagroup.transmogrifier.writer' section's export context is |
---|
67 | # tarball replace it with given function argument |
---|
68 | while hasattr(last_section, 'previous'): |
---|
69 | if isinstance(last_section, ReaderSection) and \ |
---|
70 | isinstance(last_section.import_context, TarballImportContext): |
---|
71 | last_section.import_context = context |
---|
72 | last_section = last_section.previous |
---|
73 | # end cycle if we get empty starter section |
---|
74 | if type(last_section) == type(iter(())): |
---|
75 | break |
---|
76 | last_section = last_section.gi_frame.f_locals['self'] |
---|
77 | |
---|
78 | # Pipeline execution |
---|
79 | for item in pipeline: |
---|
80 | pass # discard once processed |
---|
81 | |
---|
82 | |
---|
83 | class PloneSiteImporter(object): |
---|
84 | """ Importer of plone site. |
---|
85 | """ |
---|
86 | implements(IFilesystemImporter) |
---|
87 | |
---|
88 | def __init__(self, context): |
---|
89 | self.context = context |
---|
90 | |
---|
91 | def import_(self, import_context, subdir="structure", root=False): |
---|
92 | # When performing import steps we need to use standart importing adapter, |
---|
93 | # if 'object.xml' file is absent in 'structure' directory of the profile. |
---|
94 | # This may be because it is the base plone profile or extension profile, that has |
---|
95 | # structure part in other format. |
---|
96 | |
---|
97 | objects_xml = import_context.readDataFile('.objects.xml', subdir) |
---|
98 | if objects_xml is not None: |
---|
99 | importSiteStructure(import_context) |
---|
100 | else: |
---|
101 | from Products.CMFCore.exportimport.content import StructureFolderWalkingAdapter |
---|
102 | StructureFolderWalkingAdapter(self.context).import_(import_context, "structure", True) |
---|