Browse Source

修改了Stateful的方法, 去掉了对目标文件的对象归类, 直接暴露方法

NandHyf 1 year ago
parent
commit
0aa15b17e8
3 changed files with 84 additions and 43 deletions
  1. 28 5
      Controller.py
  2. 31 34
      Stateful.py
  3. 25 4
      config.toml

+ 28 - 5
Controller.py

@@ -2,21 +2,44 @@
 
 import Stateful, View
 
+class Command():
+    pass
 
-class client():
+class Client():
     def __init__(self) -> None:
         pass
 
+
     def get_config():
-        pass
+        doc = Stateful.getTomlDoc("config.toml")
+        
+        # T-B-C...
+        global lang
+        lang = ""
+
+
+    def get_help():
+        t = Stateful.matchTomlKey("config.toml", "lang")
+        print(t)
+
 
     def excute():
         pass
 
+
     def start():
-        pass
+        # get config
+        Client.get_config()
+
+        # test aera
+        Client.get_help()
+
+        # list board
+        # Command.list
+
+        # wait command input
+        command = input()
 
 
 if __name__ == "__main__":
-    
-    app = input()
+    Client.start()

+ 31 - 34
Stateful.py

@@ -3,51 +3,48 @@ import os
 import base64, datetime
 import tomlkit, sqlite3
 
+# kw == Key Word
+# dt_now == date&&time in UTC
+def generate_uid(kw):
+    dt_now = str(datetime.datetime.now(datetime.timezone.utc))
+    genText = str.encode(kw + "_" + dt_now)
+    uid = base64.b64encode(genText)
+    
+    return(uid)
 
-class Trigger():
-    def __init__(self, T_obj) -> None:
-        self.T_obj = T_obj
-
-    def generate_uid(T_obj):
-        dt_now = str(datetime.datetime.now(datetime.timezone.utc))
-        genText = str.encode(T_obj + "_" + dt_now)
-        uid = base64.b64encode(genText)
-        
-        return(uid)
 
 
 # ----- Methods binding command to model -----
-class WithTxt():
-    pass
-    
-    
-class WithToml():
-    pass
 
-
-class WithSqlite3():
-    def __init__():
-        pass    
-    
-    def list_():
-        pass
+# Toml
+def getTomlDoc(tomlName):
+    try:
+        with open(tomlName, "rb") as t:
+            doc = tomlkit.load(t)
+            
+            if doc == {}:
+                print("Error 0: Could not find correct 'config.toml'")
+                exit()
+
+            return doc
+        
+    except:
+        print("Error 0: Could not find correct 'config.toml'")
+        exit()
     
-    def add_insert():
-        pass
 
-    def edit_update():
-        pass
+def matchTomlKey(tomlName, key):
+    doc = getTomlDoc(tomlName)
+    return doc.item(key)
+    
 
-    def del_delete():
-        pass
+# Sqlite3
     
-    con = sqlite3.connect("KanbanCore.db")
-    cur = con.cursor
 
-# class WithMd():
+# Markdown
 
 
-# class WithCsv():
+# csv
 
 
-# class WithMongo():
+# MongoDB

+ 25 - 4
config.toml

@@ -1,9 +1,30 @@
-# Choose between sqlite3/toml/md/csv/mongodb
-# However toml/md/csv/mongodb will not be supported  in v1.0
-defaultDB = "sqlite3"
+# Choose between: zh-s/zh-f/en
+# zh-s == 简体中文; zh-f == 繁体中文(暫未支持)
+lang = "en"
+
+# Choose between: sqlite3/toml/md/csv/mongodb
+# However toml/md/csv/mongodb are not supported in v1.0
+[Database]
+type = "sqlite3"
+path = "test.db"
 
 # >>>need some guidance here<<<
 EnableGlobalCommand = false
 
 # tree/expand
-listBoardStyle = "tree"
+listBoardStyle = "tree"
+
+# ----- help Text -----
+# 应该是用asicⅡ然后根据系统语言转换?
+[commands]
+en = """
+
+"""
+zh-s = """
+
+"""
+
+[could-not-find]
+en = "could not find"
+zh-s = "找不到"
+