import subprocess import os import urllib import apt import apt.debfile import types class LliureXRemoteInstallerClient: dir_tmp="/tmp/.LLXRemoteInstallerClient" N4D_VAR="LLX_REMOTE_INSTALLER" N4D_INSTALLED="LLX_REMOTE_INSTALLER_INSTALLED" #VALOR VARIABLE DEL REPO ADDAPLICATION_SOURCES dir_sources="/etc/apt/sources.list.d/" file_sources="llxremoteinstaller_sources" file_sources=str(dir_sources)+str(file_sources) #VALORES DE LOS DICCIONARIOS DEB='deb' APT='apt' SH='sh' LIST='lista' URL='url' #PAQUETE ESENCIAL PARA LOS PROVIDES pack_provide="dctrl-tools" #RESUMEN DE APPS INSTALADAS LIST_APP_FINAL=[] cache=apt.Cache() def __init__(self): pass #def __init__ def create_dict (self,mode=[]): try: #CREACION DEL DICCIONARIO DE LO QUE HEMOS INSTALADO dict={} for mod in mode: dict[mod]=[] COMMENT="[LLXRemoteInstallerClient] (create_dict) Dictionary is created %s"%(dict) print (COMMENT) return [True,str(COMMENT),dict] except Exception as e: print e return[False,str(e)] #def_create_dict def read_var (self,namevar=None,localhost=None): try: if localhost in ["",None]: proxy="https://server:9779" else: proxy="https://localhost:9779" import xmlrpclib as x c=x.ServerProxy(proxy) DICT=c.get_variable("","VariablesManager",namevar) COMMENT="[LLXRemoteInstallerClient] (read_var) La variable N4D %s de %s posee el valor %s"%(namevar,proxy,DICT) print (COMMENT) return [True,str(COMMENT),DICT] except Exception as e: return [False,str(e)] #def_read_list def initialize_n4dvar(self,list_dict): try: dict={} for x in list_dict: #print "Inicializando...%s"%x dict[x]={} if x == self.APT: print "Es un apt" dict[x]['lliurex']={} dict[x]['lliurex'][self.LIST]=[] dict[x]['lliurex'][self.URL]=[] else: #print "Es otra cosa....." dict[x][self.URL]=[] dict[x][self.LIST]=[] COMMENT=("[LLXRemoteInstallerClient] (initialize_n4dvar) Diccionario inicializado") print ("%s" %COMMENT) return [True,str(COMMENT),dict] except Exception as e: return [False,str(e)] #def_initialize_var def test_var (self,namevar=None,localhost=None,user=None,passwd=None): try: if localhost in ["",None]: proxy="https://server:9779" else: proxy="https://localhost:9779" import xmlrpclib as x c=x.ServerProxy(proxy) u=(user,passwd) VALOR=c.get_variable(u,"VariablesManager",namevar) print "[LLXRemoteInstallerClient] (test_var) El valor de la variable N4D %s del test es:%s"%(namevar,VALOR) if VALOR in [None,'','None']: #print "Dentro.........." list_dict=[self.APT,self.DEB,self.SH] #VALOR={} #print list_dict VALOR=self.create_dict ([self.APT,self.DEB,self.SH])[2] #VALOR=self.initialize_n4dvar(list_dict)[2] if objects["VariablesManager"].add_variable(namevar,VALOR,"",namevar,[],False,False)[0]: COMMENT = ("[LLXRemoteInstallerClient] (test_var) Added variable %s to VariablesManager with valor %s" %(namevar,VALOR)) print ("%s" %COMMENT) return [True,str(COMMENT)] else: COMMENT = ("[LLXRemoteInstallerClient] (test_var) Cannot create it again %s to VariablesManager" %namevar) print ("%s" %COMMENT) return [True,str(COMMENT)] else: COMMENT=("[LLXRemoteInstallerClient] (test_var) %s Variable exists in your system, it hasn't been created again" %namevar) print ("%s" %COMMENT) return [True,str(COMMENT)] except Exception as e: return [False,str(e)] #def_test_var def reset_var (self,namevar=None,localhost=None): try: if localhost in ["",None]: proxy="https://server:9779" else: proxy="https://localhost:9779" import xmlrpclib as x c=x.ServerProxy(proxy) data=None objects["VariablesManager"].set_variable(namevar,data) COMMENT=("[LLXRemoteInstallerClient] (reset_var) %s has been updated" %namevar) print ("%s" %COMMENT) return [True,str(COMMENT)] except Exception as e: return [False,str(e)] #def_reset_var def update_var_dict (self,namevar=None,dict={},localhost=None,user=None,passwd=None): try: if self.test_var(namevar,localhost,user,passwd)[0]: if localhost in ["",None]: proxy="https://server:9779" else: proxy="https://localhost:9779" import xmlrpclib as x c=x.ServerProxy(proxy) objects["VariablesManager"].set_variable(namevar,dict) COMMENT="[LLXRemoteInstallerClient] (update_var_list) %s has been updated with this list of APP %s" %(namevar,dict) print ("%s" %COMMENT) return [True,str(COMMENT)] else: COMMENT="[LLXRemoteInstallerClient] (update_var_list) Cannot updated variable" print ("%s" %COMMENT) return [False,str(COMMENT)] except Exception as e: return [False,str(e)] #def_add_list def download(self, apps=[],url=None,dir=None): try: #CREATE AUX_SOURCES IF IT'S NECESSARY if not os.path.exists(dir): os.makedirs(dir) for app in apps: file_app=str(dir)+"/"+app url_complete=str(url)+str(app) if os.path.exists(file): print "[LLXRemoteInstallerClient] (download) The FILE: %s has been donwloaded before, it will be deleted now."%(file) os.remove(file) print "[LLXRemoteInstallerClient] (download) The FILE: %s is downloading now to directory %s ....."%(app,file_app) urllib.urlretrieve(url_complete,file_app) os.chmod(file_app,0755) COMMENT="Your FILES: %s has been downloaded in %s"%(apps,dir) return [True,str(COMMENT)] except Exception as e: return[False,str(e)] #def_download def repo_add (self,sources_private=None): try: if sources_private not in ["",None,[]]: COMMENT="[LLXRemoteInstallerClient](repo_add) REPO IS PARTICULAR %s" %sources_private print ("%s" %COMMENT) f_used=open(self.file_sources,'a') f_used.writelines(sources_private) f_used.close() #NOW READ THE NEW SOURCES.LIST sources=[] file=open(self.file_sources) f=file.read().splitlines() for line in f: sources.append(line) file.close() COMMENT="[LLXRemoteInstallerClient](repo_add) Your repo LLXRemoteInstallerClient has new lines %s"%sources print ("%s" %COMMENT) return [True,str(COMMENT),sources] except Exception as e: return [False,str(e)] #def_repo_update def repo_restore (self,file=None): try: COMMENT="[LLXRemoteInstallerClient](repo_restore) Repo %s to test APT Aplications is deleted and restore to initial state"%file print ("%s" %COMMENT) if os.path.exists(file): #print "Borrandoooooooooooooooooooooooooooooo" os.remove(file) self.repo_update() COMMENT="[LLXRemoteInstallerClient](repo_restore) Repo from AddApplications has deleted" print ("%s" %COMMENT) return [True,str(COMMENT)] except Exception as e: return [False,str(e)] #def_repo_restore def repo_update (self): try: print "[LLXRemoteInstallerClient](repo_restore) Updating indices, please wait........" #proc = subprocess.Popen('apt-get update', shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash") #proc.wait() COMMENT="[LLXRemoteInstallerClient](repo_restore) Your APT CACHE has updated with new indices" print ("%s" %COMMENT) return [True,str(COMMENT)] except Exception as e: return [False,str(e)] #def_repo_restore def deb_solvedependence (self,deb=None,list=[]): try: for s in list: name_deb=s[0] version_deb=s[1] test_deb=s[2] print "[LLXRemoteInstallerClient](deb_solvedependence) DEB: %s has the dependence with * package: %s -- version: %s %s -- "%(deb,name_deb,test_deb,version_deb) #COMPRUEBO SI EXISTE EN MI CACHE, SINO ABORTAMOS EL PROCESO if name_deb in self.cache: print "[LLXRemoteInstallerClient](deb_solvedependence) Dependence is avaible" pkg=self.cache[name_deb] #COMPRUEBO QUE ESTA INSTALADA O PIDO QUE SE INSTALE LA DEPENDENCIA if pkg.is_installed: print "[LLXRemoteInstallerClient](deb_solvedependence) Dependence IS INSTALLED in your system DO NOTHING WITH IT" else: print "[LLXRemoteInstallerClient](deb_solvedependence) Dependence %s has to been installed now ......"%(name_deb) list_deb_aux=[] list_deb_aux.append(name_deb) self.apt_install(list_deb_aux) else: #ANTES DE ABROTAR EL PROCESO COMPRUEBO QUE NO ES UN PAQUETE VIRTUAL PROCEDENTE DE UN PROVIDES print "[LLXRemoteInstallerClient](deb_solvedependence) Testing if my dependence %s is virtual package"%name_deb result=subprocess.Popen(["LAGUAGE=en_EN; grep-status -FProvides,Package -sPackage,Provides,Status %s"%name_deb],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0] virtual_deb=False #REVISAMOS EL RESULTADO A VER SI ES VIRTUAL for line in result.splitlines(): #print "Test line %s"%line if "install" in line: print "[LLXRemoteInstallerClient](deb_solvedependence) Dependence: %s is a virtual package installed in my system"%name_deb virtual_deb=True #SOLO DEVOLVEREMOS FALSE SI NO SE CUMPLEN DEPENDENCIAS Y NO ES PAQUETE VIRTUAL if not virtual_deb: COMMENT="[LLXRemoteInstallerClient](deb_solvedependence) Your DEB: %s has dependences without solution with your actual repos to solve this dependence APP: %s can not been installed"%(deb,name_deb) print COMMENT return[False,str(COMMENT)] COMMENT="[LLXRemoteInstallerClient](deb_solvedependence) Your DEPENDENCES has been resolved now you can continue to install your DEB: %s"%(deb) print COMMENT return[True,str(COMMENT)] except Exception as e: return [False,str(e)] #def_debsolvedependence def deb_testdependences(self,deb=None,list=[]): try: #COMPRUEBO QUE LAS DEPENDENCIAS ESTAN INSTALADAS print "[LLXRemoteInstallerClient](deb_testdependences) Testing your DEB: %s with this dependences list %s"%(deb,list) for x in list: print print "[LLXRemoteInstallerClient](deb_testdependences) -------------- Testing this tupla %s ------------------"%x #print len(x) #ME ASEGURO QUE TESTEAMOS UNA DEPENDENCIA DE UN SOLO ELEMENTO, SI ES DE DOS O MAS ES PORQUE ES UN OR SOLO CUMPLIR UNO DE LOS CASOS if len(x)<2: if self.deb_solvedependence(deb,x)[0] == 'False': name_deb=x[0] COMMENT="[LLXRemoteInstallerClient](deb_testdependences) Your DEB: %s has dependences without solution with your actual repos, APP: %s can not been installed"%(deb,name_deb) print COMMENT return[False,str(COMMENT)] else: #TENEMOS UNA DEPENDENCIA DE UN OR CON LO QUE UN SOLO TRUE DE UNA DE LAS DEPENDENCIAS PERMITIRA INSTALAR EL DEB OK=False print "[LLXRemoteInstallerClient](deb_testdependences) Initializing test for *OR* tupla " for s in x: s=[s] name_deb=s[0][0] print "[LLXRemoteInstallerClient](deb_testdependences) Testing OR tupla, one element is %s"%s if self.deb_solvedependence(deb,s)[0]: print "[LLXRemoteInstallerClient](deb_testdependences) Testing OR tupla, this dependence %s can be install, resolv the conflict"%name_deb OK=True ok_solved=s if OK in ['False',False]: COMMENT="[LLXRemoteInstallerClient](deb_testdependences) Testing OR tupla, can not resolve this OR dependence for %s"%(x) print COMMENT return[False,str(COMMENT)] else: print "[LLXRemoteInstallerClient](deb_testdependences) Testing OR tupla, can install this dependence: %s and can resolve OR dependence for %s"%(ok_solved,x) COMMENT="[LLXRemoteInstallerClient](deb_testdependences) Your DEPENDENCES has been resolved now you can install your DEB: %s"%(deb) print COMMENT return[True,str(COMMENT)] except Exception as e: print e return [False,str(e)] #deb_testdependences def deb_install(self,list_deb=[],dir_deb=None): try: list_ok=[] list_not=[] #CARGO LA CACHE DE PAQUETES DEL SISTEMA print "[LLXRemoteInstallerClient](deb_install) CACHE has updated with indices" #COMPRUEBO CADA DEB QUE TENGO QUE INSTALAR for deb in list_deb: file_deb=str(dir_deb)+"/"+str(deb) print "[LLXRemoteInstallerClient](deb_install) Test first deb to install: %s in dir: %s"%(deb,file_deb) app=apt.debfile.DebPackage(file_deb,self.cache) #COMPRUEBO QUE ES INSTALABLE if app.check(): print "[LLXRemoteInstallerClient](deb_install) The deb can be installed, now test the dependences, please wait...." if self.deb_testdependences(deb,app.depends)[0]: #CON LAS DEPENDENCIAS COMPROBADAS Y RESUELTAS INSTALAMOS LA APLICACION print "[LLXRemoteInstallerClient](deb_install) The system are ready to install the DEB: %s"%(deb) print "[LLXRemoteInstallerClient](deb_install) DEB INSTALLED NOW" print app.install() list_ok.append(deb) else: #NO PUEDE RESOLVER LAS DEPENDENCIAS DE ESTE PAQUETE,, NO LO INSTALA print "[LLXRemoteInstallerClient](deb_install) The system cannot resolve the dependences for your deb, review your repos or DEB if you want to install it: %s"%(deb) print "[LLXRemoteInstallerClient](deb_install) DEB INSTALLED ABORTED" print else: #EL DEB NO ES INSTALABLE POR ALGUNA RAZON print "[LLXRemoteInstallerClient](deb_install) Your DEB: %s cannot be installed in your system"%(deb) list_not.append(deb) COMMENT="The DEBS installed are: %s and DEBS with problems are:%s"%(list_ok, list_not) return [True,str(COMMENT),list_ok,list_not] except Exception as e: return[False,str(e)] #deb_install def sh_install(self,list_sh=[],dir=""): try: list_ok=[] list_not=[] for app in list_sh: print "[LLXRemoteInstallerClient](sh_install) Working with SCRIPT: %s"%app file_app=str(dir)+"/"+app if os.path.exists(file_app): print "[LLXRemoteInstallerClient](sh_install) Executing it, please wait.........." proc = subprocess.Popen(file_app, shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash") proc.wait() lines=subprocess.Popen(["LAGUAGE=en_EN; md5sum %s | awk '{print $1}'"%file_app],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0] for line in lines.splitlines(): md5=line list_ok.append([app,md5]) else: print "[LLXRemoteInstallerClient](sh_install) This script not exist in your system." list_not.append(app) if list_ok not in ["",None,[]]: COMMENT="Your FILES: %s has been executed"%(list_ok) return [True,str(COMMENT),list_ok,list_not] else: COMMENT="Some script could not executed in your system, please review it %s"%(list_not) return [True,str(COMMENT),list_ok,list_not] except Exception as e: return[False,str(e)] #sh_install def apt_install(self,list_apt=[]): try: list_apt_ok=[] list_apt_not=[] list_apt_system=[] print "" print "############################################################" for app in list_apt: print "[LLXRemoteInstallerClient](apt_install) Comprobando si es avaiable e instalable la APP: %s"%app if app in self.cache: pkg=self.cache[app] if pkg.is_installed: print "[LLXRemoteInstallerClient](apt_install) The APP: %s is intalled in your system"%(app) print "" list_apt_system.append(app) else: print "[LLXRemoteInstallerClient](apt_install) The APP: %s wil be installed soon"%(app) pkg.mark_install() list_apt_ok.append(app) list_apt_system.append(app) print "" else: list_apt_not.append(app) if list_apt_ok not in ["",None,[]]: print "[LLXRemoteInstallerClient](apt_install) Please wait we have to install this APP list: %s"%(list_apt_ok) print "WAIT........" self.cache.commit() if list_apt_not in ["",None,[]]: COMMENT="[LLXRemoteInstallerClient](apt_install) The system has been updated with this APP list: %s"%(list_apt_ok) else: COMMENT="[LLXRemoteInstallerClient](apt_install) The system has been updated with this APP list: %s but this list cannot installed:%s"%(list_apt_ok, list_apt_not) else: #print "[LLXRemoteInstallerClient](apt_install) List to install is empty because your system have the list or do not ha it in your repos" if list_apt_not in ["",None,[]]: COMMENT="[LLXRemoteInstallerClient](apt_install) Do nothing, because your system has installed all APP in list: %s"%(list_apt) else: COMMENT="[LLXRemoteInstallerClient](apt_install) Do nothing, because your system has installed all APP in list: %s and this list cannot installed because your REPO do not have it:%s"%(list_apt, list_apt_not) if list_apt_system not in ["",None,[]]: for app in list_apt_system: print "[LLXRemoteInstallerClient](apt_install) The APP: %s is intalled in your system.....Adding to list installed"%(app) list_apt_ok.append(app) print COMMENT print "%s --- %s --- %s"%(list_apt_ok,list_apt_not,list_apt_system) print "############################################################" return [True,str(COMMENT),list_apt_ok,list_apt_not,list_apt_system] except Exception as e: return[False,str(e)] #apt_install def test_system(self,user,passwd): try: print "*******************************************" print " LLXRemoteInstallerClient " print "*******************************************" #OBTENEMOS EL DICCIONARIO DE LAS COSAS INSTALADAS #print "[LLXRemoteInstallerClient] (test_system) Test if exists variable local N4D" self.test_var(self.N4D_INSTALLED,"localhost",user,passwd) #print "[LLXRemoteInstallerClient] (test_system) Variablelocal N4D exists, read it" dict_orig=self.read_var(self.N4D_INSTALLED,"localhost")[2] #OBTENEMOS EL DICCIONARIO DE LA VARIABLE DE N4D DEL SERVER dict=self.read_var(self.N4D_VAR)[2] #SI EL SERVER NO INDICA QUE INSTALE NADA NO INSTALO NADA if dict in ["",None,"None"]: COMMENT="[LLXRemoteInstallerClient](test_system) Variable %s do not exist in your server, do nothing"%self.N4D_VAR print ("%s" %COMMENT) return [True,str(COMMENT)] print "" print "*****************************************************************************" print "" print "[LLXRemoteInstallerClient] (test_system) The DICTIONARY to use is: %s"%(dict) print "" print "[LLXRemoteInstallerClient] (test_system) The DICTIONARY installed in system is: %s"%dict_orig print "" print "*****************************************************************************" print "" dict_orig_aux=dict_orig #TEST DE LOS DEBS #OBTENEMOS LOS VALORES DEL DICCIONARIO list_deb=dict[self.DEB][self.LIST] url_deb=dict[self.DEB][self.URL] #CREAMOS LA RUTA DE DESCARGA dir_deb=str(self.dir_tmp)+"/"+"deb" #COMPROBAMOS QUE EL DEB NO ESTABA ANTERIORMENTE INSTALADO EN EL SISTEMA deb_aux=[] print "[LLXRemoteInstallerClient](test_system) Comprobando el listado de DEBS si estaba instalado antes %s"%list_deb for deb in list_deb: if deb not in dict_orig[self.DEB]: print "[LLXRemoteInstallerClient](test_system)El DEB:%s no estaba, deberemos de instalarlo"%deb deb_aux.append(deb) else: print "[LLXRemoteInstallerClient](test_system)El DEB:%s esta instalado, NO LO ANYADIMOS"%deb list_deb=deb_aux #DESCARGAMOS LO NECESARIO SI TENEMOS VALORES if list_deb not in ["",None,[]]: print "[LLXRemoteInstallerClient](test_system) El listado de DEBS es %s i lo descargaremos de la URL: %s"%(list_deb,url_deb) self.download(list_deb,url_deb,dir_deb) result_deb=self.deb_install(list_deb,dir_deb) else: print "[LLXRemoteInstallerClient](test_system) El listado de DEBS esta vacio no es necesario hacer nada" result_deb=["","","","",""] print "##########################################################" #TEST DE LOS SH #OBTENEMOS LOS VALORES DEL DICCIONARIO list_sh=dict[self.SH][self.LIST] print "1" print list_sh url_sh=dict[self.SH][self.URL] print "2" print url_sh #CREAMOS LA RUTA DE DESCARGA Y DESCARGAMOS LO NECESARIO SI TENEMOS VALORES dir_sh=str(self.dir_tmp)+"/"+"scripts" print "3" if list_sh not in ["",None,[]]: sh_aux=[] for sh_tupla in list_sh: sh=sh_tupla[0] md5=sh_tupla[1] print "4" print dict_orig[self.SH] if sh_tupla not in dict_orig[self.SH]: print "[LLXRemoteInstallerClient](test_system)El SH:%s no estaba, deberemos de instalarlo"%sh sh_aux.append(sh) else: print "[LLXRemoteInstallerClient](test_system)El SH:%s esta instalado, NO LO ANYADIMOS"%sh #UNA VEZ COMPROBADA LA LISTA DE SCRIPTS LOS DESCARGAMOS Y EJECUTAMOS list_sh=sh_aux print "[LLXRemoteInstallerClient](test_system) El listado de SCRIPTS es %s i lo descargaremos de la URL: %s"%(list_sh,url_sh) self.download(list_sh,url_sh,dir_sh) if list_sh not in ["",None,[]]: result_sh=self.sh_install(list_sh,dir_sh) else: print "[LLXRemoteInstallerClient](test_system) El listado de SCRIPTS esta vacio no es necesario hacer nada" result_sh=["","","","",""] else: print "[LLXRemoteInstallerClient](test_system) El listado de SCRIPTS esta vacio no es necesario hacer nada" result_sh=["","","","",""] print "##########################################################" #TEST DE LOS APT #OBTENEMOS LOS VALORES DEL DICCIONARIO list_apt_resume=[] print "" for x in dict[self.APT]: list_apt=None print "----------------------------------------------------------------" print "[LLXRemoteInstallerClient](test_system) Comprobando el PPA: %s"%x list_apt=dict[self.APT][x][self.LIST] #print "[LLXRemoteInstallerClient](dict_ok) Comprobando el listado de APP: %s"%list_apt url=dict[self.APT][x][self.URL] print "[LLXRemoteInstallerClient](test_system) El listado de APT es %s lo comprobaremos en la URL: %s"%(list_apt,url) apt_aux=[] print "[LLXRemoteInstallerClient](test_system) Comprobando el listado de APT si estaba instalado antes %s"%list_apt for apt in list_apt: if apt not in dict_orig[self.APT]: print "[LLXRemoteInstallerClient](test_system)El APT: %s no estaba, deberemos de instalarlo"%apt apt_aux.append(apt) else: print "[LLXRemoteInstallerClient](test_system)El APT: %s esta instalado, NO LO ANYADIMOS"%apt list_apt=apt_aux #print list_apt if list_apt not in ["",None,[],]: if url not in ["",None]: #COMPROBAMOS SI ES UN REPO NUEVO POR SI HAY QUE CREARLO Y ACTUALIZAR LOS INDICES #print "entro aqui dos" if self.repo_add(url)[0]: print "[LLXRemoteInstallerClient](test_system) New REPO has created in your system" if self.repo_update()[0]: #print "[LLXRemoteInstallerClient](test_system) Your CACHE has updated with new indices" pass else: return [False,"false el repo_update"] #return [False,self.repo_update()[1]] else: #return [False,self.repo_add()[1]] return [False,"false el repo_add"] #CON LOS REPOS ACTUALIZADOS INSTALAMOS LA LISTA print "[LLXRemoteInstallerClient](test_system) Llamamos a apt_install con la lista %s"%list_apt result_apt=self.apt_install(list_apt)[2] if result_apt not in ["",None,[]]: for app in result_apt: list_apt_resume.append(app) #print result_apt[2] #print result_apt[4] #BORRAMOS EL REPO SI FUE CREADO ANTERIORMENTE self.repo_restore(self.file_sources) print "" else: print "" print "[LLXRemoteInstallerClient](test_system) No hacemos nada con este REPO %s esta vacia su lista de APPS"%x result_apt=["","","","",""] print "" result_apt=list_apt_resume print "##########################################################" #ME ASEGURO QUE ES UNA LISTA sh_installed=list(result_sh[2]) #ANYADIMOS LO QUE HEMOS HECHO AL DICCIONARIO DE N4D PARA GUARDAR EL ESTADO ACTUAL if dict_orig in ["",None,{}]: #CREAMOS EL DICCIONARIO PORQUE NO EXISTIA DE ANTES print "[LLXRemoteInstallerClient](test_system) Creando el diccionario......." dict_new=self.create_dict ([self.APT,self.DEB,self.SH])[2] dict_new[self.APT]=list(result_apt) dict_new[self.DEB]=list(result_deb[2]) dict_new[self.SH]=list(result_sh[2]) self.update_var_dict (self.N4D_INSTALLED,dict_new,"localhost",user,passwd) else: #VAMOS A ACTUALIZAR EL DICCIONARIO CON LO QUE HEMOS HECHO #LO COPIAMOS PARA TENER UN RESPALDO dict_new=dict_orig print "[LLXRemoteInstallerClient](test_system) El diccionario existia, solo lo actualizamos con estos valores iniciales.......%s"%dict_new print "[LLXRemoteInstallerClient](test_system) Anyadiremos las APTs: %s ** DEBS: %s ** SH: %s "%(result_apt,result_deb[2],result_sh[2]) #CREAMOS UNA TUPLA PARA REVISAR EL DICCIONARIO dict_help=self.create_dict ([self.APT,self.DEB,self.SH])[2] dict_help[self.APT]=list(result_apt) dict_help[self.DEB]=list(result_deb[2]) dict_help[self.SH]=list(result_sh[2]) print "[LLXRemoteInstallerClient](test_system) El diccionario a comparar es %s"%dict_help #REVISAMOS LOS VALORES DEL DICCIONARIO for valor_dict in dict_help: print "[LLXRemoteInstallerClient](test_system) Test de las APP del MODO: %s "%valor_dict for app_installed in dict_help[valor_dict]: ok=False print "[LLXRemoteInstallerClient](test_system) Comprobamos si la APP Instalada: %s "%app_installed for app_history in dict_orig[valor_dict]: print "[LLXRemoteInstallerClient](test_system) APP Instalada: %s -- TESTING -- APP Systema: %s"%(app_installed,app_history) if app_history == app_installed: print "[LLXRemoteInstallerClient](test_system) Existia con este nombre, no la anyadimos al diccionario" ok=True if not ok: print "[LLXRemoteInstallerClient](test_system) Anyadiendo a la lista la APP: %s"%app_installed print "" dict_new[valor_dict].append(app_installed) else: print "[LLXRemoteInstallerClient](test_system) Tras la revision no se anyade al diccionario la APP: %s"%app_installed print "" print "" print "-----------------------------------------------" print "" print "El diccionario final queda %s"%dict_new print "" print "-----------------------------------------------" print "Actualizandolo......." self.update_var_dict (self.N4D_INSTALLED,dict_new,"localhost",user,passwd) #ANYADIR A LA VARIABLE N4D LAS COSAS INSTALADAS #self.update_var_dict(N4D_INSTALLED,new_dict) COMMENT="The system has configured with the APPS: %s * has executed the scripts: %s * Install new DEBS: %s"%(result_apt,sh_installed,result_deb[2]) print COMMENT return [True,str(COMMENT),result_apt,result_sh[2],result_deb[2],dict_new] except Exception as e: return[False,str(e)]