source: TI03-DataExtractor/branches/old_stuff/dx_source/for_usr_local/dx/scripts/dxTestClient.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx_source/for_usr_local/dx/scripts/dxTestClient.py@793
Revision 793, 16.8 KB checked in by astephen, 14 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
RevLine 
[793]1#!/usr/bin/env python
2
3#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
4#   This software may be distributed under the terms of the
5#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
6
7"""
8dxTestClient.py
9===============
10
11This script provides a client to introduce the user to how to
12call the DX as a Web Service. Note that the following function
13calls will only work if they are connecting to a server running
14the dx Web Service server application. Note that this is a python
15client and you might wish to run clients in other languages. If
16you do so please send your code to the authors so that we can
17improve this documentation.
18
19Usage:
20
21    dxTestClient [-h] <dxServerURL>
22   
23"""
24
25helpMessage="""
26dxTestClient.py
27===============
28
29This script provides a client to introduce the user to how to
30call the DX as a Web Service. Note that the following function
31calls will only work if they are connecting to a server running
32the dx Web Service server application. Note that this is a python
33client and you might wish to run clients in other languages. If
34you do so please send your code to the authors so that we can
35improve this documentation.
36
37Usage:
38
39    dxTestClient [-h] <dxServerURL>
40   
41"""
42
43# Imports from standard libary
44import sys
45
46def extractSingleVar(DXSERVER):
47    """
48    Extracts a single variable and writes the data in NetCDF.
49    """
50    print """\nImporting SOAP library...
51    > from SOAPpy import SOAPProxy,Config
52    > Config.debug=0"""   
53    from SOAPpy import SOAPProxy,Config
54    Config.debug=0
55   
56    print """\nConnecting to the server...
57    > server = SOAPProxy(DXSERVER+":8444/") # port must be same as server
58    > sessionID, secureToken=server.startSession(username=None, password=None)"""
59    server = SOAPProxy(DXSERVER+":8444/") # port must be same as server
60    sessionID, secureToken=server.startSession(username=None, password=None)   
61       
62    print "\nReturns sessionID and secureToken:",sessionID, secureToken
63   
64    print """\nGet next set of options...
65    > getter = SOAPProxy(DXSERVER+":8445/")   
66    > (optionCategories, options, optionStrings, secureToken)=getter.getOptions(sessionID, secureToken=secureToken)"""   
67    getter = SOAPProxy(DXSERVER+":8445/")   
68    (optionCategories, options, optionStrings, secureToken)=getter.getOptions(sessionID, secureToken=secureToken)   
69     
70    print "\Returns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
71
72    print """\nSelect datasetGroup...
73    > selector = SOAPProxy(DXSERVER+":8446/")
74    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
75                                                            datasetGroup_1=options[0][0])"""
76    selector = SOAPProxy(DXSERVER+":8446/") 
77    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
78                                                            datasetGroup_1=options[0][0])
79                                                                                                                                                                           
80    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
81   
82    print """\nGet summary of this request...
83    > (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
84    > print summary""" 
85    (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
86    print summary
87   
88    print """\nSelect dataset... 
89    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
90                                                            dataset_1=options[0][0])"""
91    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
92                                                            dataset_1=options[0][0])
93
94    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
95   
96    print """\nSelect variable...
97    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
98                                                            variable_1=options[0][0])"""
99    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
100                                                            variable_1=options[0][0])
101
102    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken 
103   
104    print """\nSelect horizontalDomain...
105    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
106                                                            horizontalDomain=options)"""
107    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
108                                                            horizontalDomain=options)                                                       
109                                                           
110    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
111   
112    print """\nSelect verticalDomain...     
113    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
114                                                            verticalDomain_1=options[0][0][0])"""
115    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
116                                                            verticalDomain_1=options[0][0][0])
117                                                           
118    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken   
119   
120    print """"\nSelect temporalDomain...
121    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
122                                                            temporalDomain_1=options[0])"""
123    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
124                                                            temporalDomain_1=options[0])
125                                                           
126    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
127   
128    print """\nSelect outputFormat...
129    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
130                                                            outputFormat=options[0])"""
131    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
132                                                            outputFormat=options[0])
133
134    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken 
135   
136    print """\nCheck if the request is complete...
137    > print SOAPProxy(DXSERVER+":8449/").isComplete(sessionID, secureToken)[0]"""
138    print SOAPProxy(DXSERVER+":8449/").isComplete(sessionID, secureToken)[0]
139   
140    print """\nGet the XML describing the request (i.e. the dataSubsetSpecifier...
141    > dxrmlDoc=SOAPProxy(DXSERVER+":8450/").getDataSubsetSpecifier(sessionID, secureToken)[0]"""
142    dxrmlDoc=SOAPProxy(DXSERVER+":8450/").getDataSubsetSpecifier(sessionID, secureToken)[0] 
143     
144    print """\nPrint the content of the XML doc:
145    > print dxrmlDoc"""
146    print dxrmlDoc
147   
148    print """\nSave the XML doc to local file: dataSubsetSpecifierTest1.xml
149    > open("dataSubsetSpecifierTest1.xml", "w").write(dxrmlDoc)"""
150    open("dataSubsetSpecifierTest1.xml", "w").write(dxrmlDoc)
151   
152    print """\nGet summary of this request...
153    > (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
154    > print summary""" 
155    (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
156    print summary
157       
158    print """\nTell the dx to extract the requested data...   
159    > pathList, secureToken = SOAPProxy(DXSERVER+":8451/").extractData(sessionID, secureToken)"""
160    pathList, secureToken = SOAPProxy(DXSERVER+":8451/").extractData(sessionID, secureToken)   
161     
162    print """\nGet the list of paths to the files that have been written...
163    > print pathList"""
164    print pathList
165   
166    print "\nEnd of Request for single variable."
167       
168       
169def differenceTwoVars(DXSERVER):
170    """
171    Extracts a new variable generated from the difference
172    between two variables.
173    """
174    print """\nImporting SOAP library...
175    > from SOAPpy import SOAPProxy,Config
176    > Config.debug=0"""   
177    from SOAPpy import SOAPProxy,Config
178    Config.debug=0
179   
180    print """\nConnecting to the server...
181    > server = SOAPProxy(DXSERVER+":8444/") # port must be same as server
182    > sessionID, secureToken=server.startSession(username=None, password=None)"""
183    server = SOAPProxy(DXSERVER+":8444/") # port must be same as server
184    sessionID, secureToken=server.startSession(username=None, password=None)   
185       
186    print "\nReturns sessionID and secureToken:",sessionID, secureToken
187   
188    print """\nSelecting 2 datasets...
189    > SOAPProxy(DXSERVER+":8447/").numberOfDatasets(sessionID, 2, secureToken=secureToken)"""
190    SOAPProxy(DXSERVER+":8447/").numberOfDatasets(sessionID, 2, secureToken=secureToken)   
191     
192    print """\nGet next set of options...
193    > getter = SOAPProxy(DXSERVER+":8445/")   
194    > (optionCategories, options, optionStrings, secureToken)=getter.getOptions(sessionID, secureToken=secureToken)"""   
195    getter = SOAPProxy(DXSERVER+":8445/")   
196    (optionCategories, options, optionStrings, secureToken)=getter.getOptions(sessionID, secureToken=secureToken)   
197     
198    print "\Returns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
199
200    print """\nSelect datasetGroups...
201    > selector = SOAPProxy(DXSERVER+":8446/")
202    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
203                                                            datasetGroup_1=options[0][0], datasetGroup_2=options[1][0])"""
204    selector = SOAPProxy(DXSERVER+":8446/") 
205    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
206                                                            datasetGroup_1=options[0][0], datasetGroup_2=options[1][0])
207                                                                                                                                                                           
208    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
209   
210    print """\nGet summary of this request...
211    > (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
212    > print summary""" 
213    (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
214    print summary
215   
216    print """\nSelect datasets... 
217    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
218                                                            dataset_1=options[0][0], dataset_2=options[1][0])"""
219    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
220                                                            dataset_1=options[0][0], dataset_2=options[1][0])
221
222    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
223   
224    print """\nSelect variables...
225    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
226                                                            variable_1=options[0][0], variable_2=options[1][0])"""
227    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
228                                                            variable_1=options[0][0], variable_2=options[1][0])
229
230    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken 
231   
232    print """\nSelect horizontalDomain...
233    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
234                                                            horizontalDomain=options)"""
235    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
236                                                            horizontalDomain=options)                                                       
237                                                           
238    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
239   
240    print """\nSelect verticalDomains...     
241    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
242                                                            verticalDomain_1=options[0][0][0], verticalDomain_2=options[1][0][0])"""
243    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
244                                                            verticalDomain_1=options[0][0][0], verticalDomain_2=options[1][0][0])
245                                                           
246    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken   
247   
248    print """"\nSelect temporalDomains...
249    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
250                                                            temporalDomain_1=options[0], temporalDomain_2=options[1])"""
251    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
252                                                            temporalDomain_1=options[0], temporalDomain_2=options[1])
253                                                           
254    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken
255   
256    print """\nSelect outputFormat...
257    > (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken,
258                                                            outputFormat=options[0])"""
259    (optionCategories, options, optionStrings, secureToken)=selector.selectOptions(sessionID, secureToken=secureToken, 
260                                                            outputFormat=options[0])
261
262    print "\nReturns optionCategories, options, optionStrings, secureToken:", optionCategories, options, optionStrings, secureToken 
263   
264    print """\nCheck if the request is complete...
265    > print SOAPProxy(DXSERVER+":8449/").isComplete(sessionID, secureToken)[0]"""
266    print SOAPProxy(DXSERVER+":8449/").isComplete(sessionID, secureToken)[0]
267   
268    print """\nGet the XML describing the request (i.e. the dataSubsetSpecifier...
269    > dxrmlDoc=SOAPProxy(DXSERVER+":8450/").getDataSubsetSpecifier(sessionID, secureToken)[0]"""
270    dxrmlDoc=SOAPProxy(DXSERVER+":8450/").getDataSubsetSpecifier(sessionID, secureToken)[0] 
271     
272    print """\nPrint the content of the XML doc:
273    > print dxrmlDoc"""
274    print dxrmlDoc
275   
276    print """\nSave the XML doc to local file: dataSubsetSpecifierTest2.xml
277    > open("dataSubsetSpecifierTest2.xml", "w").write(dxrmlDoc)"""
278    open("dataSubsetSpecifierTest2.xml", "w").write(dxrmlDoc)
279   
280    print """\nGet summary of this request...
281    > (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
282    > print summary""" 
283    (summary, secureToken) = SOAPProxy(DXSERVER+":8448/").summariseRequest(sessionID, secureToken=secureToken)
284    print summary
285       
286    print """\nTell the dx to extract the requested data...   
287    > pathList, secureToken = SOAPProxy(DXSERVER+":8451/").extractData(sessionID, secureToken)"""
288    pathList, secureToken = SOAPProxy(DXSERVER+":8451/").extractData(sessionID, secureToken)   
289     
290    print """\nGet the list of paths to the files that have been written...
291    > print pathList"""
292    print pathList
293   
294    print "\nEnd of Request for variable created by differencing two variables."
295
296
297   
298if __name__=="__main__":
299    if len(sys.argv)<2 or sys.argv[1][:7]!="http://":
300        print helpMessage
301        print "Please provide the URL of the dx server as the only argument"
302        sys.exit()
303       
304    serverURL=sys.argv[1]
305    if serverURL[-1]=="/": serverURL=serverURL[:-1]
306    extractSingleVar(serverURL)
307    differenceTwoVars(serverURL)
308   
Note: See TracBrowser for help on using the repository browser.