summaryrefslogtreecommitdiffstats
path: root/usr/share/mageiawelcome/mageiawelcome.py
blob: f553bd61bfeba4be17463fe0c7e6606e8924f485 (plain)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# -*- coding: utf-8 -*-

import signal
import os
import time
import urllib.request, urllib.parse, urllib.error
import subprocess
import subprocess
import shlex
import gettext
import json
import string
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

from webgui import start_gtk_thread
from webgui import launch_browser
from webgui import synchronous_gtk_message
from webgui import kill_gtk_thread

from helpers import *

# i18n
gettext.install("mageiawelcome")

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()
    release = subprocess.getoutput('lsb_release -sd')
    release = release[1:-1]
    kernel = subprocess.getoutput('uname -r')
    if os.uname()[4] == 'x86_64':
      arch = '64-bit'
    else:
      arch = '32-bit'
    home = os.getenv("HOME")
    username = os.getenv("USER")
    desktop = get_desktop_name(os.path.basename(os.getenv("DESKTOP_SESSION")))
    
    if desktop == 'Other':
      desktop = get_desktop_name2(os.getenv("XDG_CURRENT_DESKTOP"))
    
   
    #collect packages nad its status
    listapp = get_listapp()
    
    #TODO check if non-free and tainted enabled
    restricted_repos = "disabled"
    
   
    l={}
    l['name'] = _("Welcome to Mageia!")
    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['desktop_l'] = _("Desktop:")
    l['desktop'] = desktop
    l['welcome_btn'] = _("Welcome")
    l['welcome'] = _("Welcome<!--user//-->")
    l['user'] = username
    l['welcome_msg'] = _("<p>Thank you for choosing Mageia!</p><p>We have put in a lot of effort to provide you with the best possible system. We hope you will have a good experience with Mageia. If you feel that our project is a good idea, we would also appreciate any contribution you can make to it for next versions.</p><p>To find out how you can help <a class='weblink' href='http://www.mageia.org/en/contribute/'>click here</a>.</p><p>Don't forget to tell your friends about Mageia.</p>")
    l['mcc'] = _("Mageia Control Center")
    l['conf_update'] = _("Configure media sources and update system")
    l['inst_remove'] = _("Install and remove software")
    l['h_documentation'] = _("Documentation")
    l['h_documentation_url'] = _("https://wiki.mageia.org/en/Documentation")
    l['features'] = _("New Features")
    l['relnotes'] = _("Release Notes")
    l['relnotes_url'] = _("https://wiki.mageia.org/en/Mageia_6_Release_Notes")
    l['errata'] = _("Errata")
    l['errata_url'] = _("https://wiki.mageia.org/en/Mageia_6_Errata")
    l['newcomers'] = _("Newcomers Howto")
    l['newcomers_url'] = _("https://wiki.mageia.org/en/Newcomers_start_here")
    l['h_support'] = _("Support")
    l['forum'] = _("Forums")
    l['wiki'] = _("Wiki")
    l['chat'] = _("Chat Room")
    l['bugs'] = _("Bugzilla")
    l['h_community'] = _("Community")
    l['comm_center'] = _("Community Center")
    l['contribute'] = _("Contribute")
    l['donate'] = _("Donations")
    l['joinus'] = _("Join us!")
    l['mccdesc'] = _("Mageia Control Center (aka drakconf) is a set of tools to help you configure your system")
    l['SM'] = _("Software Management")
    l['Oa'] = _("Online administration")
    l['H'] = _("Hardware")
    l['NI'] = _("Network & Internet")
    l['S'] = _("System")
    l['NS'] = _("Network Sharing")
    l['LD'] = _("Local Disks")
    l['Sec'] = _("Security")
    l['B'] = _("Boot")
    l['adminpass'] = _("Administrator password is needed")
    l['userpass'] = _("User password is needed")
    l['conf_media'] = _("Configure media sources ...")
    l['mag_media'] = _("Mageia official repositories contain:")
    l['core'] = _("<span class='label green'>core</span> - the free-open-source packages, i.e. software licensed under a free-open-source license")
    l['nonfree'] = _("<span class='label red'>non-free</span> - some programs which are not free, or closed source. For example this repository includes Nvidia and ATI graphics card proprietary drivers, firmware for various WiFi cards, etc")
    l['tainted'] = _("<span class='label red'>tainted</span> - includes packages released under a free license. However, they may infringe on patents and copyright laws in some countries, e.g. multimedia codecs needed to play various audio/video files; packages needed to play commercial video DVD, etc. ")
    l['note'] = _("<strong>Note!</strong> non-free and tainted are not enabled by default.")
    l['editss'] = _("Edit software sources")
    l['updsys'] = _("... and update system")
    l['chkupd'] = _("Check system updates")
    l['guirpmdrake'] = _("GUI - RPMDrake")
    l['rpmdrake_desc'] = _("<span class='label green'>Rpmdrake</span> is a program for installing, uninstalling and updating packages. It is the graphical user interface of <span class='label green'>urpmi</span>")
    l['readmore'] = _("read more (wiki)")
    l['r_rpmdrake'] = _("RPMdrake")
    l['urpmi'] = _("URPMI - from command line")
    l['r_term'] = _("Terminal")
    l['small_selection'] = _("This is just small selection of popular packages, for more run")
    l['featured'] = _("Featured")
    l['games'] = _("Games")
    l['internet'] = _("Internet")
    l['video'] = _("Video")
    l['audio'] = _("Audio")
    l['office'] = _("Office")
    l['graphics'] = _("Graphics")
    l['system'] = _("System")
    l['programming'] = _("Programming")
    l['selected'] = _("Selected packages:")
    l['inst_sel'] = _("Install selected")
    l['youcan'] = _("You can always launch MageiaWelcome from menu")    
    
    l['rpm_install'] = _("Applications") 
    l['applist'] = listapp
    l['bodyclass'] = restricted_repos
    l['besure_repos'] = _("Be sure you have enabled <a>online repositories</a>")
    
    
    if os.path.exists(home + "/.mageiawelcome/norun.flag"):
            l['checked'] = ("")
    else:
            l['checked'] = ("CHECKED")
   
    
    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 = json.loads(msg)
            again = True
            if msg == "close":
              return 0
            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.startswith("irc"):
              os.system("xdg-open " + msg)
            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)()