123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- import Alt
- import tomlkit, sqlite3
- def GetTomlDoc(tomlName:str):
- 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:str, key:str, table:str=None) -> str:
- doc = GetTomlDoc(tomlName)
- if table == None:
- return str(doc.item(key))
-
- elif table != None:
- d = doc.unwrap()
- return str(d[table][key])
- def MatchTomlKeys(tomlName:str, keys:list, table:str=None) -> list:
- doc = GetTomlDoc(tomlName)
- if table == None:
-
- 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
-
- def MatchTomlTable(tomlName:str, tableName:str, returnType:str="list"):
- d = GetTomlDoc(tomlName).unwrap()
- if returnType == "list":
- return list(d.get(tableName).values())
-
- elif returnType == "dict":
- return d
-
- def Exec_one(dbPath:str, commands:list):
- con = sqlite3.connect(dbPath)
- cur = con.cursor()
- cur.execute(commands)
- con.commit()
- re = cur.fetchall()
- cur.close()
- con.close()
- return re
- def IsExist(exec_commands:list, returnBool:bool=True):
-
-
- tableName = str(exec_commands[1]).capitalize()
- ItemName = str(exec_commands[2])
- sqls = "SELECT name FROM {table} WHERE name='{name}'".format(table=tableName, name=ItemName)
- ie = Exec_one(dbPath, sqls)
- if ie != [] and returnBool == False:
- return ie
-
- elif ie != [] and returnBool == True:
- return True
- elif ie == []:
- return False
-
- else:
-
- print("err <Code>: unexpected error in existence check")
-
- class objBoard():
- pass
- class objClass():
- pass
- class objEvent():
- pass
- def BuildObj():
- pass
- def GenModel():
-
-
-
- pass
- class OC():
- def __init__(self, currentPath, previousPath, dbType, dbPath, tableName, columnName, newColumnName) -> None:
- self.cp = currentPath
- self.pp = previousPath
- self.dt = dbType
- self.dp = dbPath
- self.table = tableName
- self.name = columnName
- self.newName = newColumnName
- def select(self, aliveOnly=True):
- if aliveOnly == True:
- sqls = "SELECT name FROM {table} WHERE name='{name}' AND status='alive';".format(table=self.table, name=self.name)
- elif aliveOnly == False:
- sqls = "SELECT name FROM {table} WHERE name='{name}';".format(table=self.table, name=self.name)
- res = Exec_one(self.dp, sqls)
-
- return res
- def add(self, addType="board"):
- if addType == "board":
- sqls = "INSERT INTO Board VALUES(null, '{name}', 'alive');".format(name=self.name)
-
- elif addType == "class":
- sqls = "INSERT INTO Class VALUES(null, '{name}', '{usingBoard}', 'alive');".format(name=self.name, usingBoard=self.pc)
- elif addType == "event":
- sqls = "INSERT INTO Event VALUES(null, '{name}', );"
- res = Exec_one(self.dp, sqls)
- def delete(self):
- sqls = "UPDATE {table} SET status='deleted' WHERE name='{name}';".format(table=self.table, name=self.name)
- res = Exec_one(self.dp, sqls)
- def edit(self):
-
-
-
-
-
-
- pass
-
- def move(self, moveObj):
- if moveObj == "KB":
- print("err <Code>: syntax error")
-
- elif moveObj == "CL":
- pass
-
- elif moveObj == "EV":
- pass
-
- def back(self, backType, backPath=""):
- if backType == "home":
- sqls = "SELECT name FROM sqlite_master WHERE type='table' AND name is NOT 'sqlite_sequence';"
- elif backType == "previous":
- sqls = "SELECT name FROM {table} WHERE name='{}'"
- Exec_one(dbPath, sqls)
- def Handler():
- pass
- if __name__ == "__main__":
- dbPath = "dev.db"
|