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

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

csml access to exist, working except for namespace issue

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