Browse Source

已经在rebuild了

NandHyf 1 year ago
parent
commit
5e14d4f6c7
4 changed files with 154 additions and 43 deletions
  1. 5 2
      Controller.py
  2. 36 32
      Stateful.py
  3. 105 0
      archived_Stateful.py
  4. 8 9
      dev_config.toml

+ 5 - 2
Controller.py

@@ -2,7 +2,6 @@ import Alt, Stateful
 import datetime
     
 
-# 如果需要再封装class Board/KB_Class/Event的话就在这里
 class Client():
 
     def get_config():
@@ -85,7 +84,11 @@ class View:
     def Refresh():
         pass
 
-    
+
+# For ChatGLM3-6B
+class LLMCall():
+    pass
+
 
 if __name__ == "__main__":
     Client.start()

+ 36 - 32
Stateful.py

@@ -1,9 +1,9 @@
-import Alt, WithSqlite
-import tomlkit
+import Alt
+import tomlkit, sqlite3
 
 # uid related
 
-# Toml Methods
+# ----- Toml Methods -----
 def GetTomlDoc(tomlName):
     try:
         with open(tomlName, "rb") as t:
@@ -59,47 +59,51 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
                 pass
 
         return rl
+    
 
+# ----- Sqlite -----
+def Exec_one(dbPath, commands):
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
 
-# ----- Transit Command Handler -----
-def Handler(app_commands):
-    dbType = app_commands[-1]
-    dbPath = app_commands[-2]
-    # [todo 3] 检查dbPath是否对应dbType, 否的话报错并exit()
-
-    exec_commands = app_commands[0:-2]
+    cur.execute(commands)
+    con.commit()
+    re = cur.fetchall()
+    con.close()
 
-    if dbType == "sqlite3":
-        WithSqlite.Regular(dbPath, exec_commands)
+    return re
 
 
-    elif dbType == "csv":
-        pass
+def IsExist(exec_commands, returnBool=True):
+    tableName = str(exec_commands[1]).capitalize()
 
-    elif dbType == "mongodb":
-        pass
+    ItemName = str(exec_commands[2])
 
-    elif dbType == "toml":
-        pass
+    sqls = "SELECT name FROM {table} WHERE name='{name}'".format(table=tableName, name=ItemName)
+    ie = Exec_one(dbPath, sqls)
 
-    elif dbType == "md":
-        pass
+    if ie != [] and returnBool == False:
+        return ie
+    
+    elif ie != [] and returnBool == True:
+        return True
 
+    elif ie == []:
+        return False
+    
     else:
-        input("error 1: could not found correct Data Base")
-        exit()
-
+        # Alt.Err(errCode)
+        print("err <Code>: unexpected error in existence check")
 
-# ----- Docker related -----
 
+class command():
+    pass
 
+class objBoard():
+    pass
 
-if __name__ == "__main__":
-    
-    a_c = ['/', 'test.db', 'sqlite3']
-    a_c1 = ['add', 'board', 'testBoardName', 'test.db', 'sqlite3']
-    a_c2 = ['edit', 'board', 't_boardName', 'to', 't_newBoardName', 'test.db', 'sqlite3']
-    e_c = ['add', 'board']
+class objClass():
+    pass
 
-    # Operate_sqlite3("test.db", a_c1)
-    Handler(a_c2)
+class objEvent():
+    pass

+ 105 - 0
archived_Stateful.py

@@ -0,0 +1,105 @@
+import Alt, WithSqlite
+import tomlkit
+
+# uid related
+
+# Toml Methods
+def GetTomlDoc(tomlName):
+    try:
+        with open(tomlName, "rb") as t:
+            doc = tomlkit.load(t)
+
+            if doc == {}:
+                input("error 0: could not found correct config file") 
+                exit()
+
+            return doc
+        
+    except:
+        input("error 0: could not found correct config file") 
+        exit()
+    
+
+def MatchTomlKey(tomlName, key, table=None) -> str:
+    doc = GetTomlDoc(tomlName)
+
+    if table == None:
+        return str(doc.item(key))
+    
+    elif table != None:
+        d = doc.unwrap()
+        return str(d[table][key])
+
+
+# no differernt between ↑ MatchTomlKey() ↑ except receives and returns in list
+def MatchTomlKeys(tomlName, keys, table=None) -> list:
+    doc = GetTomlDoc(tomlName)
+
+    if table == None:
+        # rl == 'r'eturn 'l'ist
+        rl = []
+
+        for key in keys:
+            try:
+                rl.append(doc.item(key))
+            except:
+                pass
+
+        return rl
+    
+
+    elif table != None:
+        rl = []
+        d = doc.unwrap()
+
+        for key in keys:
+            try:
+                rl.append(d[table][key])
+            except:
+                pass
+
+        return rl
+
+
+# ----- Transit Command Handler -----
+def Handler(app_commands):
+    dbType = app_commands[-1]
+    dbPath = app_commands[-2]
+    # [todo 3] 检查dbPath是否对应dbType, 否的话报错并exit()
+
+    exec_commands = app_commands[0:-2]
+
+    if dbType == "sqlite3":
+        WithSqlite.Regular(dbPath, exec_commands)
+
+
+    elif dbType == "csv":
+        pass
+
+    elif dbType == "mongodb":
+        pass
+
+    elif dbType == "toml":
+        pass
+
+    elif dbType == "md":
+        pass
+
+    else:
+        input("error 1: could not found correct Data Base")
+        exit()
+
+
+# ----- Docker related -----
+
+
+
+if __name__ == "__main__":
+    
+    a_c = ['/', 'test.db', 'sqlite3']
+    a_c1 = ['add', 'board', 'testBoardName', 'test.db', 'sqlite3']
+    a_c2 = ['edit', 'board', 't_boardName', 'to', 't_newBoardName', 'test.db', 'sqlite3']
+    e_c = ['add', 'board']
+
+    # Operate_sqlite3("test.db", a_c1)
+    Handler(a_c2)

+ 8 - 9
dev_config.toml

@@ -1,20 +1,17 @@
-# ----- init Configuration -----
+# ----- DB Configuration -----
 # Just a better reference for dev.db, no functional use(yet)
 [Board]
-# VALUES(?, ?, ?, ...)
 c1_p-k = "id INTEGER PRIMARY KEY ASC"
 c2 = "name"
-c1 = "status" # alive/deleted
+c1 = "status"
 
 [Class]
-# VALUES(?, ?, ?, ...)
 c1_p-k = "id INTEGER PRIMARY KEY ASC"
 c2 = "name"
 c3 = "usingBoard"
-c4 = "status" # alive/deleted
+c4 = "status"
 
 [Event]
-# VALUES(?, ?, ?, ...)
 c1_p-k = "id INTEGER PRIMARY KEY ASC"
 c2 = "name"
 c3 = "dscrp"
@@ -22,16 +19,15 @@ c4 = "creator"
 c5 = "createdTime"
 c6 = "classCreated"
 c7 = "classCurrent"
-c8 = "status" # alive/deleted
+c8 = "status"
 
 [Stucked]
-# VALUES(?, ?, ?, ...)
 c1_pk = "id INTEGER PRIMARY KEY ASC"
 c2 = "boardId"
 c3 = "eventId"
 c4 = "stuckedTime"
 c5 = "solvedTime"
-c6 = "status" # alive/deleted
+c6 = "status"
 
 
 # ----- App Configuration -----
@@ -43,3 +39,6 @@ listStyle = "tree"
 displayTimeZone = "utc+8"
 
 
+# ----- note -----
+# set integer prime key: <columnName> INTEGER PRIMARY KEY ASC
+# status: alive/deleted