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

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

Further changes associated with the browse/discovery
look and feel

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.xml=xml
19        self.elem=ET.fromstring(xml)
20        self.renderMethod=renderMethod
21        self.type='DIF'
22       
23        self.abstract=wrapGetText(self.elem,'Summary')
24        self.name=wrapGetText(self.elem,'Entry_Title')
25       
26        #Note that entity.constraints.html is about access control on the metadata,
27        #and so we don't populate this here ...
28       
29        #need entity.parameters, entity.bbox, entity.timeCoverage, entity.curator, entity.creators ...
30       
31        #load up all the information about parameters
32        self.categories=[]
33        self.topics=[]
34        self.terms=[]
35        self.variables=[]
36        self.parameters=[]
37        match={'Category':self.categories,'Topic':self.topics,'Term':self.terms,
38                'Variable':self.variables,'Detailed_Variable':self.parameters}
39        for level in ['Category','Topic','Term','Variable','Detailed_Variable']:
40            for item in self.elem.findall('Parameters/'+level):
41                value=item.text
42                if value not in match[level]: match[level].append(value)
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=(
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    g=file('../../exampleD/ucar.xml')
81    dif1xml=f.read()
82    dif2xml=g.read()
83    D=DIF(cleanup(dif1xml))
84    G=DIF(cleanup(dif2xml))
85    y='''<?xml version="1.0" encoding="UTF-8"?>
86                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
87                <html xmlsns="http://www.w3.org/1999/xhtml" xml:lang="en">
88                        <head>
89                                <META http-equiv="Content-Type" content="text/xhtml; charset=iso-8859-1"/>
90                                <title>%s</title>
91                                <LINK media="all, screen" href="../layout/style.css" type="text/css" rel="stylesheet"/>
92                        </head> '''%D.name+D.toHTML()+G.toHTML()
93    f.close()
94    f=file('output.html','wb')
95    f.write(y)
96   
97   
98       
99       
100       
101       
102       
Note: See TracBrowser for help on using the repository browser.