added comm module of communication.
authorTim Reddy Tim <treddy@hudsonalpha.org>
Tue, 19 Aug 2008 18:01:43 +0000 (18:01 +0000)
committerTim Reddy Tim <treddy@hudsonalpha.org>
Tue, 19 Aug 2008 18:01:43 +0000 (18:01 +0000)
htswanalysis/scripts/analys_track_comm.py [new file with mode: 0755]

diff --git a/htswanalysis/scripts/analys_track_comm.py b/htswanalysis/scripts/analys_track_comm.py
new file mode 100755 (executable)
index 0000000..4fa0a3e
--- /dev/null
@@ -0,0 +1,47 @@
+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 getProjects(mode):
+  varStatus = 'getting projects with newly defined tasks'
+  url = 'http://myerslab.stanford.edu/analys_track/getProjects' 
+
+  params = {'mode':mode}
+  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,'Projects.xml')
+    f = open(file_path, 'w')
+    f.write(readw)
+    f.close()
+    varStatus = mode+' Projects.xml created.'
+  else:
+    varStatus = 'Failed retrieving valid Projects.xml file. Server returned:\n'+readw
+
+  return varStatus
+
+def updTaskStatus(taskid,updMsg):  
+  url = 'http://myerslab.stanford.edu/analys_track/updStatus'
+
+  if len(updMsg) > 0:
+    params = {'taskid':taskid,'msg':updMsg}
+    # print "Msg: "+updMsg
+  else:
+    params = {'taskid':taskid}
+  readw = getWebPage(url,params)
+  return readw