From 8f6121ea90773c1e10cb5d1e2afe1d2d0cfa73b6 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 9 Apr 2021 02:38:34 +0200 Subject: [PATCH] Moved a few files to _datadir : ) --- TODO.md | 14 ++++---- oyoyo/client.py | 2 +- pesterchum.py | 93 ++++++++++++++++++++----------------------------- profile.py | 8 ++--- server.json | 5 --- serverlist.json | 7 ---- 6 files changed, 49 insertions(+), 80 deletions(-) delete mode 100644 server.json delete mode 100644 serverlist.json diff --git a/TODO.md b/TODO.md index 58f3b94..6b62a7d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,13 +1,11 @@ # TODO LIST : ) + ## ADD - - A proper prompt for choosing a server. - Memoserv support. ## FIX -- Audio mixer slider in options doesn't always work. -- Any remaining unicode-related crashes. -- Exclude unnecessary imports for builds. -- Icon is crusty...? -- "CHUMHANDLE" is cut off on pchum2.5 theme. -- Mask & target not being passed to ``_max_msg_len``. -- No error message when Pesterchum fails to join a channel. (For example, when the channel name length is over CHANNELLEN) + - Audio mixer slider in options doesn't always work. + - Any remaining unicode-related crashes. + - Exclude unnecessary imports for builds. + - Mask & target not being passed to ``_max_msg_len``. + - No error message when Pesterchum fails to join a channel. (For example, when the channel name length is over CHANNELLEN) diff --git a/oyoyo/client.py b/oyoyo/client.py index 33832eb..0adfbd4 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -87,7 +87,7 @@ class IRCClient: import json try: - with open("server.json", "r") as server_file: + with open(_datadir + "server.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) diff --git a/pesterchum.py b/pesterchum.py index 011f910..95fcd07 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -2968,7 +2968,7 @@ class PesterWindow(MovingWindow): self.irc = irc def updateServerJson(self): - print(self.customServerPrompt_qline.text() + " chosen") + logging.info(self.customServerPrompt_qline.text() + " chosen") server_and_port = self.customServerPrompt_qline.text().split(':') @@ -2978,7 +2978,7 @@ class PesterWindow(MovingWindow): "port": server_and_port[1], "TLS": self.TLS_checkbox.isChecked() } - print("server: "+str(server)) + logging.info("server: "+str(server)) except: msgbox = QtWidgets.QMessageBox() msgbox.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}") @@ -2989,15 +2989,13 @@ class PesterWindow(MovingWindow): self.changeServer() return 1 - with open("serverlist.json", "r") as server_file: + with open(_datadir + "serverlist.json", "r") as server_file: read_file = server_file.read() server_file.close() server_list_obj = json.loads(read_file) - print(server_list_obj) server_list_obj.append(server) - print(server_list_obj) try: - with open("serverlist.json", "w") as server_file: + with open(_datadir + "serverlist.json", "w") as server_file: server_file.write(json.dumps(server_list_obj, indent = 4)) server_file.close() except: @@ -3012,25 +3010,36 @@ class PesterWindow(MovingWindow): "port": "6697", "TLS": True }] - msgbox = QtWidgets.QMessageBox() - msgbox.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}") - msgbox.setWindowIcon(PesterIcon(self.theme["main/icon"])) - msgbox.setInformativeText("Failed to load from serverlist.json, do you want to revert to defaults?") - msgbox.addButton(QtWidgets.QPushButton("Yes"), QtWidgets.QMessageBox.YesRole) - msgbox.addButton(QtWidgets.QPushButton("No"), QtWidgets.QMessageBox.NoRole) - ret = msgbox.exec_() - reply = msgbox.buttonRole(msgbox.clickedButton()) + if os.path.isfile(_datadir + "serverlist.json"): + logging.error("Failed to load server list from serverlist.json.") + msgbox = QtWidgets.QMessageBox() + msgbox.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}") + msgbox.setWindowIcon(PesterIcon(self.theme["main/icon"])) + msgbox.setInformativeText("Failed to load server list, do you wish to revert to defaults?\n" \ + + "If you choose no, Pesterchum will most likely crash unless you manually fix serverlist.json\n" \ + + "Please tell me if this error occurs :'3") + msgbox.addButton(QtWidgets.QPushButton("Yes"), QtWidgets.QMessageBox.YesRole) + msgbox.addButton(QtWidgets.QPushButton("No"), QtWidgets.QMessageBox.NoRole) + ret = msgbox.exec_() + reply = msgbox.buttonRole(msgbox.clickedButton()) - if (reply==QtWidgets.QMessageBox.YesRole): - with open("serverlist.json", "w") as server_file: - server_file.write(json.dumps(default_server_list, indent = 4) ) - server_file.close() + if (reply==QtWidgets.QMessageBox.YesRole): + with open(_datadir + "serverlist.json", "w") as server_file: + server_file.write(json.dumps(default_server_list, indent = 4) ) + server_file.close() + + else: + logging.warning("Failed to load server list because serverlist.json doesn't exist, " \ + + "this isn't an issue if this is the first time Pesterchum has been started.") + with open(_datadir + "serverlist.json", "w") as server_file: + server_file.write(json.dumps(default_server_list, indent = 4) ) + server_file.close() self.changeServer() def removeServer(self): server_list_items = [] try: - with open("serverlist.json", "r") as server_file: + with open(_datadir + "serverlist.json", "r") as server_file: read_file = server_file.read() server_file.close() server_list_obj = json.loads(read_file) @@ -3038,20 +3047,18 @@ class PesterWindow(MovingWindow): server_list_items.append(server_list_obj[i]["server"]) except: if self.changeServerAskedToReset == False: - print("Failed to load.") self.changeServerAskedToReset = True self.resetServerlist() return 1 for i in range(len(server_list_obj)): - print(server_list_obj[i]) if server_list_obj[i]["server"] == self.removeServerBox.currentText(): selected_entry = i server_list_obj.pop(selected_entry) try: - with open("serverlist.json", "w") as server_file: + with open(_datadir + "serverlist.json", "w") as server_file: server_file.write(json.dumps(server_list_obj, indent = 4)) server_file.close() except: @@ -3110,11 +3117,12 @@ class PesterWindow(MovingWindow): # Show self.customServerDialog.show() + elif self.serverBox.currentText() == "Remove a server [Prompt]": # Read servers. server_list_items = [] try: - with open("serverlist.json", "r") as server_file: + with open(_datadir + "serverlist.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) @@ -3122,12 +3130,11 @@ class PesterWindow(MovingWindow): server_list_items.append(server_obj[i]["server"]) except: if self.changeServerAskedToReset == False: - print("Failed to load.") self.changeServerAskedToReset = True self.resetServerlist() return 1 - print("server_list_items: " + str(server_list_items)) + logging.info("server_list_items: " + str(server_list_items)) # Widget 1 self.chooseRemoveServerWidged = QtWidgets.QDialog() @@ -3168,9 +3175,9 @@ class PesterWindow(MovingWindow): # Show self.chooseRemoveServerWidged.show() else: - print(self.serverBox.currentText() + " chosen") + logging.info(self.serverBox.currentText() + " chosen") - with open("serverlist.json", "r") as server_file: + with open(_datadir + "serverlist.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) @@ -3182,7 +3189,7 @@ class PesterWindow(MovingWindow): selected_entry = i try: - with open("server.json", "w") as server_file: + with open(_datadir + "server.json", "w") as server_file: json_server_file = { "server": server_obj[selected_entry]["server"], "port": server_obj[selected_entry]["port"], @@ -3191,7 +3198,7 @@ class PesterWindow(MovingWindow): server_file.write(json.dumps(json_server_file, indent = 4) ) server_file.close() except: - print("failed") + logging.error("Failed to set server :(") # Continue running Pesterchum as usual pesterchum.irc.start() @@ -3203,7 +3210,7 @@ class PesterWindow(MovingWindow): # Read servers. server_list_items = [] try: - with open("serverlist.json", "r") as server_file: + with open(_datadir + "serverlist.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) @@ -3211,12 +3218,11 @@ class PesterWindow(MovingWindow): server_list_items.append(server_obj[i]["server"]) except: if self.changeServerAskedToReset == False: - print("Failed to load.") self.changeServerAskedToReset = True self.resetServerlist() return 1 - print("server_list_items: " + str(server_list_items)) + logging.info("server_list_items: " + str(server_list_items)) # Widget 1 self.chooseServerWidged = QtWidgets.QDialog() @@ -3340,29 +3346,6 @@ class MainProgram(QtCore.QObject): self.app.setQuitOnLastWindowClosed(False) options = self.oppts(sys.argv[1:]) - - - - # Tries to load the server to connect to from server.json. - # If it fails, create json file with default of irc.pesterchum.xyz & connect to irc.pesterchum.xyz -## try: -## with open("server.json", "r") as server_file: -## read_file = server_file.read() -## server_file.close() -## server_obj = json.loads(read_file) -## self.server = str(server_obj['server']) -## except: -## try: -## with open("server.json", "w") as server_file: -## json_server_file = { -## "server": "irc.pesterchum.xyz", -## } -## server_file.write(json.dumps(json_server_file, indent = 4) ) -## server_file.close() -## except: -## pass -## self.server = "irc.pesterchum.xyz" -## print(("Server is: " + self.server)) def doSoundInit(): # TODO: Make this more uniform, adapt it into a general function. diff --git a/profile.py b/profile.py index fd2f41e..db6e29b 100644 --- a/profile.py +++ b/profile.py @@ -294,7 +294,7 @@ class userConfig(object): if hasattr(self.parent, 'serverOverride'): return self.parent.serverOverride try: - with open("server.json", "r") as server_file: + with open(_datadir + "server.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) @@ -303,7 +303,7 @@ class userConfig(object): return server except: try: - with open("server.json", "w") as server_file: + with open(_datadir + "server.json", "w") as server_file: json_server_file = { "server": "irc.pesterchum.xyz", "port": "6697", @@ -319,7 +319,7 @@ class userConfig(object): if hasattr(self.parent, 'portOverride'): return self.parent.portOverride try: - with open("server.json", "r") as server_file: + with open(_datadir + "server.json", "r") as server_file: read_file = server_file.read() server_file.close() server_obj = json.loads(read_file) @@ -332,7 +332,7 @@ class userConfig(object): ## if hasattr(self.parent, 'tlsOverride'): ## return self.parent.tlsOverride ## try: -## with open("server.json", "r") as server_file: +## with open(_datadir + "server.json", "r") as server_file: ## read_file = server_file.read() ## server_file.close() ## server_obj = json.loads(read_file) diff --git a/server.json b/server.json deleted file mode 100644 index 8eada5d..0000000 --- a/server.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "server": "irc.pesterchum.xyz", - "port": "6697", - "TLS": true -} \ No newline at end of file diff --git a/serverlist.json b/serverlist.json deleted file mode 100644 index 1639c68..0000000 --- a/serverlist.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "server": "irc.pesterchum.xyz", - "port": "6697", - "TLS": true - } -] \ No newline at end of file