Browse Source

OpenShift migration

Suren A. Chilingaryan 4 years ago
parent
commit
84a84a1b25
2 changed files with 22 additions and 21 deletions
  1. 1 1
      config.yaml
  2. 21 20
      core.py

+ 1 - 1
config.yaml

@@ -1,7 +1,7 @@
 background: HIU_Background.svg
 password: PCE_D4t3nb4nk!
 polling: '30'
-port: '9876'
+port: '8080'
 pw_designer: ipe-test
 script: services/getdata.php
 server: http://pcebessadei.competence-e.kit.edu/adei-battery/

+ 21 - 20
core.py

@@ -135,10 +135,10 @@ def fetchDataADEI():
             for chunk in image.iter_content():
                 handle.write(chunk)
 
-    with open(".tmp.yaml", 'w') as stream_tmp:
+    with open("/tmp/.tmp.yaml", 'w') as stream_tmp:
         stream_tmp.write(yaml.dump(cache_data, default_flow_style=False))
-    src_file = os.getcwd() + "/.tmp.yaml"
-    dst_file = os.getcwd() + "/cache.yaml"
+    src_file = "/tmp/.tmp.yaml"
+    dst_file = "/tmp/cache.yaml"
     shutil.copy(src_file, dst_file)
 
 
@@ -149,7 +149,7 @@ class BaseHandler(tornado.web.RequestHandler):
 
 class ListHandler(tornado.web.RequestHandler):
     def get(self):
-        with open("cache.yaml", 'r') as stream:
+        with open("/tmp/cache.yaml", 'r') as stream:
             try:
                 response = yaml.load(stream)
             except yaml.YAMLError as exc:
@@ -180,7 +180,7 @@ class SetTimerHandler(tornado.web.RequestHandler):
 class DesignerHandler(tornado.web.RequestHandler):
     def get(self):
         print "In designer mode."
-        with open("cache.yaml", 'r') as stream:
+        with open("/tmp/cache.yaml", 'r') as stream:
             try:
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
@@ -258,7 +258,7 @@ class StatusHandler(tornado.web.RequestHandler):
             except yaml.YAMLError as exc:
                 print(exc)
 
-        with open("cache.yaml", 'r') as vstream:
+        with open("/tmp/cache.yaml", 'r') as vstream:
             try:
                 cache_data = yaml.load(vstream)
             except yaml.YAMLError as exc:
@@ -468,7 +468,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
 
 class GetDataHandler(tornado.web.RequestHandler):
     def get(self):
-        with open("cache.yaml", 'r') as stream:
+        with open("/tmp/cache.yaml", 'r') as stream:
             try:
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
@@ -500,7 +500,7 @@ class AuthLoginHandler(BaseHandler):
         if auth:
             self.set_current_user(username)
             print "In designer mode."
-            with open("cache.yaml", 'r') as stream:
+            with open("/tmp/cache.yaml", 'r') as stream:
                 try:
                     cache_data = yaml.load(stream)
                 except yaml.YAMLError as exc:
@@ -544,19 +544,20 @@ rt = RepeatedTimer(int(config["polling"]), fetchDataADEI)
 
 application = tornado.web.Application([
     (r"/auth/login/?", AuthLoginHandler),
-    (r"/"+config['title'].lower()+"/version/?", VersionHandler),
-    (r"/"+config['title'].lower()+"/list/?", ListHandler),
-    (r"/"+config['title'].lower()+"/start/?", StartHandler),
-    (r"/"+config['title'].lower()+"/backup/?", BackupHandler),
-    (r"/"+config['title'].lower()+"/stop/?", StopHandler),
-    (r"/"+config['title'].lower()+"/designer/?", DesignerHandler),
-    (r"/"+config['title'].lower()+"/status/?", StatusHandler),
-    (r"/"+config['title'].lower()+"/save/?", SaveHandler),
-    (r"/"+config['title'].lower()+"/update/?", UpdateHandler),
-    (r"/"+config['title'].lower()+"/getdata/?", GetDataHandler),
-    (r"/"+config['title'].lower()+"/timer/(?P<duration>[^\/]+)/?",
+    (r"/version/?", VersionHandler),
+    (r"/list/?", ListHandler),
+    (r"/start/?", StartHandler),
+    (r"/backup/?", BackupHandler),
+    (r"/stop/?", StopHandler),
+    (r"/designer/?", DesignerHandler),
+    (r"/", StatusHandler),
+    (r"/status/?", StatusHandler),
+    (r"/save/?", SaveHandler),
+    (r"/update/?", UpdateHandler),
+    (r"/getdata/?", GetDataHandler),
+    (r"/timer/(?P<duration>[^\/]+)/?",
      SetTimerHandler),
-    (r"/"+config['title'].lower()+"/add/(?P<db_server>[^\/]+)/?"
+    (r"/add/(?P<db_server>[^\/]+)/?"
      "(?P<db_name>[^\/]+)/?(?P<db_group>[^\/]+)/?(?P<sensor_name>[^\/]+)?",
      AdeiKatrinHandler)
 ], debug=True, static_path=os.path.join(root, 'static'),