7598d54a5a4b8470ad6614c7af434cd59c072d29
[htsworkflow.git] / htswanalysis / scripts / analys_track_comm.py
1 import urllib
2 import urllib2
3 import re
4 import os
5
6 def getWebPage(url,params):
7   pdata = urllib.urlencode(params)
8   req = urllib2.Request(url,pdata)
9   wpage = urllib2.urlopen(req)
10   restext = wpage.read()
11   wpage.close()
12   return restext
13
14 def getProjects(mode,folder):
15   varStatus = 'getting projects with newly defined tasks'
16   url = 'http://myerslab.stanford.edu/analys_track/getProjects' 
17
18   params = {'mode':mode}
19   readw = getWebPage(url,params)
20   #Check web response                                                                                                               
21   tempstr = re.sub(pattern="\n",repl="",string=readw)
22   #match_str = re.compile(r"^<\?xml.+$")
23   match_str = re.compile('^<\?xml.+$')
24   if match_str.search(tempstr):
25     # create file in curret folder                                                                                                 
26     file_path = os.path.join(folder,'Projects.xml')
27     f = open(file_path, 'w')
28     f.write(readw)
29     f.close()
30     varStatus = mode+' Projects.xml created.'
31   else:
32     varStatus = 'Failed retrieving valid Projects.xml file. Server returned:\n'+readw
33
34   return varStatus
35
36 def updTaskStatus(taskid,updMsg):  
37   url = 'http://myerslab.stanford.edu/analys_track/updStatus'
38
39   if len(updMsg) > 0:
40     params = {'taskid':taskid,'msg':updMsg}
41     # print "Msg: "+updMsg
42   else:
43     params = {'taskid':taskid}
44  
45   readw = getWebPage(url,params)
46   return readw