#!/usr/bin/env python # -*- coding: utf-8 -* import os import sys import xmlrpclib import gi gi.require_version('Gtk', '3.0') gi.require_version('PangoCairo', '1.0') from gi.repository import Gtk, Gdk, GObject, GLib, PangoCairo, Pango import threading import xmlrpclib import lliurex.net import subprocess import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import gettext gettext.textdomain('zero-lliurex-jclic-biblio-installer') _ = gettext.gettext DESKTOP=0 SERVER=1 CLIENT=2 CLIENT_BASE_DIR=os.path.expanduser("~/JClic/projects/") SERVER_BASE_DIR="/net/server-sync/share/jclic-aula/" TEUMESTRE="elteumestre_JClic_Infantil_Primaria_13.7" MURCIA="Murcia" JAUME="ratoli" class JclicRsrc: def __init__(self): self.n4d=xmlrpclib.ServerProxy("https://server:9779") self.t=threading.Thread() self.internet_status=False self.where_am_i=DESKTOP self.start_gui() #def def start_gui(self): builder=Gtk.Builder() glade_path="/usr/share/zero-lliurex-jclic-biblio-installer/rsrc/zero-jclic-library-setup.glade" builder.set_translation_domain("zero-lliurex-jclic-biblio-installer") builder.add_from_file(glade_path) self.main_window=builder.get_object("main_window") self.pbar=builder.get_object("progressbar") self.content_window=builder.get_object("content_window") self.cancel_button=builder.get_object("cancel_button") self.apply_button=builder.get_object("apply_button") self.msg_label=builder.get_object("msg_label") self.teumestre_checkbutton=builder.get_object("teumestre_checkbutton") self.murcia_checkbutton=builder.get_object("murcia_checkbutton") self.jaume_checkbutton=builder.get_object("jaume_checkbutton") self.main_window.connect("destroy",self.quit) self.content_window.connect("destroy",self.quit) self.cancel_button.connect("clicked",self.quit) self.apply_button.connect("clicked",self.apply_clicked) self.main_window.set_name("WHITEWINDOW") self.content_window.set_name("WHITEWINDOW") self.set_css_info() self.t=threading.Thread(target=self.check) self.t.daemon=True self.t.start() GLib.timeout_add(50,self.pulsate) self.main_window.show() Gtk.main() #def start_gui def set_css_info(self): css = """ #WHITEWINDOW { background-image:-gtk-gradient (linear, left top, right top, from (#ceed85), to (#dbf499)); } GtkFrame{ background-image:-gtk-gradient (linear, left top, left bottom, from (#ffdc5a), to (#ffdc5a)); } #WHITEFONT { color: white; text-shadow: 0px 1px black; } """ self.style_provider=Gtk.CssProvider() self.style_provider.load_from_data(css) Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) #def set_css_info def pulsate(self): if self.t.is_alive(): self.pbar.pulse() else: self.pbar.set_fraction(1) self.main_window.hide() if self.internet_status: if self.where_am_i==SERVER: self.mestre_dir=SERVER_BASE_DIR+TEUMESTRE self.murcia_dir=SERVER_BASE_DIR+MURCIA self.jaume_dir=SERVER_BASE_DIR+JAUME else: self.mestre_dir=CLIENT_BASE_DIR+TEUMESTRE self.murcia_dir=CLIENT_BASE_DIR+MURCIA self.jaume_dir=CLIENT_BASE_DIR+JAUME print self.mestre_dir if os.path.exists(self.mestre_dir): self.teumestre_checkbutton.set_active(True) if os.path.exists(self.murcia_dir): self.murcia_checkbutton.set_active(True) if os.path.exists(self.jaume_dir): self.jaume_checkbutton.set_active(True) self.content_window.show() else: self.msg_label.set_markup(""+"There is no internet connection."+"") return self.t.is_alive() #def pulsate def check(self): import time if lliurex.net.get_ip_from_host("www.google.es")!=None: self.internet_status=True if os.path.exists("/var/lib/n4d/variables-dir/REMOTE_VARIABLES_SERVER"): self.where_am_i=CLIENT os.environ["http_proxy"]="proxy:3128" if os.path.exists("/var/lib/n4d/variables-dir/LDAP_BASE_DN"): self.where_am_i=SERVER time.sleep(2) #def check def apply_clicked(self,widget): self.apply_button.set_sensitive(False) t=threading.Thread(target=self._execute) t.daemon=True t.start() #def apply def _execute(self): command="zero-lliurex-jclic-biblio-downloader" cmd="http_proxy='%s' %s %s elteumestre %s"%(["","proxy:3128"][self.where_am_i==2],command,["remove","install"][self.teumestre_checkbutton.get_active()],[CLIENT_BASE_DIR,SERVER_BASE_DIR][self.where_am_i==1]) print "[!] CALLING",cmd subprocess.call(cmd,shell=True,preexec_fn=lambda: signal.signal(signal.SIGPIPE,signal.SIG_DFL)) cmd="http_proxy='%s' %s %s murcia %s"%(["","proxy:3128"][self.where_am_i==2],command,["remove","install"][self.murcia_checkbutton.get_active()],[CLIENT_BASE_DIR,SERVER_BASE_DIR][self.where_am_i==1]) print "[!] CALLING",cmd subprocess.call(cmd,shell=True,preexec_fn=lambda: signal.signal(signal.SIGPIPE,signal.SIG_DFL)) cmd="http_proxy='%s' %s %s ratoli %s"%(["","proxy:3128"][self.where_am_i==2],command,["remove","install"][self.jaume_checkbutton.get_active()],[CLIENT_BASE_DIR,SERVER_BASE_DIR][self.where_am_i==1]) print "[!] CALLING",cmd subprocess.call(cmd,shell=True,preexec_fn=lambda: signal.signal(signal.SIGPIPE,signal.SIG_DFL)) print "DONE" self.quit(None) #def _execute def quit(self,widget): Gtk.main_quit() sys.exit(0) #def quit #class JclicRsrc if __name__=="__main__": jclic=JclicRsrc()