Changeset 905


Ignore:
Timestamp:
11/15/10 14:49:32 (14 years ago)
Author:
dietuyt
Message:

Small fixes to lrt2cmdi and added a -simpledir option to
dir2cmdicollection.py for the LRT inventory (just processes all cmdi
files in the current directory)

Location:
metadata/trunk/toolkit/scripts
Files:
2 edited

Legend:

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

    r887 r905  
    1313#                       'path' := the relative path of the record
    1414
    15 import os, datetime
     15import os, datetime, sys
    1616from string import Template
    1717
     
    1919ref_flag = "path" # "handle" | "path"
    2020
     21
    2122def main():
     23        simple_dir_structure = False
     24        if len(sys.argv) > 1:
     25                if sys.argv[1] == "-simpledir":
     26                        simple_dir_structure = True
     27
    2228        rootList = []
    2329        if not os.path.isdir(target_dir):
    2430                os.mkdir(target_dir)
    25         for root, dirs, files in os.walk(os.getcwd()):
    26                 startpath = os.getcwd()         
    27                 for d in dirs:
    28                         if d == "0":
    29                                 rootList.append(generate_branch(root, dirs))
     31       
     32        if not simple_dir_structure:
     33                for root, dirs, files in os.walk(os.getcwd()):
     34                        startpath = os.getcwd()         
     35                        for d in dirs:
     36                                if d == "0":
     37                                        rootList.append(generate_branch(root, dirs))
     38        else:
     39                rootList.append(generate_branch(os.getcwd(), [""], "lrt_inventory"))
    3040        writeCollection(rootList, "collection_root.cmdi", "olac-root")
    31                
     41
    3242def generate_branch(root, dirs):
    3343        collectionName = os.path.relpath(root)
     44        return generate_branch(root, dirs, collectionName)
     45
     46def generate_branch(root, dirs, collectionName):
     47        #collectionName = os.path.relpath(root)
    3448        collectionFile = "collection_%s.cmdi" % collectionName
    3549       
  • metadata/trunk/toolkit/scripts/lrt2cmdi.py

    r884 r905  
    1717
    1818    def fillElement(self, xpath, value):
     19        #print "fill %s with %s" % (xpath, value)
    1920        self.xmlTree.find(xpath).text = value.strip()
    2021       
    2122    def fillMultipleElement(self, elementname, xpath, values):
    2223        # fill in the already existing element
    23         if values[0]:
     24        #print values
     25        if (values[0]):
     26            #print "first one", values[0]
     27            #print values[0]
    2428            self.fillElement(xpath, values[0])
     29            #print "fill %s with %s" % (xpath, values[0])
     30        #print
    2531       
    2632        element = self.xmlTree.find(xpath)
     
    3137        for value in values[1:]:
    3238            if value:
    33                 # create new sibling of xpath (elementname) = value           
     39                # create new sibling of xpath (elementname) = value
     40                #print value
     41                #print "next one", value
    3442                position += 1
    3543                newElement = ElementTree.Element(elementname)
     
    5664                uniqueItems = set(items) # filter out double items
    5765                items = [i for i in uniqueItems] # convert set back to a list
     66                #print items
     67                 
    5868                self.fillMultipleElement("Institute", "//LrtCommon/Institute", items)
    5969   
     
    193203           
    194204def loadInfo():
    195     #csvFile = csv.reader(urllib.urlopen("http://www.clarin.eu/export_resources").readlines())
    196     csvFile = csv.reader(urllib.urlopen("resources.csv").readlines()) 
     205    csvFile = csv.reader(urllib.urlopen("http://www.clarin.eu/export_resources").readlines())
     206    #csvFile = csv.reader(urllib.urlopen("resources.csv").readlines()) 
    197207    linenr = 0
    198208    newDict = dict()
Note: See TracChangeset for help on using the changeset viewer.