#!/usr/bin/env python # -*- coding: utf-8 -* import os import xmlrpclib from gi.repository import Gtk, Gdk, GObject, GLib, PangoCairo, Pango import threading import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import gettext gettext.textdomain('lliurex-owncloud') _ = gettext.gettext class OwnCloud: def __init__(self): self.executing=False self.start_gui() #def __ini__ def start_gui(self): builder=Gtk.Builder() builder.set_translation_domain("lliurex-owncloud") glade_path="/usr/share/lliurex-owncloud/rsrc/lliurex-owncloud-setup.glade" builder.add_from_file(glade_path) self.window=builder.get_object("window1") self.accept_button=builder.get_object("accept_button") self.cancel_button=builder.get_object("cancel_button") self.dbname_entry=builder.get_object("dbname_entry") self.dbuser_entry=builder.get_object("dbuser_entry") self.dbpwd_entry=builder.get_object("dbpwd_entry") self.dbpwd_entry2=builder.get_object("dbpwd_entry2") self.user_entry=builder.get_object("user_entry") self.pwd_entry=builder.get_object("pwd_entry") self.pwd_entry2=builder.get_object("pwd_entry2") self.msg_label=builder.get_object("msg_label") self.window.connect("destroy",self.exit) self.accept_button.connect("clicked",self.accept_clicked) self.cancel_button.connect("clicked",self.exit) self.progress_window=builder.get_object("window2") self.pbar=builder.get_object("progressbar") self.window.show() self.window.set_name("BLUE") self.progress_window.set_name("BLACK") label1=builder.get_object("label1") label1.set_name("WHITE") label2=builder.get_object("label2") label2.set_name("WHITE") label3=builder.get_object("label3") label3.set_name("WHITE") label4=builder.get_object("label4") label4.set_name("WHITE") label5=builder.get_object("label5") label5.set_name("WHITE") label6=builder.get_object("label6") label6.set_name("WHITE") label7=builder.get_object("label7") label7.set_name("WHITE") label8=builder.get_object("label8") label8.set_name("WHITE") label9=builder.get_object("label9") label9.set_name("WHITE") label9=builder.get_object("label10") label9.set_name("WHITE") self.msg_label.set_name("WHITE") self.set_defaults() self.set_css_info() Gtk.main() #def start_gui def set_defaults(self): self.dbname_entry.set_text("owncloud") self.dbuser_entry.set_text("owncloud_dbu") self.user_entry.set_text("owncloud_admin") #def set_defaults def set_css_info(self): css = """ #BLUE { background-image:-gtk-gradient (linear, left top, left bottom, from (#1d2d44), to (#1d2d44));; } #BLACK{ background-image:-gtk-gradient (linear, left top, left bottom, from (#000000), to (#000000));; } GtkFrame{ background-image:-gtk-gradient (linear, left top, left bottom, from (#35537a), to (#35537a));; } #WHITE { 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 exit(self,widget): Gtk.main_quit() #def exit def get_values(self): self.template={} self.template["DB_NAME"]=self.dbname_entry.get_text() self.template["DB_USER"]=self.dbuser_entry.get_text() self.template["DB_PWD"]=self.dbpwd_entry.get_text() self.template["DB_PWD2"]=self.dbpwd_entry2.get_text() self.template["ADMIN_USER"]=self.user_entry.get_text() self.template["ADMIN_PWD"]=self.pwd_entry.get_text() self.template["ADMIN_PWD2"]=self.pwd_entry2.get_text() #def get_values def accept_clicked(self,widget): self.get_values() ret,msg=self.parse_values() if not ret: self.msg_label.set_markup(""+msg+"") return ''' ip="server" c=xmlrpclib.ServerProxy("https://%s:9779"%ip) n4d_key=self.get_n4d_key() status,ret=c.initialize_owncloud(n4d_key,"LliurexOwncloud",self.template) if status: os.system("zero-center set-configured lliurex-owncloud") self.msg_label.set_markup(""+"Initialization successful"+"") self.accept_button.set_sensitive(False) else: self.msg_label.set_markup(""+ret+"") os.system("zero-center set-failed lliurex-owncloud") ''' self.executing=True self.progress_window.show() GLib.timeout_add(50,self.pulsate) self.ret_msg="" self.ret_status=False t=threading.Thread(target=self.execute,args=()) t.daemon=True t.start() #def accept_clicked def pulsate(self): if self.executing: self.pbar.pulse() else: if self.ret_status: os.system("zero-center set-configured lliurex-owncloud") self.msg_label.set_markup(""+_("Initialization successful")+"") self.accept_button.set_sensitive(False) else: self.msg_label.set_markup(""+self.ret_msg+"") os.system("zero-center set-failed lliurex-owncloud") return self.executing #def pulsate def execute(self): ip="server" c=xmlrpclib.ServerProxy("https://%s:9779"%ip) n4d_key=self.get_n4d_key() self.ret_status,self.ret_msg=c.initialize_owncloud(n4d_key,"LliurexOwncloud",self.template) self.executing=False self.progress_window.hide() return False #def execute def get_n4d_key(self): try: f=open("/etc/n4d/key") key=f.readline().strip("\n") f.close() return key except: return None #def get_n4d_key def parse_values(self): for item in self.template: if self.template[item]=="" or self.template[item]==None: return [False,"There are empty fields to be completed"] if self.template["DB_PWD"]!=self.template["DB_PWD2"]: return [False,"DB Passwords do not match"] if self.template["ADMIN_PWD"]!=self.template["ADMIN_PWD2"]: return [False,"Administrator passwords do not match"] return [True,""] #def parse_values #class owncloud if __name__=="__main__": o=OwnCloud()