diff --git a/libs/data.py b/libs/data.py
index e06e1bb..c0beaf8 100644
--- a/libs/data.py
+++ b/libs/data.py
@@ -14,7 +14,7 @@ import time
from tornado.httpclient import HTTPClient, HTTPRequest
from yuuki_core.ttypes import OpType
-from .data_mds import listen as mds_listen
+from .data_mds import PythonMDS
from .thread_control import Yuuki_Multiprocess
from .thread_control import Yuuki_Thread
@@ -79,37 +79,37 @@ class Yuuki_Data:
if not os.path.isdir(self.DataPath):
os.mkdir(self.DataPath)
- for Type in self.DataType:
- name = self.DataPath + self.DataName.format(Type)
+ for data_type in self.DataType:
+ name = self.DataPath + self.DataName.format(data_type)
+
+ test_result = 0
if not os.path.isfile(name):
with open(name, "w") as f:
f.write("")
- Type = 0
else:
with open(name, "r") as f:
try:
json.load(f)
- Type = 0
except ValueError:
- Type = 1
- assert Type == 0, "{}\nJson Test Error".format(name)
+ test_result = 1
+ assert test_result == 0, "{}\nJson Test Error".format(name)
- for Type in self.DataType:
- name = self.DataPath + self.DataName.format(Type)
with open(name, "r+") as f:
text = f.read()
if text != "":
- self.Data[Type] = json.loads(text)
+ self.Data[data_type] = json.loads(text)
else:
- self.Data[Type] = self.DataType[Type]
- f.write(json.dumps(self.Data[Type]))
+ self.Data[data_type] = self.DataType[data_type]
+ f.write(json.dumps(self.Data[data_type]))
+
return self._MDS_Initialize()
def _MDS_Initialize(self):
if self.threading:
+ mds = PythonMDS()
self.mdsHost = "http://localhost:2019/"
self.mdsCode = "{}.{}".format(random.random(), time.time())
- self.MdsThreadControl.add(mds_listen, (self.mdsCode,))
+ self.MdsThreadControl.add(mds.listen, (self.mdsCode,))
# MDS Sync
diff --git a/libs/data_mds.py b/libs/data_mds.py
index 45459f5..6e2430d 100644
--- a/libs/data_mds.py
+++ b/libs/data_mds.py
@@ -10,103 +10,23 @@
# Initializing
import json
+from abc import ABC
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, RequestHandler
-switch_data = {}
+# Works
+_work = {}
auth_code = 0
-# Functions
-def update(data):
- global switch_data
- # noinspection PyBroadException
- try:
- if type(data["path"]) is list:
- over = query({"path": data["path"]})
- over.get("data").update(data["data"])
- return {"status": 200}
- return {"status": 400}
- except:
- return {"status": 500}
-
-
-def delete(data):
- global switch_data
- # noinspection PyBroadException
- try:
- if type(data["path"]) is list:
- over = query({"path": data["path"]})
- over.get("data").pop(data["data"])
- return {"status": 200}
- return {"status": 400}
- except:
- return {"status": 500}
-
-
-def query(data):
- global switch_data
- query_data = data["path"]
- # noinspection PyBroadException
- try:
- if type(switch_data) is dict and type(query_data) is list:
- result = switch_data
- query_len = len(query_data) - 1
- for count, key in enumerate(query_data):
- if key in result:
- if count < query_len:
- if type(result.get(key)) is not dict:
- result = 1 # "unknown_type" + type(source_data.get(key))
- break
- result = result.get(key)
- else:
- result = 2 # "unknown_key"
- break
-
- return {"status": 200, "data": result}
- return {"status": 400}
- except:
- return {"status": 500}
-
-
-def sync(data):
- global switch_data
- # noinspection PyBroadException
- try:
- switch_data = data["path"]
- return {"status": 200}
- except:
- return {"status": 500}
-
-
-def yuukiLimitDecrease(data):
- global switch_data
- # noinspection PyBroadException
- try:
- switch_data["LimitInfo"][data["path"]][data["userId"]] -= 1
- return {"status": 200}
- except:
- return {"status": 500}
-
-
-# Works
-_work = {
- "UPT": update,
- "DEL": delete,
- "GET": query,
- "SYC": sync,
- "YLD": yuukiLimitDecrease
-}
-
-
-class IndexHandler(RequestHandler):
+class IndexHandler(RequestHandler, ABC):
def get(self):
self.write('''
Python MDS Server
To switch data in multiprocessing.