source: TI02-CSML/trunk/csml/API/ops_Dataset.py @ 2431

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/API/ops_Dataset.py@2431
Revision 2431, 3.0 KB checked in by domlowe, 14 years ago (diff)

test file parsing doc from exist

Line 
1''' ops_Dataset  contains operations for root Dataset class'''
2
3import codecs
4import csml.csmllibs.xmlEncoding
5import csml.parser_extra
6import csml.API.existDB
7import cElementTree as ET
8
9
10def testmethod(self):
11    print 'testmethod for dataset'
12    return 'testmethod dataset'
13
14def parse(self, csmlfile, xmldb=None, collection='/db/ndg_A_metadata', id_field = 'id', nslong='http://ndg.nerc.ac.uk/csml', nsshort='csml', passwords=None):
15    """must be provided with csmlfile   parses the csmlfile into self """
16    if xmldb is not None:     
17        #use xml db (exist)
18        COLLECTION=collection
19        DOC_ID=csmlfile
20        ID_FIELD=id_field
21        NSLONG=nslong
22        NSSHORT=nsshort
23        if passwords is not None:
24            existDB = csml.API.existDB.ndg_eXist(db=xmldb, passwordFile=passwords) 
25        else:
26            existDB = csml.API.existDB.ndg_eXist(db=xmldb) 
27        csmlfile=existDB.getXMLRecord(COLLECTION,ID_FIELD,DOC_ID,att=1,namespaceLong=NSLONG, namespaceShort=NSSHORT)
28        elem=ET.fromstring(csmlfile)
29        tree=ET.ElementTree(element=elem)
30    else:
31        #use filesystem
32        #determine encoding
33        f = open(csmlfile)
34        startoffile=f.readline()
35        encoding=csml.csmllibs.xmlEncoding.autoDetectXMLEncoding(startoffile)
36        f.close()
37        #parse with correct encoding
38        tree = csml.parser_extra.encodingParser(csmlfile,encoding)
39    self.fromXML(tree.getroot())
40    self =csml.parser_extra.ParserPostProcessor(self).resolveReferences()
41   
42def getSecurity(self):
43    """ returns a dictonary containing attributeAuthority: role"""
44    security=[]
45    if hasattr(self, 'accessControlPolicy'):
46        if hasattr(self.accessControlPolicy,'dgSecurityConditions'):
47            for condition in self.accessControlPolicy.dgSecurityConditions:
48                #need to test for these but ok for alpha.
49                cond=[]
50                cond.append(condition.effect)
51                cond.append(condition.simpleCondition.dgAttributeAuthority)
52                cond.append(condition.simpleCondition.attrauthRole)
53                cond.append(condition.conditionExplanationText)
54                security.append(cond)
55    return security
56
57def getFeatureList(self):
58    #returns a list of feature ids for the dataset
59    self.featureList = []
60    for member in csml.csmllibs.csmlextra.listify(self.featureCollection.featureMembers):
61            self.featureList.append(member.id)
62    return self.featureList
63   
64def getFeature(self, featureID):
65    """ returns a single feature object """
66    for member in csml.csmllibs.csmlextra.listify(self.featureCollection.featureMembers):
67            if member.id == featureID:
68                return member   
69
70def getFileExtract(self,extractID):
71        for extract in csml.csmllibs.csmlextra.listify(self.dataset.arrayDescriptors):
72            if  extract.id==extractID:
73                return extract
74
75def getBoundingBox(self):
76    ''' get boundingBox, returns the boundingBox of the CSMLFeatureCollection (assumes there is only one...)'''
77    print self.CSMLFeatureCollection.boundedBy
Note: See TracBrowser for help on using the repository browser.