Przeglądaj źródła

ensure epics completes successfully

Jalal Mostafa 2 lat temu
rodzic
commit
f7482a25b7
2 zmienionych plików z 33 dodań i 29 usunięć
  1. 18 13
      core.py
  2. 15 16
      res/adei2rest.py

+ 18 - 13
core.py

@@ -126,14 +126,17 @@ def fetch_epics():
 
     # now wait for get() to complete
     ca.poll()
-    for chid in pvchids:
-        val = ca.get_complete_with_metadata(chid, ftype=14)
-        timestamp = calendar.timegm(
-            datetime.datetime.utcfromtimestamp(val['timestamp']).timetuple())
-        pvdata[ca.name(chid)] = {
-            'timestamp': timestamp,
-            'value': val['value']
-        }
+    for idx, chid in enumerate(pvchids):
+        try:
+            val = ca.get_complete_with_metadata(chid, ftype=14)
+            timestamp = calendar.timegm(
+                datetime.datetime.utcfromtimestamp(val['timestamp']).timetuple())
+            pvdata[ca.name(chid)] = {
+                'timestamp': timestamp,
+                'value': val['value']
+            }
+        except Exception as e:
+            print(pvs[idx], e)
 
     pvdata['time'] = strftime("%Y-%m-%d %H:%M:%S")
 
@@ -371,7 +374,7 @@ class UpdateHandler(tornado.web.RequestHandler):
 
             data = requests.get(url, auth=(os.environ["BORA_ADEI_USERNAME"],
                                 os.environ["BORA_ADEI_PASSWORD"]))
-            cr = data.content
+            cr = str(data.content)
             cr = cr.split(",")
 
             match_token = item
@@ -441,7 +444,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
             auth=(os.environ["BORA_ADEI_USERNAME"],
                   os.environ["BORA_ADEI_PASSWORD"])
         )
-        cr = data.content
+        cr = str(data.content)
         cr = cr.splitlines()
         cr = ",".join(cr)
         cr = cr.split(",")
@@ -470,12 +473,14 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
             db_mask = None
 
         for i, item in enumerate(cr):
-            if "[" and "]" in item.strip():
-                lhs = re.match(r"[^[]*\[([^]]*)\]", item.strip()).groups()[0]
+            normalized_item = item.strip()
+            if "[" in normalized_item and "]" in normalized_item:
+                lhs = re.match(r"[^[]*\[([^]]*)\]",
+                               normalized_item).groups()[0]
                 if lhs == params['sensor_name']:
                     db_mask = i - 1
             else:
-                if item.strip() == match_token:
+                if normalized_item == match_token:
                     db_mask = i - 1
         if db_mask is None:
             response = {"Error": "Cannot find variable on ADEI server."}

+ 15 - 16
res/adei2rest.py

@@ -1,22 +1,23 @@
 #!/usr/bin/python
-import sys, getopt
+import sys
+import getopt
 
 
 def main(sensor, mystr):
-    print mystr
+    print(mystr)
     query = mystr.split("#")[1]
-    print mystr.split("#")
+    print(mystr.split("#"))
     cmds = query.split("&")
-    
-    print cmds 
-   
+
+    print(cmds)
+
     db_server = None
     db_name = None
     db_group = None
     for item in cmds:
-        print item
+        print(item)
         subtitle = item.split("=")
-        print subtitle
+        print(subtitle)
         if subtitle[0].strip() == "db_server":
             db_server = subtitle[1].strip()
         elif subtitle[0].strip() == "db_name":
@@ -24,21 +25,19 @@ def main(sensor, mystr):
         elif subtitle[0].strip() == "db_group":
             db_group = subtitle[1].strip()
 
-    #print query
-    print "check"
-    print db_server   
+    # print query
+    print("check")
+    print(db_server)
 
- 
     rest_str = []
     rest_str.append("http://ipepc57.ipe.kit.edu:8888/add")
     rest_str.append(db_server)
     rest_str.append(db_name)
     rest_str.append(db_group)
     rest_str.append(sensor)
-  
- 
-    print "/".join(rest_str)
+
+    print("/".join(rest_str))
 
 
 if __name__ == "__main__":
-   main(sys.argv[1], sys.argv[2])
+    main(sys.argv[1], sys.argv[2])