Changeset 1354

Show
Ignore:
Timestamp:
08/08/08 00:45:52 (4 months ago)
Author:
sgillies
Message:

Remove cruft from entity loaders

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PleiadesEntity/trunk/Extensions/loader.py

    r1312 r1354  
    105105 
    106106 
    107 def loaden(self, sourcedir): 
     107def loaden(site, sourcedir): 
    108108    """Attempt to load all XML files in the specified source directory. 
    109109    Files which can not be loaded are reported.""" 
     
    112112    for xml in glob.glob("%s/*.xml" % sourcedir): 
    113113        try: 
    114             load_place(self, xml) 
     114            load_place(site, xml) 
    115115            count += 1 
    116116        except Exception, e: 
     
    156156    appropriate temporalAttestation children of the object at  
    157157    portalcontext.""" 
    158     
    159     #wftool = getToolByName(portalcontext, 'portal_workflow') 
    160158 
    161159    for tp in  xmlcontext.findall("{%s}timePeriod" % ADLGAZ): 
     
    190188            raise EntityLoadError, "There is already a TemporalAttestation with id=%s in portal context = %s" % (id, portalcontext.Title()) 
    191189 
    192         #wftool.doActionFor(getattr(portalcontext, id), "publish") 
    193  
    194190def getalltext(elem): 
    195191    text = elem.text or "" 
     
    200196def parse_secondary_references(xmlcontext, portalcontext, ptool, wftool=None): 
    201197    srs =  xmlcontext.find("{%s}secondaryReferences" % AWMC) 
    202     if srs
     198    if srs is not None
    203199        bibls = srs.xpath('tei:bibl', namespaces={'tei': TEI}) 
    204200        if not bibls: 
     
    221217                except: 
    222218                    raise 
    223                     #raise EntityLoadError, "There is already a SecondaryReference with id=%s in portal context" % id 
    224                  
    225                 #wftool.doActionFor(getattr(portalcontext, id), "publish") 
    226  
    227 import sys 
    228219 
    229220def parse_attrib_rights(xmlcontext): 
     
    336327                    description=description 
    337328                    ) 
    338             name = getattr(names, nid) 
     329            name = names[nid] 
    339330        except: 
    340331            nid = names.duplicates.invokeFactory("Name", 
     
    352343                    description=description 
    353344                    ) 
    354             name = getattr(names.duplicates, nid) 
    355  
    356         #wftool.doActionFor(name, "publish") 
    357           
     345            name = names.duplicates[nid] 
     346 
    358347        nids.append(nid) 
    359348        association_certainties.append(certainty) 
     
    361350        # Time Periods associated with the name 
    362351        parse_periods(e, name) 
    363          
    364352        # SecondaryReferences associated with the name 
    365353        parse_secondary_references(e, name, ptool) #, wftool) 
    366         #name.reindexObject() 
    367354         
    368355    return (nids, association_certainties) 
     
    377364    for e in root.findall("{%s}spatialLocation" % ADLGAZ): 
    378365        coords = e.findall("{%s}point" % GEORSS)[0].text.split() 
    379  
    380366        lid = portalcontext.invokeFactory('Location', 
    381367                    geometry='Point:[%s,%s]' % (coords[1], coords[0]), 
     
    384370                    rights=rights 
    385371                    ) 
    386          
    387         #wftool.doActionFor(getattr(portalcontext, lid), "publish") 
    388372        lids.append(lid) 
    389          
    390373        # Time Periods associated with the location 
    391         parse_periods(root, getattr(portalcontext, lid)) 
    392          
    393         #getattr(locations, lid).reindexObject() 
     374        parse_periods(root, portalcontext[lid]) 
    394375 
    395376    return lids 
     
    400381 
    401382    ptool = getToolByName(site, 'plone_utils') 
    402     #wftool = getToolByName(site, 'portal_workflow') 
    403383 
    404384    places = site['places'] 
     
    410390    try: 
    411391        root = etree.parse(file).getroot() 
    412         
    413392        creators, contributors, rights = parse_attrib_rights(root) 
    414              
    415393        # Names 
    416         nids, association_certainties = parse_names(root, names, ptool) #, wftool) 
    417  
     394        nids, association_certainties = parse_names(root, names, ptool) 
    418395        # Locations 
    419         lids = parse_locations(root, locations, ptool) #, wftool) 
    420      
     396        lids = parse_locations(root, locations, ptool) 
    421397        # Place 
    422398        e = root.findall("{%s}modernLocation" % AWMC) 
     
    455431            id = None 
    456432     
    457         placeNames = [getattr(names, nid) for nid in nids] 
     433        placeNames = [names[nid] for nid in nids] 
    458434        computedTitle = '/'.join([n.Title() for n in placeNames]) 
    459435         
     
    467443                    description=description 
    468444                    ) 
    469         p = getattr(places, pid) 
    470         #wftool.doActionFor(p, "publish") 
    471         #p.reindexObject() 
    472      
     445        p = places[pid] 
     446 
    473447        # Iterate over locations 
    474448        for lid in lids: 
     
    480454                    associationCertainty='certain', 
    481455                    ) 
    482                 a = getattr(p, aid) 
    483                 a.addReference(getattr(locations, lid), 'hasLocation') 
    484                 #wftool.doActionFor(a, "publish") 
    485              
     456                a = p[aid] 
     457                a.addReference(locations[lid], 'hasLocation') 
    486458                # Secondary references for the place 
    487459                parse_secondary_references(root, a, ptool) #, wftool) 
    488                 #a.reindexObject() 
    489              
     460 
    490461            else: 
    491462                for i, nid in enumerate(nids): 
     
    498469                        associationCertainty=certainty, 
    499470                        ) 
    500                     a = getattr(p, aid) 
    501                     a.addReference(getattr(locations, lid), 'hasLocation') 
    502                     a.addReference(getattr(names, nid), 'hasName') 
    503                     #wftool.doActionFor(a, "publish") 
    504              
     471                    a = p[aid] 
     472                    a.addReference(locations[lid], 'hasLocation') 
     473                    a.addReference(names[nid], 'hasName') 
    505474                    # Secondary references for the place 
    506475                    parse_secondary_references(root, a, ptool) #, wftool) 
    507                     #a.reindexObject() 
    508476     
    509477        # If there are no locations, iterate over the names 
     
    515483                        associationCertainty='certain', 
    516484                        ) 
    517                 a = getattr(p, aid) 
    518                 a.addReference(getattr(names, nid), 'hasName') 
    519                 #wftool.doActionFor(a, "publish") 
     485                a = p[aid] 
     486                a.addReference(names[nid], 'hasName') 
    520487                # Secondary references for the place 
    521488                parse_secondary_references(root, a, ptool) #, wftool) 
    522                 #a.reindexObject() 
    523489 
    524490    except: