NandHyf 1 year ago
parent
commit
bf18f5514b
5 changed files with 27 additions and 22 deletions
  1. 4 4
      Controller.py
  2. 16 11
      Stateful.py
  3. BIN
      __pycache__/Stateful.cpython-311.pyc
  4. 7 7
      dev_config.toml
  5. BIN
      命令结构.png

+ 4 - 4
Controller.py

@@ -24,13 +24,13 @@ class Client():
     def TransitCommand():
         # do while or for (1)
         while(1):
-            app_command = input(currentPath + "/: ", ).split(" ")
+            app_commands = input(currentPath + "/: ", ).split(" ")
             # Input exception check
             
             # Add DBType && Path
-            app_command.append(dbPath)
-            app_command.append(dbType)
-            Stateful.TransitHandler(app_command)
+            app_commands.append(dbPath)
+            app_commands.append(dbType)
+            Stateful.PackHandler(app_commands)
 
 
     def start():

+ 16 - 11
Stateful.py

@@ -63,16 +63,19 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
         d = doc.unwrap()
 
         for key in keys:
-            rl.append(d[table][key])
+            try:
+                rl.append(d[table][key])
+            except:
+                pass
 
         return rl
 
 
 # Sqlite3
-def Operate_sqlite3(dbPath, dbType, match_commands):
-    matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, dbType)
+def Operate_sqlite3(dbPath, match_commands):
+    matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, "sqlite3")
 
-    s = " "
+    s = " ".join(matchedSyntax)
 
     con = sqlite3.connect(dbPath)
     cur = con.cursor()
@@ -90,13 +93,12 @@ def Operate_sqlite3(dbPath, dbType, match_commands):
 
 
 # ----- Transit Command Handler -----
-def TransitHandler(transit_commands):
-    dbType = transit_commands[-1]
-    dbPath = transit_commands[-2]
-    match_commands = transit_commands[0:-2]
+def PackHandler(app_commands):
+    dbType = app_commands[-1]
+    dbPath = app_commands[-2]
 
     if dbType == "sqlite3":
-        Operate_sqlite3(dbPath, dbType, match_commands)
+        Operate_sqlite3(dbPath, app_commands)
 
     elif dbType == "csv":
         pass
@@ -117,7 +119,10 @@ def TransitHandler(transit_commands):
 
 if __name__ == "__main__":
     
-    a_c = ['add', 'board']
+    a_c = ['add', 'board', 'testBoardName', 'test.db', 'sqlite3']
+    a_c1 = ['edit', 'board', 't_boardName', 'to', 't_newBoardName', 'test.db', 'sqlite3']
     e_c = ['add', 'board']
-    Operate_sqlite3("test.db", "sqlite3", e_c)
+    
+    # Operate_sqlite3("test.db", a_c1)
+    PackHandler(a_c)
     

BIN
__pycache__/Stateful.cpython-311.pyc


+ 7 - 7
dev_config.toml

@@ -10,18 +10,18 @@ displayTime = "utc+8"
 [sqlite3]
 # app_command[0] -> command1
 "/" = "SELECT name FROM sqlite_master WHERE type='table';"
-list = "SELECT"
-add = "INSERT INTO"
-edit = "UPDATE"
-delete = "UPDATE" # change stauts to "deleted"
+list = "SELECT "
+add = "INSERT INTO "
+edit = "UPDATE "
+delete = "UPDATE " # change stauts to "deleted"
 
 # app_command[1] -> obj1
 board = "TABLE {boardName} "
-class = ""
-event = ""
+class = "TABLE {className} "
+event = "TABLE {eventName} "
 
 # app_command[2] -> tag1
 "-name" = ""
 "-d" = ""
 "-ddl" = ""
-to = ""
+to = "here is to"

BIN
命令结构.png