summaryrefslogtreecommitdiffstats
path: root/usr/lib/mageiawelcome/mageiawelcome.py
diff options
context:
space:
mode:
Diffstat (limited to 'usr/lib/mageiawelcome/mageiawelcome.py')
-rw-r--r--usr/lib/mageiawelcome/mageiawelcome.py164
1 files changed, 164 insertions, 0 deletions
diff --git a/usr/lib/mageiawelcome/mageiawelcome.py b/usr/lib/mageiawelcome/mageiawelcome.py
new file mode 100644
index 0000000..c203bc1
--- /dev/null
+++ b/usr/lib/mageiawelcome/mageiawelcome.py
@@ -0,0 +1,164 @@
+# -*- 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/lib/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')
+ arch = commands.getoutput('uname -m')
+ 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. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
+ 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)
+ subprocess.Popen(args)
+
+ elif msg.startswith("gurpmi"):
+ print msg
+ name = msg.split(' ')[1]
+ args = shlex.split(msg)
+ print args
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE)
+ proc.wait()
+ print proc.returncode
+ if (proc.returncode == 0):
+ web_send('$("li#'+ name +'").addClass("urpme");$("li#'+name+' button").not(".cmd").html("<i class=icon-minus-sign> </i> remove").addClass("uninst").removeClass("inst")')
+ 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)() \ No newline at end of file