Selaa lähdekoodia

- 重写了处理逻辑
收工!

NandHyf 1 vuosi sitten
vanhempi
commit
eeb6827498
7 muutettua tiedostoa jossa 130 lisäystä ja 112 poistoa
  1. 9 27
      Controller.py
  2. 68 2
      KBC-chart.drawio
  3. 31 18
      Stateful.py
  4. 22 4
      config.toml
  5. 0 61
      example_Controller.py
  6. 0 0
      lang_en.toml
  7. 0 0
      lang_zh-s.toml

+ 9 - 27
Controller.py

@@ -1,29 +1,6 @@
 import Exceptions
 import Stateful, View
 
-class Command():
-    def list():
-        pass
-
-    def add():
-        pass
-    
-    def delete():
-        pass
-
-    def edit():
-        pass
-    
-    def move():
-        pass
-
-    def backHome():
-        pass
-
-    def backPrevious():
-        pass
-    
-
 
 class Client():
 
@@ -48,8 +25,13 @@ class Client():
         print(Stateful.matchTomlKey("config.toml", lang, "command-help"))
 
 
-    def handleCommand(commad):
-        pass
+    def transitCommand():
+        app_command = input("~/: ").split(" ")
+
+
+        app_command.append(dbType)
+        app_command.append(dbPath)
+        Stateful.transitHandler(app_command)
 
 
     def start():
@@ -57,14 +39,14 @@ class Client():
         Client.get_config()
 
         # test code
-
+        Client.transitCommand()
 
 
         # 2. list board
         # Command.list
 
         # 3. wait command input
-        command = input()
+
 
 
 if __name__ == "__main__":

+ 68 - 2
KBC-chart.drawio

@@ -1,6 +1,6 @@
-<mxfile host="app.diagrams.net" modified="2023-10-19T07:05:37.475Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46" etag="CYWbZvkdm9E_PX37ZPY1" version="22.0.5" type="device">
+<mxfile host="app.diagrams.net" modified="2023-10-19T08:27:22.379Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46" etag="S_qfIjpJ4JBCC-FvRaBK" version="22.0.5" type="device">
   <diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">
-    <mxGraphModel dx="1192" dy="536" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
+    <mxGraphModel dx="800" dy="443" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
       <root>
         <mxCell id="WIyWlLk6GJQsqaUBKTNV-0" />
         <mxCell id="WIyWlLk6GJQsqaUBKTNV-1" parent="WIyWlLk6GJQsqaUBKTNV-0" />
@@ -130,6 +130,72 @@
             <mxPoint x="350" y="360" as="targetPoint" />
           </mxGeometry>
         </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-1" value="Controller" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
+          <mxGeometry x="240" y="680" width="200" height="520" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-20" value="transit = app_command&lt;br style=&quot;border-color: var(--border-color);&quot;&gt;+ dbType&lt;br style=&quot;border-color: var(--border-color);&quot;&gt;+dbPath" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-1">
+          <mxGeometry x="40" y="90" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-30" value="var" style="whiteSpace=wrap;html=1;rounded=0;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-1">
+          <mxGeometry x="40" y="170" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-2" value="Stateful" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
+          <mxGeometry x="440" y="680" width="200" height="520" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-24" value="exec()" style="whiteSpace=wrap;html=1;rounded=0;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-2">
+          <mxGeometry x="40" y="90" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-28" value="return" style="whiteSpace=wrap;html=1;rounded=0;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-2">
+          <mxGeometry x="40" y="170" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-3" value="Model" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
+          <mxGeometry x="640" y="680" width="200" height="520" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-26" value="modify model" style="whiteSpace=wrap;html=1;rounded=0;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-3">
+          <mxGeometry x="40" y="90" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-4" value="UI" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
+          <mxGeometry x="40" y="680" width="200" height="520" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-5" value="开始" style="strokeWidth=2;html=1;shape=mxgraph.flowchart.terminator;whiteSpace=wrap;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-4">
+          <mxGeometry x="50" y="40" width="100" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-32" value="Refresh View" style="whiteSpace=wrap;html=1;rounded=0;" vertex="1" parent="Gs5nCNOHAZd9Ihr5n0aR-4">
+          <mxGeometry x="40" y="170" width="120" height="60" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;exitPerimeter=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-5" target="Gs5nCNOHAZd9Ihr5n0aR-20">
+          <mxGeometry relative="1" as="geometry">
+            <mxPoint x="260" y="800" as="targetPoint" />
+            <Array as="points">
+              <mxPoint x="140" y="800" />
+            </Array>
+          </mxGeometry>
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-8" value="App command" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="Gs5nCNOHAZd9Ihr5n0aR-6">
+          <mxGeometry x="-0.0056" relative="1" as="geometry">
+            <mxPoint x="-14" as="offset" />
+          </mxGeometry>
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-16" value="响应命令的逻辑" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
+          <mxGeometry x="40" y="650" width="100" height="30" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-25" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-20" target="Gs5nCNOHAZd9Ihr5n0aR-24">
+          <mxGeometry relative="1" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-27" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-24" target="Gs5nCNOHAZd9Ihr5n0aR-26">
+          <mxGeometry relative="1" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-29" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-26" target="Gs5nCNOHAZd9Ihr5n0aR-28">
+          <mxGeometry relative="1" as="geometry">
+            <mxPoint x="540" y="770" as="sourcePoint" />
+          </mxGeometry>
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-31" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-28" target="Gs5nCNOHAZd9Ihr5n0aR-30">
+          <mxGeometry relative="1" as="geometry" />
+        </mxCell>
+        <mxCell id="Gs5nCNOHAZd9Ihr5n0aR-33" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="Gs5nCNOHAZd9Ihr5n0aR-30" target="Gs5nCNOHAZd9Ihr5n0aR-32">
+          <mxGeometry relative="1" as="geometry" />
+        </mxCell>
       </root>
     </mxGraphModel>
   </diagram>

