Bladeren bron

重写了读取配置文件的方法

NandHyf 1 jaar geleden
bovenliggende
commit
c9b28ae5fc
3 gewijzigde bestanden met toevoegingen van 39 en 60 verwijderingen
  1. 13 36
      Controller.py
  2. 9 9
      Stateful.py
  3. 17 15
      dev.toml

+ 13 - 36
Controller.py

@@ -2,13 +2,12 @@ import Alt, Stateful
 import datetime
 
 
-class kbc_config():
-    def __init__(self) -> None:
-        global configs
-        configs = {}
-
+class kbc_controller():
     def get_config():
-        pass
+        tomls = Stateful.MatchTomlTable("dev.toml", "app_config", "dict")
+        global app_config
+        app_config = tomls["app_config"]
+
 
     def get_help():
         pass
@@ -17,28 +16,6 @@ class kbc_config():
         pass
 
 
-class Client():
-
-    def get_config():
-        # [todo 4]
-        c = ['DBType', 'DBPath', 'lang', 'listStyle', 'displayTimeZone']
-        # rl == 'r'eturn 'l'ist
-        rl = Stateful.MatchTomlKeys("dev.toml", c)
-        
-        global lang, listStyle, dbType, dbPath, displayTimeZone, currentPath
-        dbType = rl[0]
-        dbPath = rl[1]
-        lang = rl[2]
-        listStyle = rl[3]
-        displayTimeZone = rl[4]
-        currentPath = ""
-
-
-    # [todo 4]
-    def get_help():
-        print(Stateful.MatchTomlKey("clean_config.toml", lang, "command-help"))
-
-
     # [todo 3]
     def InUTC(timeZone=0):
         dt_now_UTC0 = str(datetime.datetime.now(datetime.timezone.utc))
@@ -58,12 +35,12 @@ class Client():
             # Input exception check
             
             # [todo 1]
-            # Client.InputCheck(app_commands)
+            # Controller.InputCheck(app_commands)
             if len(app_commands) < 5:
                 # Add CurrentPath && DBType && Path
                 app_commands.append(currentPath)
-                app_commands.append(dbPath)
-                app_commands.append(dbType)
+                app_commands.append(app_config["dbPath"])
+                app_commands.append(app_config["dbType"])
 
                 Stateful.Handler(app_commands)
 
@@ -83,12 +60,12 @@ class Client():
         # 0. init
         
         # 1. get config
-        Client.get_config()
+        kbc_controller.get_config()
 
         # 2.
-        startState = Stateful.Handler(['/', dbPath, dbType])
+        startState = Stateful.Handler(['/', app_config["dbPath"], app_config["dbType"]])
         print(startState)
-        Client.TransitCommand()
+        kbc_controller.TransitCommand()
 
 
 class View:
@@ -110,6 +87,6 @@ class LLM():
 
 
 if __name__ == "__main__":
-    # Client.start()
-    Stateful.oc["dt"] = "s"
+    # Controller.start()
+    kbc_controller.get_config()
     

+ 9 - 9
Stateful.py

@@ -5,18 +5,18 @@ import tomlkit, sqlite3
 
 # ----- Operating Cursor -----
 oc = {
-    "dt":str, 
-    "dp":str,
+    "dt":str, # DBType
+    "dp":str, # DBPath
 
-    "cp":list, 
-    "pp":list,
+    "cp":list, # CurrentPath
+    "pp":list, # PreviousPath
 
     "next_move":str,
 
-    "tp":list, 
-    "tp_in":list, 
-    "tp_to":list, 
-    "tp_attr":str
+    "tp":list, # TargetPath
+    "tp_in":list, # ~ after command parameter "in"(&& before command parameter "to")
+    "tp_to":list, # ~ after command parameter "to"
+    "tp_attr":str # ~ like "-name" in "edit -name oldName to newName"
     }
 # some thoughts:
 # class oc():
@@ -35,7 +35,7 @@ def GetTomlDoc(tomlName:str):
 
             return doc
         
-    except:
+    except FileNotFoundError:
         input("error 0: could not found correct config file") 
         exit()
     

+ 17 - 15
dev.toml

@@ -1,16 +1,3 @@
-# ----- App Configuration -----
-StrictMode = true
-
-DBType = "sqlite3"
-DBPath = "dev.db"
-
-Lang = "en"
-ListStyle = "tree"
-DisplayTimeZone = "utc+8"
-
-Start_as_LLM_server = false
-
-
 # ----- DB Configuration -----
 # Just a better reference for dev.db, no functional use(yet)
 [compact_main]
@@ -34,14 +21,29 @@ c6 = "operator"
 c7 = "state"
 
 
+# ----- App Configuration -----
+[app_config]
+StrictMode = true
+
+DBType = "sqlite3"
+DBPath = "dev.db"
+
+Lang = "en"
+ListStyle = "tree"
+DisplayTimeZone = "utc+8"
+
+Start_as_LLM_server = false
+
+
 # ----- Some Notes -----
 # compact_main.status:
+#   10 = alive
 #   -10 = deleted
-#    10 = alive
 
 # log_action.state:
+#   10 = successfully committed
 #   -10 = committed failed
-#    10 = successfully committed
+
 
 # Set integer prime key: <columnName> INTEGER PRIMARY KEY ASC
 # status: alive/deleted/unclassified(event only)