Package Ganga :: Package Utility :: Package external :: Package ARDAMDClient :: Module testClient
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Utility.external.ARDAMDClient.testClient

  1  #!/usr/bin/env python 
  2  import mdstandalone 
  3  import mdinterface 
  4  import mdclient 
  5  import time 
  6  import math 
  7   
  8  #client=mdstandalone.MDStandalone('/tmp/') 
  9  client = mdclient.MDClient(host = 'gangamd.cern.ch', port = 9922, login = 'asaroka') 
 10  client.requireSSL("/tmp/x509up_u8032", "/tmp/x509up_u8032") 
 11   
 12  try: 
 13      print "Creating directory /pytest ..." 
 14      client.createDir("/pytest")     
 15  except mdinterface.CommandException, ex: 
 16      print "Error:", ex 
 17   
 18  try: 
 19      print "Adding entries in bulk..." 
 20      client.addEntries(["/pytest/a", "/pytest/b", "/pytest/c"])     
 21  except mdinterface.CommandException, ex: 
 22      print "Error:", ex 
 23       
 24  try: 
 25      print "Adding attribute..." 
 26      client.addAttr("/pytest", "events", "int")     
 27  except mdinterface.CommandException, ex: 
 28      print "Error:", ex 
 29       
 30  try: 
 31      print "Adding attribute..." 
 32      client.addAttr("/pytest", "eventGen", "varchar(20)")     
 33  except mdinterface.CommandException, ex: 
 34      print "Error:", ex 
 35       
 36  try: 
 37      print "Adding attribute..." 
 38      client.addAttr("/pytest", "sssin", "float")     
 39  except mdinterface.CommandException, ex: 
 40      print "Error:", ex 
 41       
 42  try: 
 43      print "Adding attribute..." 
 44      client.addAttr("/pytest", "l1", "int")     
 45  except mdinterface.CommandException, ex: 
 46      print "Error:", ex 
 47   
 48  try: 
 49      attributes, types=client.listAttr("/pytest/t0") 
 50      print attributes 
 51      print types 
 52  except mdinterface.CommandException, ex: 
 53      print "Error:", ex 
 54   
 55  try: 
 56      for i in range(0,10): 
 57          client.addEntry("/pytest/t"+str(i), 
 58                          ['events', 'eventGen', 'sssin', 'l1'], 
 59                          [ str(i*100), 'myGen', str(math.sin(float(i))), str(i%2) ]) 
 60  except mdinterface.CommandException, ex: 
 61      print "Error:", ex 
 62   
 63   
 64  try: 
 65      print "Getting all attributes..." 
 66      client.getattr('/pytest', ['eventGen', 'sssin', 'events']) 
 67      while not client.eot():  
 68          file, values=client.getEntry() 
 69          print "->",file, values 
 70  except mdinterface.CommandException, ex: 
 71      print "Error:", ex 
 72   
 73  try: 
 74      print "Creating directory /pytest/testdir ..." 
 75      client.createDir("/pytest/testdir")     
 76  except mdinterface.CommandException, ex: 
 77      print "Error:", ex 
 78   
 79  try: 
 80      print "Listing entries..." 
 81      client.listEntries('/pytest') 
 82      while not client.eot(): 
 83          file, type=client.getEntry() 
 84          print "->",file, type[0] 
 85  except mdinterface.CommandException, ex: 
 86      print "Error:", ex 
 87   
 88  try: 
 89      print "Creating directory /pylock ..." 
 90      client.createDir("/pylock")     
 91  except mdinterface.CommandException, ex: 
 92      print "Error:", ex 
 93               
 94   
 95  try: 
 96     print "Adding attribute id..." 
 97     client.addAttr("/pylock", "id", "int") 
 98  except mdinterface.CommandException, ex: 
 99     print "Error:", ex   