+ 31 - 18
Stateful.py

@@ -3,6 +3,7 @@ import base64, datetime
 import tomlkit, sqlite3
 
 # kw == 'k'ey 'w'ord; dt_now = date&&time in UTC
+# Please consider adding more salt to prevent uid duplication(specially under multi-user use case)
 def generate_uid(kw):
     dt_now = str(datetime.datetime.now(datetime.timezone.utc))
     genText = str.encode(kw + "_" + dt_now)
@@ -50,7 +51,7 @@ def matchTomlKeys(tomlName, keys, table=None) -> list:
             try:
                 rl.append(doc.item(key))
             except:
-                Exceptions.err0()
+                pass
 
         return rl
     
@@ -67,35 +68,47 @@ def matchTomlKeys(tomlName, keys, table=None) -> list:
 
 
 # Sqlite3
-def connect_sqlite3(dbPath):
+def operate_sqlite3(dbPath, command):
     con = sqlite3.connect(dbPath)
-
     cur = con.cursor()
 
+    # 
+    cur.execute()
+    
     cur.close()
 
-def closeConnect():
-    pass
 
-def list_SELECT():
-    pass
+# Markdown
 
-def add_CREATE():
-    pass
 
-def add_INSERT_INTO():
-    pass
+# csv
 
-def edit_UPDATE():
-    pass
 
-def delete_status2del():
-    pass
+# MongoDB
 
-# Markdown
 
+# ----- Transit Command Handler -----
+def transitHandler(transit_command):
+    dbType = transit_command[-1]
+    dbPath = transit_command[-2]
+    exec_command = transit_command[0:-3]
 
-# csv
+    if dbType == "sqlite3":
+        operate_sqlite3(dbPath, exec_command)
+
+    if dbType == "csv":
+        pass
+
+    if dbType == "mongodb":
+        pass
+
+    if dbType == "toml":
+        pass
+
+    if dbType == "md":
+        pass
 
+    else:
+        input("err 1: correct db not found")
+        exit()
 
-# MongoDB

+ 22 - 4
config.toml

@@ -3,7 +3,7 @@
 lang = "en"
 
 # tree/expand
-# listStyle = "tree"
+listStyle = "tree"
 
 # >>>need some guidance here<<<
 EnableGlobalCommand = false
@@ -23,9 +23,28 @@ type = "sqlite3"
 path = "test.db"
 
 
+# ----- DB Syntax Translation -----
+[sqlite3]
+list = "SELECT"
+add = "INSERT INTO"
+edit = "UPDATE"
+
+
+[csv]
+
+
+[mongodb]
+
+
+[toml_as_DB]
+
+
+[md_as_DB]
+
+
 # ----- helps -----
 # 难道用asicⅡ然后根据系统语言转换?
-# 或者是单独的.toml/.txt 文本文件也行
+# 或者是单独的.toml/.txt 文本文件也行 <<< 采用这个方案
 [command-help]
 en = """
 Help texts in en
@@ -37,5 +56,4 @@ Help texts in zh-s
 
 [could-not-find]
 en = "could not find"
-zh-s = "找不到"
-
+zh-s = "找不到"

+ 0 - 61
example_Controller.py

@@ -1,61 +0,0 @@
-import Stateful
-
-
-class Command():
-    def __init__(self, order, obj0=[], tag0=None, content=[], tag1=None, obj1=None) -> None:
-        self.enableGlobalCommand = False
-        self.order = order
-        self.obj0 = obj0
-        self.tag0 = tag0
-        self.content = content
-        self.tag1 = tag1
-        self.obj1 = obj1
-
-    def help():
-        pass
-
-    def exit():
-        exit()
-
-    def export():
-        pass
-
-    def list_board():
-        pass
-    
-    def list_event():
-        pass
-
-    def select_board():
-        pass
-
-    def add():
-        pass
-
-    def edit():
-        pass
-
-    def move():
-        pass
-
-    def delete():
-        pass
-
-    def archive():
-        pass
-
-    def back2home():
-        pass
-
-    def get_info():
-        pass
-    
-    def get_num():
-        pass
-
-
-class Board():
-    pass
-
-class Event():
-    pass

+ 0 - 0
lang_en.toml


+ 0 - 0
lang_zh-s.toml