Changeset 194:b1f10e8bc8a9
- Timestamp:
- 08/24/09 21:21:28 (12 months ago)
- Author:
- rgrp
- Branch:
- default
- convert_revision:
- svn:0ead1229-0713-0410-96cd-f668dbfad531/trunk@280
- Message:
-
[cli,model][s]: follow up to previous commit (r279) to factor out common load_texts stuff from miltondata and shksprdata into shakespeare/model and get it running perfectly with new code.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r193
|
r194
|
|
| 47 | 47 | repo = Repository(metadata, Session) |
| 48 | 48 | |
| | 49 | |
| | 50 | from ConfigParser import SafeConfigParser |
| | 51 | def load_texts(fileobj, locator, norm_work_name=None): |
| | 52 | if not norm_work_name: |
| | 53 | norm_work_name = lambda x: x |
| | 54 | cfgp = SafeConfigParser() |
| | 55 | cfgp.readfp(fileobj) |
| | 56 | for section in cfgp.sections(): |
| | 57 | work_name = unicode(norm_work_name(section)) |
| | 58 | work = Work.by_name(work_name) |
| | 59 | if work is None: |
| | 60 | work = Work(name=work_name) |
| | 61 | |
| | 62 | item = Material.by_name(unicode(section)) |
| | 63 | if item is None: |
| | 64 | item = Material(name=unicode(section)) |
| | 65 | assert item is not None |
| | 66 | for key, val in cfgp.items(section): |
| | 67 | val = unicode(val, 'utf8') |
| | 68 | if key in ['title', 'creator']: |
| | 69 | setattr(work, key, val) |
| | 70 | setattr(item, key, val) |
| | 71 | item.work = work |
| | 72 | if not item.resources: |
| | 73 | res = Resource( |
| | 74 | locator_type=u'package', |
| | 75 | locator=locator(section), |
| | 76 | # TODO: use format correctly |
| | 77 | format=u'txt', |
| | 78 | material=item, |
| | 79 | ) |
| | 80 | Session.flush() |