100      
101      
102  try: 
103      print "Creating LOCK table..." 
104      client.addEntry("/pylock/lock", ['id'], [4711]) 
105      client.addEntry("/pylock/lock2", ['id'], [ 100])     
106  except mdinterface.CommandException, ex: 
107      print "Error:", ex 
108     
109                                                                 
110  try: 
111      print "Selecting attributes" 
112      client.selectAttr(['/pytest:eventGen', '/pytest:sssin', '/pytest:events'], '/pytest:FILE="t1"') 
113  #    client.selectAttr(['/pytest:eventGen', '/pytest:sssin', '/pytest:events'], '/pytest:events = 100') 
114      while not client.eot(): 
115          values=client.getSelectAttrEntry() 
116          print  "selcted ->", values 
117  except mdinterface.CommandException, ex: 
118      print "Error:", ex 
119   
120   
121  try: 
122      print "Updating attributes" 
123      client.updateAttr('/pytest', ["sssin 'sssin + 1'"], '/pytest:events = /pylock:id') 
124  except mdinterface.CommandException, ex: 
125      print "Error:", ex 
126                                   
127   
128  try: 
129    print "Setting env to 42..." 
130    client.setAttr('/pytest/?', ['events'], [42]) 
131  except mdinterface.CommandException, ex: 
132    print "Error:", ex 
133         
134   
135  try: 
136      print "Getting all attributes..." 
137      client.getattr('/pytest', ['eventGen', 'sssin', 'events']) 
138      while not client.eot():  
139          file, values=client.getEntry() 
140          print "->",file, values 
141  except mdinterface.CommandException, ex: 
142      print "Error:", ex                                 
143   
144   
145  try: 
146      print "Removing directory /pylock/testdir ..." 
147      client.removeDir("/pytest/testdir") 
148  except mdinterface.CommandException, ex: 
149      print "Error:", ex 
150   
151   
152  try:  
153      print "Removing entries" 
154      client.rm("/pytest/*") 
155  except mdinterface.CommandException, ex: 
156      print "Error:", ex 
157   
158   
159  try:  
160      print "Removing entries" 
161      client.rm("/pylock/*") 
162  except mdinterface.CommandException, ex: 
163      print "Error:", ex 
164   
165  try:  
166      print "Removing attribute..." 
167      client.removeAttr("/pytest", "events") 
168  except mdinterface.CommandException, ex: 
169      print "Error:", ex 
170   
171  try:  
172      print "Removing attribute..." 
173      client.removeAttr("/pytest", "sssin")  
174  except mdinterface.CommandException, ex: 
175      print "Error:", ex 
176   
177  try:  
178      print "Removing attribute..." 
179      client.removeAttr("/pytest", "eventGen") 
180  except mdinterface.CommandException, ex: 
181      print "Error:", ex 
182   
183  try:  
184      print "Removing attribute..." 
185      client.removeAttr("/pytest", "l1")   
186  except mdinterface.CommandException, ex: 
187      print "Error:", ex 
188   
189  try: 
190      print "Removing attribute..." 
191      client.removeAttr("/pylock", "id") 
192  except mdinterface.CommandException, ex: 
193      print "Error:", ex 
194   
195  try: 
196      print "Creating sequence..." 
197      client.sequenceCreate("seq", "/pytest") 
198  except mdinterface.CommandException, ex: 
199      print "Error:", ex 
200   
201  try: 
202      print "Getting next from sequence..." 
203      print client.sequenceNext("/pytest/seq") 
204  except mdinterface.CommandException, ex: 
205      print "Error:", ex 
206   
207  try: 
208      print "Getting next from sequence..." 
209      print client.sequenceNext("/pytest/seq") 
210  except mdinterface.CommandException, ex: 
211      print "Error:", ex 
212   
213  try: 
214      print "Removing sequence..." 
215      client.sequenceRemove("/pytest/seq")     
216  except mdinterface.CommandException, ex: 
217      print "Error:", ex 
218   
219  #try: 
220  #    print "Removing directory /pylock/testdir ..." 
221  #    client.removeDir("/pytest/testdir") 
222  #except mdinterface.CommandException, ex: 
223  #    print "Error:", ex 
224               
225   
226  try: 
227      print "Removing directory /pylock..." 
228      client.removeDir("/pytest") 
229  except mdinterface.CommandException, ex: 
230      print "Error:", ex 
231   
232  try: 
233      print "Removing directory /pylock..." 
234      client.removeDir("/pylock") 
235  except mdinterface.CommandException, ex: 
236      print "Error:", ex 
237