Changeset 194:b1f10e8bc8a9

Show
Ignore:
Timestamp:
08/24/09 21:21:28 (7 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:
1 modified

Legend:

Unmodified
Added
Removed
  • shakespeare/model/__init__.py

    r193 r194  
    4747repo = Repository(metadata, Session) 
    4848 
     49 
     50from ConfigParser import SafeConfigParser 
     51def 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()