[dataprod <-> frontend] messaging functions. among others, it gets the run config...
authorUnknown Author <unknown>
Tue, 5 Aug 2008 23:16:12 +0000 (23:16 +0000)
committerUnknown Author <unknown>
Tue, 5 Aug 2008 23:16:12 +0000 (23:16 +0000)
htswdataprod/scripts/exp_track_comm.py [new file with mode: 0755]

diff --git a/htswdataprod/scripts/exp_track_comm.py b/htswdataprod/scripts/exp_track_comm.py
new file mode 100755 (executable)
index 0000000..843a3e0
--- /dev/null
@@ -0,0 +1,77 @@
+import urllib
+import urllib2
+import re
+import os
+
+def getWebPage(url,params):
+  pdata = urllib.urlencode(params)
+  req = urllib2.Request(url,pdata)
+  wpage = urllib2.urlopen(req)
+  restext = wpage.read()
+  wpage.close()
+  return restext
+
+def getConfigFile(fcid,runfolder):
+  #This function serves as well as a sync check between the datarun server and exp track web server
+  #By retrieving a valid config params set with valid input: fcid and runfolder we ensure that both servers are synch-ed  
+
+  varStatus = 'getting conf file from exp trac server'
+  url = 'http://myerslab.stanford.edu/exp_track/getConfile'
+  
+  params = {'user':'rami','fcid':fcid,'runf':runfolder}
+  readw = getWebPage(url,params)
+  #Check web response 
+  tempstr = re.sub(pattern="\n",repl=", ",string=readw)
+  #match_str = re.compile(r"READ_LENGTH.+$")
+  match_str = re.compile('^READ_LENGTH.+')
+  if match_str.search(tempstr):
+    # create file in curret folder
+    folder = './'  
+    file_path = os.path.join(folder,'config.txt')
+    f = open(file_path, 'w')
+    f.write(readw.replace(',','\n'))
+    f.close()
+    varStatus = 'OK. "config.txt" created. You can check it now.'
+  else:
+    varStatus = 'Failed reading valid Config Params in server reply:\n'+readw
+  
+  return varStatus
+
+
+def getLanesNames(fcid):
+  varStatus = 'getting Lane Names'
+  url = 'http://myerslab.stanford.edu/exp_track/getLanesNames'                                                                        
+  
+  params = {'user':'rami','fcid':fcid}
+  readw = getWebPage(url,params)
+  #Check web response                                                                                                               
+  tempstr = re.sub(pattern="\n",repl="",string=readw)
+  #match_str = re.compile(r"^<\?xml.+$")
+  match_str = re.compile('^<\?xml.+$')
+  if match_str.search(tempstr):
+    # create file in curret folder                                                                                                 
+    folder = './'
+    file_path = os.path.join(folder,'LaneNames.xml')
+    f = open(file_path, 'w')
+    f.write(readw)
+    f.close()
+    varStatus = 'OK. LaneNames.xml created. CollectReads can use it now.'
+  else:
+    varStatus = 'Failed retrieving valid LaneNames.xml data. Server returned:\n'+readw
+
+  return varStatus
+
+def updExpTrack(fcid,runfolder,updStatus,updMsg):  
+  url = 'http://myerslab.stanford.edu/exp_track/updStatus'
+
+  if len(updMsg) > 0:
+    params = {'user':'rami','fcid':fcid,'runf':runfolder,'updst':updStatus,'m\
+sg':updMsg}
+    print "Msg: "+updMsg
+  else:
+    params = {'user':'rami','fcid':fcid,'runf':runfolder,'updst':updStatus}
+    print "No Msg: "+len(updMsg).__str__()
+  readw = getWebPage(url,params)
+  return readw