From 45e1d47c1c6a5db47d40de10d600a47ab78201fd Mon Sep 17 00:00:00 2001 From: Hugo Posnic Date: Sun, 18 Dec 2016 00:05:56 +0100 Subject: [PATCH] Change way to handle urls --- data/urls.json | 12 ++++++++++++ src/manjaro-hello.py | 32 +++++++++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 data/urls.json diff --git a/data/urls.json b/data/urls.json new file mode 100644 index 0000000..e64d919 --- /dev/null +++ b/data/urls.json @@ -0,0 +1,12 @@ +{ + "build": "https://github.com/manjaro", + "chat": "https://kiwiirc.com/client/irc.freenode.net/?nick=manjaro-web|?#manjaro", + "donate": "https://manjaro.org/donate", + "facebook": "https://www.facebook.com/ManjaroLinux", + "forums": "https://forum.manjaro.org", + "google+": "https://plus.google.com/118244873957924966264", + "mailling": "https://lists.manjaro.org/cgi-bin/mailman/listinfo", + "reddit": "https://www.reddit.com/r/ManjaroLinux", + "twitter": "https://twitter.com/ManjaroLinux", + "wiki": "https://wiki.manjaro.org" +} diff --git a/src/manjaro-hello.py b/src/manjaro-hello.py index bf68cf6..54e0fe8 100644 --- a/src/manjaro-hello.py +++ b/src/manjaro-hello.py @@ -15,18 +15,6 @@ class ManjaroHello(): def __init__(self): # App vars self.app = "manjaro-hello" - self.urls = { - "wiki": "https://wiki.manjaro.org", - "forums": "https://forum.manjaro.org", - "chat": "https://kiwiirc.com/client/irc.freenode.net/?nick=manjaro-web|?#manjaro", - "mailling": "https://lists.manjaro.org/cgi-bin/mailman/listinfo", - "build": "https://github.com/manjaro", - "donate": "https://manjaro.org/donate", - "google+": "https://plus.google.com/118244873957924966264", - "facebook": "https://www.facebook.com/ManjaroLinux", - "twitter": "https://twitter.com/ManjaroLinux", - "reddit": "https://www.reddit.com/r/ManjaroLinux" - } # Path vars self.current_folder = os.getcwd() + "/" @@ -43,6 +31,7 @@ class ManjaroHello(): self.config_path = os.path.expanduser("~") + "/.config/" self.preferences_path = self.config_path + self.app + ".json" + self.urls_path = self.data_path + "urls.json" self.autostart_path = self.config_path + "autostart/" + self.app + ".desktop" self.logo_path = "/usr/share/icons/manjaro.png" @@ -52,6 +41,9 @@ class ManjaroHello(): # Load system infos self.infos = get_infos() + # Load data files + self.urls = read_json(self.urls_path) + # Init window self.builder = Gtk.Builder() self.builder.add_from_file(self.ui_path + "manjaro-hello.glade") @@ -183,14 +175,13 @@ class ManjaroHello(): def get_preferences(self): """Read preferences from config file.""" - try: - with open(self.preferences_path, "r") as f: - return json.load(f) - except OSError as e: - return { + preferences = read_json(self.preferences_path) + if not preferences: + preferences = { "autostart": os.path.isfile(self.autostart_path), "locale": None } + return preferences def read_page(self, name): """Read page according to language. @@ -277,6 +268,13 @@ def get_lsb_infos(): print(e) return lsb +def read_json(path): + try: + with open(path, "r") as f: + return json.load(f) + except OSError as e: + return None + if __name__ == "__main__": ManjaroHello() Gtk.main()