mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
feat: support local-fs via dynamic config menu
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ __pycache__/
|
||||
cache/
|
||||
install/
|
||||
*.json
|
||||
install-dir/
|
||||
16
client.py
16
client.py
@@ -30,8 +30,9 @@ def close_input_window(input_window):
|
||||
'''Close the config window and save the settings'''
|
||||
|
||||
# retrieve values #
|
||||
entries = list(filter(lambda x: isinstance(x, customtkinter.CTkEntry), input_window.winfo_children()))
|
||||
entries = list(filter(lambda x: isinstance(x, (customtkinter.CTkEntry, customtkinter.CTkOptionMenu)), input_window.winfo_children()))
|
||||
labels = [ input_window.grid_slaves(row=e.grid_info()["row"], column=e.grid_info()["column"]-1)[0] for e in entries ]
|
||||
print(labels)
|
||||
ret_dict = dict()
|
||||
for e, l in zip(entries, labels):
|
||||
ret_dict.update({ l.cget("text") : e.get() })
|
||||
@@ -276,17 +277,30 @@ if __name__ == "__main__":
|
||||
user = config_loaded.get("User:")
|
||||
password = config_loaded.get("Password:")
|
||||
install_dir = config_loaded["Install dir:"]
|
||||
backend_type = config_loaded["Select option:"]
|
||||
|
||||
# get the secod part of the server string, then split once at first / to get path and prepend / again#
|
||||
if backend_type == "FTP/FTPS":
|
||||
remote_root_dir = "/" + config_loaded["Server/Path:"].split("://")[1].split("/", 1)[1]
|
||||
server = config_loaded["Server/Path:"][:-len(remote_root_dir)]
|
||||
elif backend_type == "Local Filesystem":
|
||||
remote_root_dir = config_loaded["Server/Path:"]
|
||||
server = None
|
||||
else:
|
||||
raise NotImplementedError("Unsupported Backend")
|
||||
|
||||
# debug output #
|
||||
print(user, password, install_dir, remote_root_dir, server, config_loaded["Server/Path:"])
|
||||
|
||||
# add db backend #
|
||||
if backend_type == "FTP/FTPS":
|
||||
db = data_backend.FTP(user, password, install_dir, server=server,
|
||||
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||
elif backend_type == "Local Filesystem":
|
||||
db = data_backend.LocalFS(user, password, install_dir, server=server,
|
||||
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||
else:
|
||||
raise NotImplementedError("Unsupported Backend")
|
||||
|
||||
# geometry is set at the very beginning #
|
||||
app.update()
|
||||
|
||||
@@ -20,6 +20,7 @@ class DataBackend:
|
||||
self.install_dir = install_dir
|
||||
self.progress_bar_wrapper = progress_bar_wrapper
|
||||
self.root = tkinter_root
|
||||
self.cache_dir = "./cache/"
|
||||
|
||||
def get(self, path, return_content=False):
|
||||
'''Return the contents of this path'''
|
||||
@@ -50,8 +51,8 @@ class LocalFS(DataBackend):
|
||||
|
||||
# load the file on remote #
|
||||
with open(fullpath, "rb") as f:
|
||||
print(cache_dir, path)
|
||||
target = os.path.join(cache_dir, os.path.basename(path))
|
||||
print("Cache-Dir-Base", cache_dir, "Cache-Dir-Target", target, "Path:", path)
|
||||
with open(target, "wb") as ft:
|
||||
if return_content:
|
||||
return f.read()
|
||||
@@ -82,9 +83,9 @@ class LocalFS(DataBackend):
|
||||
if not os.path.isfile(meta_file):
|
||||
continue
|
||||
else:
|
||||
meta_info_list.append(software.Software(meta_file, self))
|
||||
meta_info_list.append(software.Software(meta_file, self, self.progress_bar_wrapper))
|
||||
|
||||
return meta_info_list
|
||||
return list(filter(lambda x: not x.invalid, meta_info_list))
|
||||
|
||||
class FTP(DataBackend):
|
||||
|
||||
@@ -122,6 +123,9 @@ class FTP(DataBackend):
|
||||
else:
|
||||
ftp.login()
|
||||
|
||||
# cache dir is automatically set #
|
||||
self.cache_dir = None
|
||||
|
||||
return ftp
|
||||
|
||||
|
||||
@@ -227,5 +231,5 @@ class FTP(DataBackend):
|
||||
#print(meta_file_content)
|
||||
local_meta_file_list.append(f)
|
||||
|
||||
return [ software.Software(meta_file, self, self.progress_bar_wrapper)
|
||||
for meta_file in local_meta_file_list ]
|
||||
return list(filter(lambda x: not x.invalid, [ software.Software(meta_file, self, self.progress_bar_wrapper)
|
||||
for meta_file in local_meta_file_list ]))
|
||||
15
software.py
15
software.py
@@ -14,9 +14,17 @@ class Software:
|
||||
self.meta_file = meta_file
|
||||
self.directory = os.path.dirname(meta_file)
|
||||
self.backend = backend
|
||||
# print(self.directory)
|
||||
self.cache_dir = os.path.join("cache", self.directory)
|
||||
print("Software Directory:", self.directory)
|
||||
|
||||
self.cache_dir = backend.cache_dir or os.path.join("cache", self.directory)
|
||||
|
||||
# return None instead of the object if yaml failed #
|
||||
try:
|
||||
self.invalid = False
|
||||
self._load_from_yaml()
|
||||
except ValueError as e:
|
||||
self.invalid = True
|
||||
|
||||
self.progress_bar_wrapper = progress_bar_wrapper
|
||||
|
||||
def _load_from_yaml(self):
|
||||
@@ -24,6 +32,9 @@ class Software:
|
||||
content = self.backend.get(self.meta_file, self.cache_dir, return_content=True)
|
||||
|
||||
meta = yaml.safe_load(content)
|
||||
if not meta:
|
||||
raise ValueError("Empty Meta File")
|
||||
|
||||
self.title = meta.get("title")
|
||||
self.genre = meta.get("genre")
|
||||
self.description = meta.get("description")
|
||||
|
||||
Reference in New Issue
Block a user