2016-12-04 18:09:15 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2016-12-10 00:18:22 +01:00
|
|
|
from locale import gettext as _
|
2016-12-05 18:41:28 +01:00
|
|
|
import gi
|
2016-12-08 18:11:08 +01:00
|
|
|
import json
|
|
|
|
|
import locale
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import webbrowser
|
2016-12-04 18:09:15 +01:00
|
|
|
gi.require_version("Gtk", "3.0")
|
2016-12-04 19:11:31 +01:00
|
|
|
from gi.repository import Gtk
|
2016-12-04 18:09:15 +01:00
|
|
|
|
2016-12-05 22:18:23 +01:00
|
|
|
class ManjaroHello():
|
2016-12-04 18:09:15 +01:00
|
|
|
def __init__(self):
|
2016-12-05 21:49:29 +01:00
|
|
|
# App vars
|
|
|
|
|
self.app = "manjaro-hello"
|
2016-12-09 17:28:22 +01:00
|
|
|
self.default_locale = "en_US"
|
2016-12-10 00:18:22 +01:00
|
|
|
self.sys_locale = locale.getdefaultlocale()[0]
|
2016-12-10 01:00:05 +01:00
|
|
|
self.welcome_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"
|
|
|
|
|
}
|
2016-12-05 18:41:28 +01:00
|
|
|
self.social_urls = {
|
|
|
|
|
"google+": "https://plus.google.com/118244873957924966264",
|
|
|
|
|
"facebook": "https://www.facebook.com/ManjaroLinux",
|
|
|
|
|
"twitter": "https://twitter.com/ManjaroLinux",
|
|
|
|
|
"reddit": "https://www.reddit.com/r/ManjaroLinux"
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 17:28:22 +01:00
|
|
|
# Path vars
|
2016-12-10 17:34:29 +01:00
|
|
|
self.current_folder = os.getcwd() + "/"
|
|
|
|
|
if os.path.exists("/usr/share/" + self.app + "/data/"):
|
|
|
|
|
self.data_path = "/usr/share/" + self.app + "/data/"
|
|
|
|
|
self.locale_path = "/usr/share/locale/"
|
|
|
|
|
else:
|
|
|
|
|
self.data_path = self.current_folder + "data/"
|
|
|
|
|
self.locale_path = "locale/"
|
|
|
|
|
self.config_path = os.path.expanduser("~") + "/.config/"
|
|
|
|
|
self.preferences_path = self.config_path + self.app + ".json"
|
|
|
|
|
self.desktop_path = self.current_folder + self.app + ".desktop"
|
|
|
|
|
self.autostart_path = self.config_path + "autostart/" + self.app + ".desktop"
|
2016-12-04 18:09:15 +01:00
|
|
|
|
2016-12-09 17:28:22 +01:00
|
|
|
# Load preferences
|
|
|
|
|
self.preferences = self.get_preferences()
|
|
|
|
|
if not self.preferences:
|
|
|
|
|
self.preferences = {
|
|
|
|
|
"autostart": os.path.isfile(self.autostart_path),
|
|
|
|
|
"locale": None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Init translation
|
|
|
|
|
locales = os.listdir(self.locale_path)
|
|
|
|
|
locales.append(self.default_locale)
|
|
|
|
|
if self.preferences["locale"] not in locales:
|
|
|
|
|
if self.sys_locale in locales:
|
|
|
|
|
self.preferences["locale"] = self.sys_locale
|
|
|
|
|
else:
|
|
|
|
|
self.preferences["locale"] = self.default_locale
|
|
|
|
|
|
2016-12-10 16:45:38 +01:00
|
|
|
locale.setlocale(locale.LC_ALL, self.preferences["locale"] + ".utf8")
|
2016-12-10 00:18:22 +01:00
|
|
|
locale.bindtextdomain(self.app, self.locale_path)
|
|
|
|
|
locale.textdomain(self.app)
|
2016-12-09 17:28:22 +01:00
|
|
|
|
|
|
|
|
# Save new locale
|
|
|
|
|
self.save_preferences()
|
|
|
|
|
|
|
|
|
|
# Load system infos
|
|
|
|
|
self.infos = get_infos()
|
|
|
|
|
|
|
|
|
|
# Init window
|
2016-12-04 18:09:15 +01:00
|
|
|
self.builder = Gtk.Builder()
|
|
|
|
|
self.builder.set_translation_domain(self.app)
|
|
|
|
|
self.builder.add_from_file("manjaro-hello.glade")
|
|
|
|
|
self.builder.connect_signals(self)
|
|
|
|
|
self.window = self.builder.get_object("window")
|
|
|
|
|
|
2016-12-09 17:28:22 +01:00
|
|
|
# Change selected language
|
|
|
|
|
self.builder.get_object("languages").set_active_id(self.preferences["locale"]);
|
|
|
|
|
self.builder.get_object("languages").connect("changed", self.on_languages_changed)
|
|
|
|
|
|
2016-12-04 22:48:13 +01:00
|
|
|
# Set window subtitle
|
2016-12-06 18:54:02 +01:00
|
|
|
if self.infos["codename"] and self.infos["release"]:
|
|
|
|
|
self.builder.get_object("headerbar").props.subtitle = self.infos["codename"] + " " + self.infos["release"] + " "
|
|
|
|
|
self.builder.get_object("headerbar").props.subtitle += self.infos["arch"]
|
2016-12-04 18:09:15 +01:00
|
|
|
|
2016-12-10 17:34:29 +01:00
|
|
|
# Load images
|
|
|
|
|
self.builder.get_object("google+").set_from_file(self.data_path + "img/google+.png")
|
|
|
|
|
self.builder.get_object("facebook").set_from_file(self.data_path + "img/facebook.png")
|
|
|
|
|
self.builder.get_object("twitter").set_from_file(self.data_path + "img/twitter.png")
|
|
|
|
|
self.builder.get_object("reddit").set_from_file(self.data_path + "img/reddit.png")
|
|
|
|
|
|
2016-12-05 21:49:29 +01:00
|
|
|
# Set autostart switcher state
|
2016-12-04 18:09:15 +01:00
|
|
|
self.builder.get_object("autostart").set_active(self.preferences["autostart"])
|
|
|
|
|
|
2016-12-09 17:28:22 +01:00
|
|
|
# Init pages
|
|
|
|
|
for page in ("readme", "release", "involved"):
|
|
|
|
|
self.builder.get_object(page + "text").set_markup(self.read_page(page))
|
|
|
|
|
|
2016-12-08 17:39:52 +01:00
|
|
|
# Live systems
|
|
|
|
|
if self.infos["live"]:
|
|
|
|
|
can_install = False
|
|
|
|
|
if os.path.isfile("/usr/bin/calamares"):
|
|
|
|
|
self.builder.get_object("installgui").set_visible(True)
|
|
|
|
|
can_install = True
|
|
|
|
|
if os.path.isfile("/usr/bin/cli-installer"):
|
|
|
|
|
self.builder.get_object("installcli").set_visible(True)
|
|
|
|
|
can_install = True
|
|
|
|
|
if can_install:
|
|
|
|
|
self.builder.get_object("installlabel").set_visible(True)
|
|
|
|
|
|
|
|
|
|
self.window.show();
|
2016-12-04 18:09:15 +01:00
|
|
|
|
|
|
|
|
def change_autostart(self, state):
|
2016-12-04 20:40:34 +01:00
|
|
|
if state and not os.path.isfile(self.autostart_path):
|
2016-12-04 18:09:15 +01:00
|
|
|
try:
|
2016-12-05 21:49:29 +01:00
|
|
|
os.symlink(self.desktop_path, self.autostart_path)
|
2016-12-04 19:32:11 +01:00
|
|
|
except OSError as e:
|
2016-12-04 18:09:15 +01:00
|
|
|
print(e)
|
2016-12-04 20:40:34 +01:00
|
|
|
elif not state and os.path.isfile(self.autostart_path):
|
2016-12-04 18:09:15 +01:00
|
|
|
try:
|
2016-12-05 21:49:29 +01:00
|
|
|
os.unlink(self.autostart_path)
|
2016-12-04 19:32:11 +01:00
|
|
|
except OSError as e:
|
2016-12-04 18:09:15 +01:00
|
|
|
print(e)
|
2016-12-05 21:55:58 +01:00
|
|
|
self.preferences["autostart"] = state
|
2016-12-04 18:09:15 +01:00
|
|
|
self.save_preferences()
|
|
|
|
|
|
|
|
|
|
def save_preferences(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.preferences_path, "w") as f:
|
|
|
|
|
json.dump(self.preferences, f)
|
2016-12-04 19:32:11 +01:00
|
|
|
except OSError as e:
|
2016-12-04 18:09:15 +01:00
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
def get_preferences(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.preferences_path, "r") as f:
|
|
|
|
|
return json.load(f)
|
2016-12-04 19:32:11 +01:00
|
|
|
except OSError as e:
|
2016-12-04 18:09:15 +01:00
|
|
|
return None
|
|
|
|
|
|
2016-12-05 19:32:15 +01:00
|
|
|
def read_page(self, name):
|
2016-12-10 17:34:29 +01:00
|
|
|
filename = self.data_path + "pages/{}/{}".format(self.preferences["locale"], name)
|
2016-12-04 20:40:34 +01:00
|
|
|
if not os.path.isfile(filename):
|
2016-12-10 17:34:29 +01:00
|
|
|
filename = self.data_path + "pages/{}/{}".format(self.default_locale, name)
|
2016-12-04 18:09:15 +01:00
|
|
|
try:
|
|
|
|
|
with open(filename, "r") as f:
|
|
|
|
|
return f.read()
|
2016-12-04 19:32:11 +01:00
|
|
|
except OSError as e:
|
2016-12-04 18:09:15 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# Handlers
|
2016-12-09 17:28:22 +01:00
|
|
|
def on_languages_changed(self, combobox):
|
|
|
|
|
self.preferences["locale"] = combobox.get_active_id()
|
|
|
|
|
self.save_preferences()
|
|
|
|
|
os.execv(sys.executable, ['python'] + sys.argv)
|
|
|
|
|
|
2016-12-04 18:09:15 +01:00
|
|
|
def on_about_clicked(self, btn):
|
|
|
|
|
dialog = self.builder.get_object("aboutdialog")
|
|
|
|
|
dialog.set_transient_for(self.window)
|
|
|
|
|
dialog.run()
|
|
|
|
|
dialog.hide()
|
|
|
|
|
|
2016-12-10 01:00:05 +01:00
|
|
|
def on_action_btn_clicked(self, btn):
|
2016-12-04 19:43:38 +01:00
|
|
|
name = btn.get_name()
|
|
|
|
|
if name == "readmebtn":
|
|
|
|
|
self.builder.get_object("stack").set_visible_child(self.builder.get_object("documentation"))
|
|
|
|
|
self.builder.get_object("documentation").set_current_page(0)
|
|
|
|
|
elif name == "releasebtn":
|
|
|
|
|
self.builder.get_object("stack").set_visible_child(self.builder.get_object("documentation"))
|
|
|
|
|
self.builder.get_object("documentation").set_current_page(1)
|
|
|
|
|
elif name == "involvedbtn":
|
|
|
|
|
self.builder.get_object("stack").set_visible_child(self.builder.get_object("project"))
|
|
|
|
|
self.builder.get_object("project").set_current_page(0)
|
2016-12-08 17:39:52 +01:00
|
|
|
elif name == "installgui":
|
2016-12-08 18:11:08 +01:00
|
|
|
subprocess.call(["sudo", "-E", "calamares"])
|
2016-12-08 17:39:52 +01:00
|
|
|
elif name == "installcli":
|
2016-12-08 18:11:08 +01:00
|
|
|
subprocess.call(["sudo cli-installer"])
|
2016-12-04 18:09:15 +01:00
|
|
|
|
2016-12-10 01:00:05 +01:00
|
|
|
def on_link_btn_clicked(self, btn):
|
|
|
|
|
webbrowser.open_new_tab(self.welcome_urls[btn.get_name()[:-3]])
|
|
|
|
|
|
2016-12-05 18:41:28 +01:00
|
|
|
def on_social_pressed(self, eventbox, _):
|
2016-12-09 17:32:17 +01:00
|
|
|
webbrowser.open_new_tab(self.social_urls[eventbox.get_name()])
|
2016-12-05 18:41:28 +01:00
|
|
|
|
2016-12-04 18:09:15 +01:00
|
|
|
def on_autostart_switched(self, switch, _):
|
|
|
|
|
autostart = True if switch.get_active() else False
|
|
|
|
|
self.change_autostart(autostart)
|
|
|
|
|
|
|
|
|
|
def on_delete_window(self, *args):
|
|
|
|
|
Gtk.main_quit(*args)
|
|
|
|
|
|
2016-12-04 19:17:48 +01:00
|
|
|
def get_infos():
|
|
|
|
|
lsb = get_lsb_information()
|
|
|
|
|
infos = {}
|
2016-12-06 18:54:02 +01:00
|
|
|
infos["codename"] = lsb.get("CODENAME", None)
|
|
|
|
|
infos["release"] = lsb.get("RELEASE", None)
|
|
|
|
|
infos["arch"] = "64-bits" if sys.maxsize > 2**32 else "32-bits"
|
2016-12-08 17:39:52 +01:00
|
|
|
infos["live"] = os.path.exists("/bootmnt/manjaro") or os.path.exists("/run/miso/bootmnt/manjaro")
|
2016-12-04 19:17:48 +01:00
|
|
|
|
|
|
|
|
return infos
|
|
|
|
|
|
2016-12-04 19:10:33 +01:00
|
|
|
def get_lsb_information():
|
|
|
|
|
lsb = {}
|
|
|
|
|
try:
|
|
|
|
|
with open("/etc/lsb-release") as lsb_file:
|
|
|
|
|
for line in lsb_file:
|
|
|
|
|
if "=" in line:
|
|
|
|
|
var, arg = line.rstrip().split("=")
|
|
|
|
|
if var.startswith("DISTRIB_"):
|
|
|
|
|
var = var[8:]
|
|
|
|
|
if arg.startswith("\"") and arg.endswith("\""):
|
|
|
|
|
arg = arg[1:-1]
|
|
|
|
|
if arg:
|
|
|
|
|
lsb[var] = arg
|
2016-12-04 20:28:41 +01:00
|
|
|
except OSError as e:
|
|
|
|
|
print(e)
|
2016-12-04 19:10:33 +01:00
|
|
|
|
|
|
|
|
return lsb
|
|
|
|
|
|
2016-12-05 22:18:23 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
ManjaroHello()
|
|
|
|
|
Gtk.main()
|