| 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 = """ | 
|---|
| 22 | ... [transmogrifier] | 
|---|
| 23 | ... pipeline = | 
|---|
| 24 | ...     reader | 
|---|
| 25 | ...     printer | 
|---|
| 26 | ... | 
|---|
| 27 | ... [reader] | 
|---|
| 28 | ... blueprint = quintagroup.transmogrifier.reader | 
|---|
| 29 | ... prefix = structure | 
|---|
| 30 | ... | 
|---|
| 31 | ... [printer] | 
|---|
| 32 | ... blueprint = collective.transmogrifier.sections.tests.pprinter | 
|---|
| 33 | ... """ | 
|---|
| 34 | >>> registerConfig(u'quintagroup.transmogrifier.tests.reader', reader) | 
|---|
| 35 | >>> transmogrifier(u'quintagroup.transmogrifier.tests.reader') # doctest: +ELLIPSIS, +REPORT_NDIFF | 
|---|
| 36 | {'_files': {'other.file': {'data': 'some data', 'name': 'other.file'}, | 
|---|
| 37 | 'propertymanager': {'data': 'some data', | 
|---|
| 38 | 'name': '.properties.xml'}}, | 
|---|
| 39 | '_import_context': <Tarball ...>, | 
|---|
| 40 | '_path': ''} | 
|---|
| 41 | {'_files': {'manifest': {'data': 'some data', 'name': '.objects.xml'}}, | 
|---|
| 42 | '_import_context': <Tarball ...>, | 
|---|
| 43 | '_path': 'news'} | 
|---|
| 44 | {'_import_context': <Tarball ...>, | 
|---|
| 45 | '_path': 'news/recent'} | 
|---|
| 46 | {'_files': {'manifest': {'data': 'some data', 'name': '.objects.xml'}}, | 
|---|
| 47 | '_import_context': <Tarball ...>, | 
|---|
| 48 | '_path': 'pages'} | 
|---|
| 49 | {'_files': {'discussioncontainer': {'data': 'some data', | 
|---|
| 50 | 'name': '.comments.xml'}, | 
|---|
| 51 | 'marshall': {'data': 'some data', 'name': '.marshall.xml'}}, | 
|---|
| 52 | '_import_context': <Tarball ...>, | 
|---|
| 53 | '_path': 'pages/front-page'} | 
|---|
| 54 |  | 
|---|
| 55 | Now we test if reader context is properly controlled by ``context`` option. | 
|---|
| 56 |  | 
|---|
| 57 | >>> dirreader = """ | 
|---|
| 58 | ... [transmogrifier] | 
|---|
| 59 | ... pipeline = | 
|---|
| 60 | ...     reader | 
|---|
| 61 | ...     printer | 
|---|
| 62 | ... | 
|---|
| 63 | ... [reader] | 
|---|
| 64 | ... blueprint = quintagroup.transmogrifier.reader | 
|---|
| 65 | ... context = directory | 
|---|
| 66 | ... path = /path/to/directory | 
|---|
| 67 | ... | 
|---|
| 68 | ... [printer] | 
|---|
| 69 | ... blueprint = collective.transmogrifier.sections.tests.pprinter | 
|---|
| 70 | ... """ | 
|---|
| 71 | >>> registerConfig(u'quintagroup.transmogrifier.tests.dirreader', dirreader) | 
|---|
| 72 | >>> transmogrifier(u'quintagroup.transmogrifier.tests.dirreader') # doctest: +ELLIPSIS, +REPORT_NDIFF | 
|---|
| 73 | {'_import_context': <Directory args=(..., '/path/to/directory')>, | 
|---|
| 74 | '_path': ''} | 
|---|
| 75 | >>> dbreader = """ | 
|---|
| 76 | ... [transmogrifier] | 
|---|
| 77 | ... pipeline = | 
|---|
| 78 | ...     reader | 
|---|
| 79 | ...     printer | 
|---|
| 80 | ... | 
|---|
| 81 | ... [reader] | 
|---|
| 82 | ... blueprint = quintagroup.transmogrifier.reader | 
|---|
| 83 | ... context = snapshot | 
|---|
| 84 | ... path = snapshot-20081008163000 | 
|---|
| 85 | ... | 
|---|
| 86 | ... [printer] | 
|---|
| 87 | ... blueprint = collective.transmogrifier.sections.tests.pprinter | 
|---|
| 88 | ... """ | 
|---|
| 89 | >>> registerConfig(u'quintagroup.transmogrifier.tests.dbreader', dbreader) | 
|---|
| 90 | >>> transmogrifier(u'quintagroup.transmogrifier.tests.dbreader') # doctest: +ELLIPSIS, +REPORT_NDIFF | 
|---|
| 91 | {'_import_context': <Snapshot args=(..., 'snapshot-20081008163000')>, | 
|---|
| 92 | '_path': ''} | 
|---|