Changeset 887


Ignore:
Timestamp:
11/12/10 13:35:53 (14 years ago)
Author:
patdui
Message:
  • made some small changes so when using the path, the correct relative path is created based from the target_dir (so adding ../) and reusing the idx for the ResourceProxy? id attribute.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/scripts/dir2cmdicollection.py

    r886 r887  
    8585        name = "OLAC: " + collectionName.replace("_", " ")
    8686        idx = ""
     87        path = ""
    8788        for item in collectionList:
    8889                # trying to restore the original id (which is in the MdSelfLink
    89                 if os.path.isfile(item) and ref_flag=="handle":
     90                if os.path.isfile(item):
    9091                                for line in open(item):
    9192                                        if "<MdSelfLink>" in line:
     
    9495                                                break
    9596                else:
    96                          idx = item             
     97                         idx = item
     98                         
     99                if ref_flag=="path":
     100                        # need to add '../' for the number of dirs in the target_dir, so paths match again.
     101                        path = "../"+item
     102                else:
     103                        path = idx;
     104                       
    97105                #idx = item.replace(".xml.cmdi","").replace("_", ":",1)[::-1].replace("_", ":",1)[::-1].replace("_", "-")
    98                 resourceProxies += "\n" + resourceTemplate.substitute(idname = idx.replace(".","_").replace("/","_").replace("\\","_"), idx = idx)
     106                resourceProxies += "\n" + resourceTemplate.substitute(idname = idx.replace(".","_").replace("/","_").replace("\\","_"), idx = path)
    99107        if collectionName=="olac-root":
    100108                collidx = "olac-root"
    101109        else:
    102110                # print "idx:" + idx
    103                 if idx!="" and ref_flag=="handle":
     111                if idx!="":
    104112                        collidx = idx[:idx.rfind(":")] # this is just a hack to derive the collection-id from the id of the collection-item (stripping the running number)
    105113                else:
     
    107115        print collidx
    108116        outfile = outstring.substitute(date= datetime.datetime.now().strftime("%Y-%m-%d"), selflink=collidx, rp=resourceProxies,url=url, name=name)
    109         f = open(target_dir + collectionFile, 'w')     
     117        collectionFile = target_dir + collectionFile
     118        f = open(collectionFile, 'w')   
    110119        f.write(outfile)
    111120        f.close()
    112121       
    113122        print collectionFile
    114         return collidx
     123        if ref_flag=="path":
     124                return collectionFile
     125        else:
     126                return collidx
    115127
    116128main()
Note: See TracChangeset for help on using the changeset viewer.