Last change
on this file since 359 was
359,
checked in by chervol, 18 years ago
|
updated the adapter to save data in correct PersistentMapping? structure
|
File size:
1.4 KB
|
Rev | Line | |
---|
[359] | 1 | import os.path |
---|
| 2 | |
---|
| 3 | from zope.interface import classProvides, implements |
---|
| 4 | |
---|
| 5 | from collective.transmogrifier.interfaces import ISectionBlueprint, ISection |
---|
| 6 | |
---|
| 7 | class Source(object): |
---|
| 8 | classProvides(ISectionBlueprint) |
---|
| 9 | implements(ISection) |
---|
| 10 | |
---|
| 11 | def __init__(self, transmogrifier, name, options, previous): |
---|
| 12 | self.previous = previous |
---|
| 13 | self.source = options.get('source', '').strip() |
---|
| 14 | self.allow_empty = options.get('allow-empty-items', '').strip() == 'yes' and True or False |
---|
| 15 | items_source = options.get('items', '').strip() |
---|
| 16 | self.items = [] |
---|
| 17 | for line in items_source.splitlines(): |
---|
| 18 | self.items.append([i.strip() for i in line.split(';')]) |
---|
| 19 | |
---|
| 20 | def __iter__(self): |
---|
| 21 | for item in self.previous: |
---|
| 22 | yield item |
---|
| 23 | |
---|
| 24 | for path, type_, fname in self.items: |
---|
| 25 | if not fname.startswith('/'): |
---|
| 26 | fname = os.path.join(os.path.dirname(__file__), fname) |
---|
| 27 | try: |
---|
| 28 | fp = file(fname) |
---|
| 29 | data = fp.read() |
---|
| 30 | fp.close() |
---|
| 31 | except IOError, e: |
---|
| 32 | if self.allow_empty: |
---|
| 33 | yield dict(_type=type_, _path=path) |
---|
| 34 | continue |
---|
| 35 | |
---|
| 36 | item = dict( |
---|
| 37 | _type=type_, |
---|
| 38 | _path=path, |
---|
| 39 | _files={ |
---|
| 40 | self.source: {'data': data} |
---|
| 41 | } |
---|
| 42 | ) |
---|
| 43 | yield item |
---|
Note: See
TracBrowser
for help on using the repository browser.