source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/DIF.py @ 940

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/DIF.py@940
Revision 940, 3.6 KB checked in by lawrence, 14 years ago (diff)

Some minor bug fixes in rendering DIFs and stubB

Line 
1# python class to support methods on a DIF ... to conform with
2# renderEntity etc ...
3#
4import ElementTree as ET
5from Utilities import *
6from geoUtilities import *
7from People import *
8from ServiceBinding import Service
9from renderEntity import renderEntity
10
11class DIF:
12    ''' Supports the NASA GCMD DIF format for python operations,
13    note ... not a complete implementation, currently minimum to
14    show a reasonable piece of content '''
15    def __init__(self,xml,renderMethod=renderEntity):
16        '''Initialise a python dif instance based on an xml document '''
17        self.metadataType='DIF'
18        self.elem=ET.fromstring(xml)
19        self.renderMethod=renderMethod
20        self.type='DIF'
21       
22        self.abstract=wrapGetText(self.elem,'Summary')
23        self.name=wrapGetText(self.elem,'Entry_Title')
24       
25        #Note that entity.constraints.html is about access control on the metadata,
26        #and so we don't populate this here ...
27       
28        #need entity.parameters, entity.bbox, entity.timeCoverage, entity.curator, entity.creators ...
29       
30        #load up all the information about parameters
31        self.categories=[]
32        self.topics=[]
33        self.terms=[]
34        self.variables=[]
35        self.parameters=[]
36        match={'Category':self.categories,'Topic':self.topics,'Term':self.terms,
37                'Variable':self.variables,'Detailed_Variable':self.parameters}
38        for level in ['Category','Topic','Term','Variable','Detailed_Variable']:
39            for item in self.elem.findall('Parameters/'+level):
40                value=item.text
41                if value not in match[level]: match[level].append(value)
42        print self.parameters
43           
44        #load up information about spatial bounding box
45        self.bbox=Bounding(self.elem,entity='DIF')
46       
47        #load up information about temporal extent
48        self.timeCoverage='Start Date:%s Stop Date:%s (%s)'%(
49            wrapGetText(self.elem,'Temporal_Coverage/Start_Date'),
50            wrapGetText(self.elem,'Temporal_Coverage/Stop_Date'),
51            wrapGetText(self.elem,'Data_Set_Progress') )
52           
53        #Data curator information
54        self.centre=DIFcontact(self.elem.find('Data_Center'),ctype='centre')
55        self.curator=DIFcontact(self.elem)
56           
57        #Data Creators
58        self.creators=[]
59
60        #should create a class for the service links (i.e. similar to data granules for stubB)
61        #that would include any security info ...
62       
63        self.services=[]
64        for item in self.elem.find('Related_URL'):
65            s=Service()
66            s.name=item.find('URL_Content_Type')
67            s.description=item.find('Description')
68            s.url=item.find('URL')
69            self.services.append(s)
70           
71    def toHTML(self):
72        ''' Use the render method (optionally passed at initialisation, or the
73        default - renderEntity - to get an HTML version of the DIF '''
74        return self.renderMethod(self)
75       
76           
77if __name__=="__main__":
78   
79    f=file('../../exampleD/spade.xml')
80    difxml=f.read()
81    D=DIF(cleanup(difxml))
82    y='''<?xml version="1.0" encoding="UTF-8"?>
83                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
84                <html xmlsns="http://www.w3.org/1999/xhtml" xml:lang="en">
85                        <head>
86                                <META http-equiv="Content-Type" content="text/xhtml; charset=iso-8859-1"/>
87                                <title>%s</title>
88                                <LINK media="all, screen" href="../layout/style.css" type="text/css" rel="stylesheet"/>
89                        </head> '''%D.name+D.toHTML()
90    f.close()
91    f=file('output.html','wb')
92    f.write(y)
93   
94   
95       
96       
97       
98       
99       
Note: See TracBrowser for help on using the repository browser.