浏览代码

谁来教教我怎么写装饰器啊啊啊啊啊

NandHyf 11 月之前
父节点
当前提交
91be9b8c8b
共有 3 个文件被更改,包括 33 次插入38 次删除
  1. 8 15
      kbc.py
  2. 5 0
      kbc_alt.py
  3. 20 23
      kbc_sqlite.py

+ 8 - 15
kbc.py

@@ -9,11 +9,9 @@ import datetime
 class kbc_controller():
     def get_app_config(returnDict:bool=True):
         tomls = kbc_toml.MatchTomlTable("dev.toml", "app_config", "dict")
-        global app_config
-        app_config = tomls["app_config"]
 
         if returnDict == True:
-            return app_config
+            return tomls
         
 
     def get_help():
@@ -24,12 +22,11 @@ class kbc_controller():
 
 
     # [todo 4]
-    def display_in_timezone():
+    def display_in_timezone(timezone:int=0):
         pass
     
 
     # [todo 2]
-    # 前端只检查输入数量正确, 内容正确统一代回后端检查
     def validCheck():
         pass
 
@@ -39,9 +36,8 @@ class kbc_controller():
 
 
     def transitCommand():
-        # do while or for (1)
-        while(1):
-            app_commands = input(currentPath + "/: ", ).split(" ")
+        while(True):
+            pass
             # Input exception check
             
             # [todo 1]
@@ -50,13 +46,10 @@ class kbc_controller():
 
     # [todo 4]
     def start():
-        pass
-
-        # 2. Valid DB
-        # startState = Stateful.Translator(['/', app_config["dbPath"], app_config["dbType"]])
-        # print(startState)
-        # kbc_controller.TransitCommand()
+        global app_config
+        app_config = kbc_controller.get_app_config()["app_config"]
 
 
 if __name__ == "__main__":
-    kbc_controller.start()   
+    kbc_controller.start()
+    kbc_alt.pause()

+ 5 - 0
kbc_alt.py

@@ -3,6 +3,11 @@
 # err 1: correct DB not found
 # -----
 
+
+def pause():
+    input("pausing, press any key to continue: ")
+
+
 def Err(errCode, lang='en'):
     errText = ""
     input("err ", errCode, ": ",  errText)

+ 20 - 23
kbc_sqlite.py

@@ -70,10 +70,6 @@ class DB():
         pass
 
 
-def direct():
-    pass
-
-
 # ----- Operating Cursor -----
 oc = {
 "dt":str, # DBType
@@ -91,49 +87,50 @@ oc = {
 }
 # some thoughts:
 # class oc():
-#   def get_oc(), def move_oc()
+#   def read_oc(), def move_oc()
 
 
 # ----- Execute Methods -----
 def execute(dbPath):
     def dec(origin_func):
         pass
+        def new_exec():
+            con = sqlite3.connect(dbPath)
+            cur = con.cursor()
 
-    con = sqlite3.connect(dbPath)
-    cur = con.cursor()
+            cur.execute(commands)
+            con.commit()
 
-    cur.execute(commands)
-    con.commit()
+            # if fetchall == input, return 0?
+            if fetchall == True:
+                re = cur.fetchall()
+                return re
+            
+            cur.close()
+            con.close()    
 
-    # if fetchall == input, return 0?
-    if fetchall == True:
-        re = cur.fetchall()
-        return re
-    
-    cur.close()
-    con.close()
-    def dec():
-        pass
+
+@execute(oc["dp"])
+def exec_one(sqls:str="", fetchall:bool=False):
+    return 
 
 
 @execute(oc["dp"])
-def exec_one(dbPath:str, commands:list, fetchall:bool=False):
+def exec_many(sqls:dict={}, fetchall:bool=False):
     pass
 
 
 @execute(oc["dp"])
-def exec_many():
+def direct():
     pass
 
 
 def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="", returnBool:bool=True):
-    # [todo 4] 这里面.capitalize()后面需要根据config.toml里面的内容判断
-    # 可能也不用, 因为KBCLEV的表名和本身并无关系
     if capitalize == True:
         tableName = tableName.capitalize()
 
     sqls = "SELECT name FROM {table} WHERE name='{name}';".format(table=tableName, name=itemName)
-    ie = exec_one(dbPath, sqls)
+    ie = exec_one(sqls)
 
     if ie != [] and returnBool == False:
         return ie