From 4ea3452676f9fdf91bdf3b4b295cb8de5f80fc6b Mon Sep 17 00:00:00 2001
From: wanli <wanliofficial@aliyun.com>
Date: Tue, 13 Apr 2021 21:28:10 +0800
Subject: [PATCH] update

---
 tools/config.json                  |  0
 tools/gen_code.py                  |  0
 tools/templates/controller.tpl     |  0
 tools/templates/model.tpl          |  0
 tools/templates/resource.tpl       |  0
 tools/templates/route.tpl          |  0
 tools/templates/signal_manager.tpl |  0
 tools/webcreator/__init__.py       |  1 +
 tools/webcreator/log.py            | 31 +++++++++++++++
 tools/webcreator/response.py       | 31 +++++++++++++++
 tools/webcreator/signals_slots.py  | 62 ++++++++++++++++++++++++++++++
 11 files changed, 125 insertions(+)
 create mode 100644 tools/config.json
 create mode 100644 tools/gen_code.py
 create mode 100644 tools/templates/controller.tpl
 create mode 100644 tools/templates/model.tpl
 create mode 100644 tools/templates/resource.tpl
 create mode 100644 tools/templates/route.tpl
 create mode 100644 tools/templates/signal_manager.tpl
 create mode 100644 tools/webcreator/__init__.py
 create mode 100644 tools/webcreator/log.py
 create mode 100644 tools/webcreator/response.py
 create mode 100644 tools/webcreator/signals_slots.py

diff --git a/tools/config.json b/tools/config.json
new file mode 100644
index 0000000..e69de29
diff --git a/tools/gen_code.py b/tools/gen_code.py
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templates/controller.tpl b/tools/templates/controller.tpl
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templates/model.tpl b/tools/templates/model.tpl
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templates/resource.tpl b/tools/templates/resource.tpl
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templates/route.tpl b/tools/templates/route.tpl
new file mode 100644
index 0000000..e69de29
diff --git a/tools/templates/signal_manager.tpl b/tools/templates/signal_manager.tpl
new file mode 100644
index 0000000..e69de29
diff --git a/tools/webcreator/__init__.py b/tools/webcreator/__init__.py
new file mode 100644
index 0000000..6af601c
--- /dev/null
+++ b/tools/webcreator/__init__.py
@@ -0,0 +1 @@
+# -*- coding: utf_8 -*-
\ No newline at end of file
diff --git a/tools/webcreator/log.py b/tools/webcreator/log.py
new file mode 100644
index 0000000..61127d4
--- /dev/null
+++ b/tools/webcreator/log.py
@@ -0,0 +1,31 @@
+# -*- coding: utf_8 -*-
+
+############################
+#   Log
+#   日志
+############################
+
+import logging
+from logging.handlers import RotatingFileHandler
+import os
+
+logPath = os.getcwd() + os.path.sep + "logs"
+if not os.path.exists(logPath):
+    os.makedirs(logPath)
+
+fh = RotatingFileHandler("logs/running.log", maxBytes=10 * 1024 * 1024, backupCount=100)
+fh.setLevel(logging.DEBUG)
+
+# log write in console
+ch = logging.StreamHandler()
+ch.setLevel(logging.WARNING)
+
+# log formatter
+formatter = logging.Formatter('[%(asctime)s][%(levelname)7s] [%(filename)15s%(funcName)15s%(lineno)06s] %(message)s')
+fh.setFormatter(formatter)
+ch.setFormatter(formatter)
+
+logger = logging.root
+logger.setLevel(logging.INFO)
+logger.addHandler(fh)
+logger.addHandler(ch)
\ No newline at end of file
diff --git a/tools/webcreator/response.py b/tools/webcreator/response.py
new file mode 100644
index 0000000..bbe8e30
--- /dev/null
+++ b/tools/webcreator/response.py
@@ -0,0 +1,31 @@
+# -*- coding: utf_8 -*-
+
+############################
+#   Response
+#   响应
+############################
+
+class ResponseCode(object):
+    OK = (200, 'ok')
+    NO_DATA = (204, 'no data')
+    NOT_FOUND = (404, 'not found')
+    NOTHING_CHANGE = (304, 'nothing change')
+    REQUEST_ERROR = (400, 'request error')
+    AUTHORIZATION_ERROR = (401, 'authentication error')
+    INVAILD_REQUEST = (403, 'invaild request')
+    PARAMETER_ERROR = (4001, 'parameter error')
+    PARAMETER_NULL = (4002, 'parameter is null')
+    PASSWORD_ERROR = (4003, 'password error')
+    EXISTS_ERROR = (4004, 'record exists')
+    INVAILD_ROLE_ERROR = (4005, 'invaild role error')
+    ACCOUNT_DISABLED = (4006, 'account is disabled')
+    SERVER_ERROR = (500, 'server error')
+    DB_ERROR = (5001, 'database error')
+    UNKNOWN_ERROR = (5003, 'unknown error')
+
+def response_result(code, msg=None, data=None, **kwargs):
+    if msg is None:
+        msg = code[1]
+    result = { 'code': code[0], 'message': msg, 'data': data }
+    result.update(kwargs)
+    return result
\ No newline at end of file
diff --git a/tools/webcreator/signals_slots.py b/tools/webcreator/signals_slots.py
new file mode 100644
index 0000000..dba97f4
--- /dev/null
+++ b/tools/webcreator/signals_slots.py
@@ -0,0 +1,62 @@
+# -*- coding: utf_8 -*-
+
+############################
+#   Signals-Slots
+#   信号槽
+############################
+
+class PySignal(object):
+    """
+    Simple event class used to provide hooks for different types of events in Locust.
+
+    Here's how to use the EventHook class::
+
+        my_event = PySignal()
+        def on_my_event(a, b, **kw):
+            print "Event was fired with arguments: %s, %s" % (a, b)
+        my_event += on_my_event
+        my_event.fire(a="foo", b="bar")
+        my_event.emit(a="foo", b="bar")
+
+    """
+
+    def __init__(self):
+        self._handlers = []
+
+    def __iadd__(self, handler):
+        return self.connect(handler)
+
+    def __isub__(self, handler):
+        return self.disconnect(handler)
+
+    def connect(self, handler):
+        self._handlers.append(handler)
+        return self
+
+    def disconnect(self, handler):
+        self._handlers.remove(handler)
+        return self
+
+    def fire(self, *args, **kwargs):
+        
+        return self.emit(*args, **kwargs)
+
+    def emit(self, *args, **kwargs):
+        rets = {}
+        for handler in self._handlers:
+            ret = handler(*args, **kwargs)
+            rets[handler.__name__] = ret
+        if len(rets) == 1:
+            return list(rets.values())[0]  # list()用来兼容python3
+        return rets
+
+
+if __name__ == '__main__':
+    my_event = PySignal()
+
+    def on_my_event(a, b, **kw):
+        print(a, b)
+        print(kw)
+    my_event.connect(on_my_event)
+    my_event.fire(1, 2, c="foo", d="bar")
+    my_event.emit(3, 4, e="foo", f="bar")
-- 
2.24.1