source: products/quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/reader.txt @ 1589

Last change on this file since 1589 was 282, checked in by fenix, 18 years ago

Tagging 0.4.4 version of product

File size: 3.8 KB
RevLine 
[275]1Reader section
2==============
3
4A reader source pipeline section walks through different GenericSetup
5import contexts and yields items for every folder. Item contains it's
6path stored on a key given in ``path-key`` option and dictionary of
7data of files, contained in directory to which this item corresponds,
8stored on a key given in ``files-key`` option. The reader section blueprint
9name is ``quintagroup.transmogrifier.reader``.
10
11Which import context to use is controlled by ``context`` option. Possible
12values are: directory, tarball (default if option is absent or it's illegal)
13and snapshot. The only required option in this section is ``path`` which
14is a filesystem path of directory or archive for first two contexts, or
15snapshot's id for last context. Other usefull option is ``prefix`` which
16is additional path that must be added to ``path`` (it was designed to
17be used for tarball context, where content lives in 'structure' subdirectory,
18but may be used for other two too). Also note that ``prefix`` isn't added
19to generated item's path.
20
[282]21Reader reads files and adds to ``item[files-key]`` dictionary with file's data
22and name. This dictionary is stored on a key, that identifies to which section
23this file corresponds. Mapping between filenames and sections is defined in
24reader section options. Option name is filename and option value is section name.
25
[275]26>>> reader = """
27... [transmogrifier]
28... pipeline =
29...     reader
30...     printer
31...
32... [reader]
33... blueprint = quintagroup.transmogrifier.reader
34... prefix = structure
[282]35... .objects.xml = manifest
36... .marshall.xml = marshall
37... .properties.xml = propertymanager
38... .comments.xml = comments
[275]39...
40... [printer]
41... blueprint = collective.transmogrifier.sections.tests.pprinter
42... """
43>>> registerConfig(u'quintagroup.transmogrifier.tests.reader', reader)
44>>> transmogrifier(u'quintagroup.transmogrifier.tests.reader') # doctest: +ELLIPSIS, +REPORT_NDIFF
45{'_files': {'other.file': {'data': 'some data', 'name': 'other.file'},
46            'propertymanager': {'data': 'some data',
47                                'name': '.properties.xml'}},
48 '_import_context': <Tarball ...>,
49 '_path': ''}
50{'_files': {'manifest': {'data': 'some data', 'name': '.objects.xml'}},
51 '_import_context': <Tarball ...>,
52 '_path': 'news'}
53{'_import_context': <Tarball ...>,
54 '_path': 'news/recent'}
55{'_files': {'manifest': {'data': 'some data', 'name': '.objects.xml'}},
56 '_import_context': <Tarball ...>,
57 '_path': 'pages'}
[282]58{'_files': {'comments': {'data': 'some data', 'name': '.comments.xml'},
[275]59            'marshall': {'data': 'some data', 'name': '.marshall.xml'}},
60 '_import_context': <Tarball ...>,
61 '_path': 'pages/front-page'}
62
63Now we test if reader context is properly controlled by ``context`` option.
64
65>>> dirreader = """
66... [transmogrifier]
67... pipeline =
68...     reader
69...     printer
70...
71... [reader]
72... blueprint = quintagroup.transmogrifier.reader
73... context = directory
74... path = /path/to/directory
75...
76... [printer]
77... blueprint = collective.transmogrifier.sections.tests.pprinter
78... """
79>>> registerConfig(u'quintagroup.transmogrifier.tests.dirreader', dirreader)
80>>> transmogrifier(u'quintagroup.transmogrifier.tests.dirreader') # doctest: +ELLIPSIS, +REPORT_NDIFF
81{'_import_context': <Directory args=(..., '/path/to/directory')>,
82 '_path': ''}
83>>> dbreader = """
84... [transmogrifier]
85... pipeline =
86...     reader
87...     printer
88...
89... [reader]
90... blueprint = quintagroup.transmogrifier.reader
91... context = snapshot
92... path = snapshot-20081008163000
93...
94... [printer]
95... blueprint = collective.transmogrifier.sections.tests.pprinter
96... """
97>>> registerConfig(u'quintagroup.transmogrifier.tests.dbreader', dbreader)
98>>> transmogrifier(u'quintagroup.transmogrifier.tests.dbreader') # doctest: +ELLIPSIS, +REPORT_NDIFF
99{'_import_context': <Snapshot args=(..., 'snapshot-20081008163000')>,
100 '_path': ''}
Note: See TracBrowser for help on using the repository browser.