added exception catching to the parser and a simple Status (Msg property) to the...
authorRami Rauch <rrauch@stanford.edu>
Tue, 2 Dec 2008 21:28:02 +0000 (21:28 +0000)
committerRami Rauch <rrauch@stanford.edu>
Tue, 2 Dec 2008 21:28:02 +0000 (21:28 +0000)
htswfrontend/htswfrontend/htsw_reports/libinfopar.py

index 56c75ad21028c005fd88b0218d69d461b7acc9a6..672af8468f36e9404da3034ecddad9815d84e95d 100644 (file)
@@ -1,3 +1,4 @@
+from htswfrontend import settings
 from django.http import HttpResponse
 from datetime import datetime
 from string import *
@@ -22,16 +23,19 @@ class LibInfoHandler(ContentHandler):
     self.searchTerm= searchTerm
     self.currlibid = ''
     self.LanesCount, self.ReadsCount = 0, 0
-    self.Msg = ''
+    self.Msg = 'OK'
        
   def startElement(self, name, attrs):
-    if name == 'Library':     
-      self.currlibid = attrs.get('Name',"")      
-    elif name == 'Track' and self.searchTerm == self.currlibid:
-      self.LanesCount += len(attrs.get('Lane',""))
-      self.ReadsCount += int(attrs.get('Count',""))
-    else:
-      self.Msg += ' | name = '+name+', currlibid = '+ self.currlibid
+    try:
+      if name == 'Library':     
+        self.currlibid = attrs.get('Name',"")      
+      elif name == 'Track' and self.searchTerm == self.currlibid:
+        self.LanesCount += len(attrs.get('Lane',""))
+        self.ReadsCount += int(attrs.get('Count',""))
+      #else:
+      #  self.Msg += ' | name = '+name+', currlibid = '+ self.currlibid
+    except: 
+      self.Msg = 'failed parsing xml file'
     return
 
   #def characters (self, ch):
@@ -48,10 +52,14 @@ def getLibReads(libid):
   parser = make_parser()   
   curHandler = LibInfoHandler(searchTerm)
   parser.setContentHandler(curHandler)
-  parser.parse(open('/htsworkflow/htswfrontend/htswfrontend/htsw_reports/LibInfo/LibraryInfo.xml'))
+  folder_loc = '/htsworkflow/htswfrontend/htswfrontend'  # DEV
+  #folder_loc = '/Library/WebServer/gaworkflow/gaworkflow/frontend'  # PROD
+  parser.parse(open(folder_loc+'/htsw_reports/LibInfo/LibraryInfo.xml'))
   arRes = []
   arRes.append(curHandler.LanesCount) 
   arRes.append(curHandler.ReadsCount)
+  arRes.append(curHandler.Msg)
+
   return arRes
 
 def getWebPage(url,params):
@@ -64,7 +72,7 @@ def getWebPage(url,params):
 
 def refreshLibInfoFile(request): 
  varStatus = 'getting conf file from exp trac server'
- url = 'http://m304-apple-server.stanford.edu/ENCODE/LibraryInfo.xml'
+ url = settings.TASKS_PROJS_SERVER+'/LibraryInfo.xml'
  params = {}
  readw = getWebPage(url,params)
  # make sure file content starts as xml
@@ -80,7 +88,9 @@ def refreshLibInfoFile(request):
    if day < 10: day = "0"+day.__str__()
    else: day = day.__str__()
    mydate = year+month+day
-   folder = '/htsworkflow/htswfrontend/htswfrontend/htsw_reports/LibInfo/'
+   folder_loc = '/htsworkflow/htswfrontend/htswfrontend'  # DEV                                                                                                                          
+   #folder_loc = '/Library/WebServer/gaworkflow/gaworkflow/frontend'  # PROD
+   folder = folder_loc+'/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')