# -*- coding: utf-8 -*- import signal import os import time import urllib import commands import subprocess import shlex import gettext import string import gtk from user import home from simplejson import dumps as to_json from simplejson import loads as from_json from webgui import start_gtk_thread from webgui import launch_browser from webgui import synchronous_gtk_message from webgui import asynchronous_gtk_message from webgui import kill_gtk_thread from helpers import * # i18n gettext.install("mageiawelcome", "/usr/share/mageiawelcome/locale") class Global(object): quit = False @classmethod def set_quit(cls, *args, **kwargs): cls.quit = True def main(): start_gtk_thread() # Changing working directory abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) #collect sys info release = open("/etc/release", "r").read() kernel = commands.getoutput('uname -r') if os.uname()[4] == 'x86_64': arch = '64-bit' else: arch = '32-bit' home = os.getenv("HOME") username = os.getenv("USER") #collect packages nad its status listapp = get_listapp() #check if non-free and tainted enabled restricted_repos = "disabled" l={} l['name'] = _("Welcome to Mageia!") l['slogan'] = _("Use... Create... and Share the Magic") l['show'] = _("Show this window at startup") l['close'] = _("Close") l['release'] = release l['kernel_l'] = _("kernel:") l['kernel'] = kernel l['arch_l'] = _("arch:") l['arch'] = arch l['welcome'] = _("Welcome") l['user'] = username l['welcome_msg'] = _("

Thank you for choosing Mageia!

We have put a lot of effort to provide you with the best possible system, however please note that as nothing in this world is perfect neither is this distribution, therefore we will be very thankful for every contribution you can make to it.

To find out how you can help click here.

Don't forget to tell your friends about Mageia.

") l['newbie_howto'] = _("Newbie HowTo") l['didyouknow'] = _("First steps") l['rpm_install'] = _("Apps") l['applist'] = listapp l['bodyclass'] = restricted_repos if os.path.exists(home + "/.mageiawelcome/norun.flag"): l['checked'] = ("") else: l['checked'] = ("CHECKED") l['home_l'] = _("Home directory") l['home'] = home l['about'] = _("About") # Translations file = os.path.abspath('index.html') template = open(file).read() html = string.Template(template).safe_substitute(l) browser, web_recv, web_send = \ synchronous_gtk_message(launch_browser)(html, quit_function=Global.set_quit) # Finally, here is our personalized main loop while not Global.quit: again = False msg = web_recv() if msg: msg = from_json(msg) again = True if msg == "close": my_quit_wrapper() elif msg == "checkbox checked": if os.path.exists(home + "/.mageiawelcome/norun.flag"): os.system("rm -rf " + home + "/.mageiawelcome/norun.flag") elif msg == "checkbox unchecked": os.system("mkdir -p " + home + "/.mageiawelcome") os.system("touch " + home + "/.mageiawelcome/norun.flag") elif msg.startswith("http"): os.system("xdg-open " + msg) elif msg == "irc": if os.path.exists("/usr/bin/xchat-gnome"): os.system("/usr/bin/xchat-gnome &") elif os.path.exists("/usr/bin/xchat"): os.system("/usr/bin/xchat &") elif os.path.exists("/usr/bin/konversation"): os.system("/usr/bin/konversation &") elif os.path.exists("/usr/bin/quassel"): os.system("/usr/bin/quassel &") elif msg.startswith("run"): args = shlex.split(msg) args.pop(0) print args if args[0] == "xvt": os.chdir(home) subprocess.Popen(args) elif msg.startswith("gurpmi"): print msg args = shlex.split(msg) cat = args.pop(1) print args proc = subprocess.Popen(args, stdout=subprocess.PIPE) proc.wait() print proc.returncode if (proc.returncode == 0): listapp = get_listapp() web_send('$("ul#lista_applikacji").html("'+listapp+'");$("li#'+cat+'").trigger("click");') else: pass elif msg.startswith("install_selected"): print msg msg2 = msg.replace('install_selected','gurpmi') args = shlex.split(msg2) cat = args.pop(1) print args proc = subprocess.Popen(args, stdout=subprocess.PIPE) proc.wait() print proc.returncode if (proc.returncode == 0): listapp = get_listapp() web_send('$("ul#lista_applikacji").html("'+listapp+'");$("li#'+cat+'").trigger("click");') else: pass if again: pass else: time.sleep(0.1) def my_quit_wrapper(fun): signal.signal(signal.SIGINT, Global.set_quit) def fun2(*args, **kwargs): try: x = fun(*args, **kwargs) # equivalent to "apply" finally: kill_gtk_thread() Global.set_quit() return x return fun2 if __name__ == '__main__': # <-- this line is optional my_quit_wrapper(main)()