1 | Reader section |
---|
2 | ============== |
---|
3 | |
---|
4 | A reader source pipeline section walks through different GenericSetup |
---|
5 | import contexts and yields items for every folder. Item contains it's |
---|
6 | path stored on a key given in ``path-key`` option and dictionary of |
---|
7 | data of files, contained in directory to which this item corresponds, |
---|
8 | stored on a key given in ``files-key`` option. The reader section blueprint |
---|
9 | name is ``quintagroup.transmogrifier.reader``. |
---|
10 | |
---|
11 | Which import context to use is controlled by ``context`` option. Possible |
---|
12 | values are: directory, tarball (default if option is absent or it's illegal) |
---|
13 | and snapshot. The only required option in this section is ``path`` which |
---|
14 | is a filesystem path of directory or archive for first two contexts, or |
---|
15 | snapshot's id for last context. Other usefull option is ``prefix`` which |
---|
16 | is additional path that must be added to ``path`` (it was designed to |
---|
17 | be used for tarball context, where content lives in 'structure' subdirectory, |
---|
18 | but may be used for other two too). Also note that ``prefix`` isn't added |
---|
19 | to generated item's path. |
---|
20 | |
---|
21 | Reader reads files and adds to ``item[files-key]`` dictionary with file's data |
---|
22 | and name. This dictionary is stored on a key, that identifies to which section |
---|
23 | this file corresponds. Mapping between filenames and sections is defined in |
---|
24 | reader section options. Option name is filename and option value is section name. |
---|
25 | |
---|
26 | >>> reader = """ |
---|
27 | ... [transmogrifier] |
---|
28 | ... pipeline = |
---|
29 | ... reader |
---|
30 | ... printer |
---|
31 | ... |
---|
32 | ... [reader] |
---|
33 | ... blueprint = quintagroup.transmogrifier.reader |
---|
34 | ... prefix = structure |
---|
35 | ... .objects.xml = manifest |
---|
36 | ... .marshall.xml = marshall |
---|
37 | ... .properties.xml = propertymanager |
---|
38 | ... .comments.xml = comments |
---|
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'} |
---|
58 | {'_files': {'comments': {'data': 'some data', 'name': '.comments.xml'}, |
---|
59 | 'marshall': {'data': 'some data', 'name': '.marshall.xml'}}, |
---|
60 | '_import_context': <Tarball ...>, |
---|
61 | '_path': 'pages/front-page'} |
---|
62 | |
---|
63 | Now 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': ''} |
---|