1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# -*- 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. 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)
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)()
|