Added config versioning and file root

Added a version number to the config with a basic warning when the loaded version is different than expected.
Saving & loading file root to config
dev
peery 3 years ago
parent 6026e736ba
commit 7a276a5492

@ -17,6 +17,11 @@ class ArtNetManager:
def __init__(self, config_location: str = "."):
self.config = ConfigReader(config_location, "somePassword")
if self.config.data["version"] != self.config.CONFIG_VERSION:
print("Loaded config version is unequal to expected version! {0} (current) != {1} (expected)"
.format(self.config.data["version"], self.config.CONFIG_VERSION))
self.db_connection = None
self.__app = QApplication(sys.argv)
@ -45,16 +50,10 @@ class ArtNetManager:
database=db_data["database"])
self.window = Window(self)
# TODO prompt for overwriting config when password invalid
# TODO sane default location
# TODO tag editor, don't kill dialog if fields are missing
# TODO display Tag Category when searching for tags
# TODO remove string limit restrictions on implications & similar
self.__file_root: str = None
self.window.on_artnet_root_change_clicked()
self.__file_reader = FileReader(self.__file_root)
if len(self.config.data["file_root"]) == 0 or not os.path.isdir(self.config.data["file_root"]): # no file_root given by config or invalid
print("Querying for new file root due to lack of valid one ...")
self.window.on_artnet_root_change_clicked()
self.__file_reader = FileReader(self.config.data["file_root"])
self.curr_image_index: int = None
@ -336,7 +335,7 @@ class ArtNetManager:
print("Displaying", self.all_images[self.curr_image_index])
self.window.display_image(image_title, image_author,
os.path.join(self.__file_root, self.all_images[self.curr_image_index]),
os.path.join(self.config.data["file_root"], self.all_images[self.curr_image_index]),
self.all_images[self.curr_image_index],
art_ID, image_link, file_name=s[-1])
self.window.set_tag_list([self.db_connection.get_tag_by_ID(x)[0][1].strip() for x in self.db_connection.get_art_tags_by_ID(art_ID)])
@ -349,7 +348,7 @@ class ArtNetManager:
return DBAdapter(user=user, password=password, host=host, port=port, database=database)
def get_root(self) -> str:
return self.__file_root
return self.config.data["file_root"]
def change_root(self, path: str):
"""
@ -362,7 +361,8 @@ class ArtNetManager:
if len(path) == 0:
exit(0)
print("Changing root to", path)
self.__file_root = path
self.config.data["file_root"] = path
self.config.update_config()
def get_db_connection_details(self) -> dict:
return self.config.data["db"]

@ -19,6 +19,8 @@ class ConfigReader:
kdf = None
nonce = None
CONFIG_VERSION = 3
def __init__(self, root_folder: str, password: str):
if root_folder is None:
raise Exception("No root folder was defined!")
@ -68,6 +70,7 @@ class ConfigReader:
new_data = data
new_data["db"]["password"] = self.encrypt_text(data["db"]["password"])
new_data["db"]["user"] = self.encrypt_text(data["db"]["user"])
new_data["file_root"] = self.encrypt_text(data["file_root"])
return new_data
@ -79,6 +82,7 @@ class ConfigReader:
new_data = data
new_data["db"]["password"] = self.decrypt_text(data["db"]["password"])
new_data["db"]["user"] = self.decrypt_text(data["db"]["user"])
new_data["file_root"] = self.decrypt_text(data["file_root"])
return new_data
@ -88,6 +92,7 @@ class ConfigReader:
:return:
"""
self.data = {
"version": ConfigReader.CONFIG_VERSION,
"db": {
"host": "localhost",
"port": 5432,
@ -95,7 +100,7 @@ class ConfigReader:
"user": "your_user",
"password": "enter_password_via_gui"
},
"file_root": "",
}
self.update_config()

@ -163,7 +163,7 @@ class Window(QtWidgets.QMainWindow):
md5_hash=image_data["md5_hash"])
self.set_temporary_status_message("Saved {0} ({1}) to ArtNet DB!"
.format(self.curr_image_title, self.curr_art_id), 5000)
.format(image_data["title"], image_data["ID"]), 5000)
self.update_window_title()
self.data_changed = False
return True

Loading…
Cancel
Save