Changeset 201:574d0d75ee24
- Timestamp:
- 09/26/09 15:20:49 (6 months ago)
- Author:
- rgrp
- Branch:
- default
- convert_revision:
- svn:0ead1229-0713-0410-96cd-f668dbfad531/trunk@289
- Message:
-
[shksprdata][l]: add in moby metadata and associated material.
- refactor loading of text info into db and load moby metadata.
- script creation of moby html and pdf in cache and link to these using Resource on relevant Material
- support new locator_type cache on Resource
- Location:
- shakespeare
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r169
|
r201
|
|
| 35 | 35 | def path_from_offset(self, offset): |
| 36 | 36 | "Get full path of file in cache given by offset." |
| | 37 | if offset.startswith('/'): |
| | 38 | offset = offset[1:] |
| 37 | 39 | return os.path.join(self.cache_path, offset) |
| | 40 | |
| | 41 | def save(self, path, data): |
| | 42 | fp = self.path_from_offset(path) |
| | 43 | fo = open(fp, 'w') |
| | 44 | fo.write(data) |
| | 45 | fo.close() |
| 38 | 46 | |
| 39 | 47 | def download_url(self, url, overwrite=False): |
-
|
r196
|
r201
|
|
| 62 | 62 | Session.flush() |
| 63 | 63 | |
| 64 | | def load_texts(fileobj, locator, norm_work_name=None): |
| | 64 | def load_material(fileobj, norm_work_name=None): |
| 65 | 65 | if not norm_work_name: |
| 66 | 66 | norm_work_name = lambda x: x |
| 67 | 67 | cfgp = SafeConfigParser() |
| 68 | 68 | cfgp.readfp(fileobj) |
| | 69 | results = [] |
| 69 | 70 | for section in cfgp.sections(): |
| 70 | 71 | work_name = unicode(norm_work_name(section)) |
| 71 | 72 | work = Work.by_name(work_name) |
| 72 | | if work is None: |
| 73 | | work = Work(name=work_name) |
| | 73 | assert work is not None, work_name |
| 74 | 74 | |
| 75 | 75 | item = Material.by_name(unicode(section)) |
| … |
… |
|
| 81 | 81 | setattr(item, key, val) |
| 82 | 82 | item.work = work |
| 83 | | if not item.resources: |
| 84 | | res = Resource( |
| 85 | | locator_type=u'package', |
| 86 | | locator=locator(section), |
| 87 | | # TODO: use format correctly |
| 88 | | format=u'txt', |
| 89 | | material=item, |
| 90 | | ) |
| | 83 | results.append(item) |
| 91 | 84 | Session.flush() |
| | 85 | return results |
| | 86 | |
-
|
r197
|
r201
|
|
| 100 | 100 | from StringIO import StringIO |
| 101 | 101 | return StringIO(self.locator) |
| | 102 | elif self.locator_type == u'cache': |
| | 103 | import shakespeare.cache |
| | 104 | cache = shakespeare.cache.default |
| | 105 | fp = cache.path_from_offset(self.locator) |
| | 106 | return open(fp) |
| 102 | 107 | else: |
| 103 | 108 | raise NotImplementedError |
-
|
r197
|
r201
|
|
| 63 | 63 | assert out.read() == sometext |
| 64 | 64 | |
| | 65 | def test_get_stream_cache(self): |
| | 66 | import shakespeare.cache |
| | 67 | cache = shakespeare.cache.default |
| | 68 | sometext = u'baa baa' |
| | 69 | path = 'testcache.txt' |
| | 70 | cache.save(path, sometext) |
| | 71 | res = model.Resource(locator=path, locator_type=u'cache') |
| | 72 | out = res.get_stream() |
| | 73 | assert out.read() == sometext |
| | 74 | |
| 65 | 75 | |
| 66 | 76 | class TestStatistic: |