+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 refreshLibInfoFile(request):
+ varStatus = 'getting conf file from exp trac server'
+ url = 'http://m304-apple-server.stanford.edu/ENCODE/LibraryInfo.xml'
+ params = {}
+ readw = getWebPage(url,params)
+ # make sure file content starts as xml
+ match_str = re.compile('^<\?xml.+')
+ if match_str.search(readw): ##tempstr):
+ # Rename current file with timestamp
+ year = datetime.today().year.__str__()
+ year = replace(year,'20','')
+ month = datetime.today().month
+ if month < 10: month = "0"+month.__str__()
+ else: month = month.__str__()
+ day = datetime.today().day
+ if day < 10: day = "0"+day.__str__()
+ else: day = day.__str__()
+ mydate = year+month+day
+ folder = '/htsworkflow/htswfrontend/htswfrontend/htsw_reports/LibInfo/'
+ os.rename(folder+'LibraryInfo.xml',folder+mydate+'_LibraryInfo.xml')
+ # create file in curret folder
+ file_path = os.path.join(folder,'LibraryInfo.xml')
+ f = open(file_path, 'w')
+ f.write(readw)
+ f.close()
+ varStatus = 'OK. LibraryInfo.xml refreshed at Web server.'
+ else:
+ varStatus = 'Failed reading valid LibraryInfo.xml server reply:\n'+readw
+ return HttpResponse(varStatus)