import sys import os import xmlrpclib import copy import time class PanelDesignManager: DOCK_SKEL="\ [org/mate/desktop/session/required-components]\n\ dock='%s'\n\ windowmanager='marco'\n\ filemanager='caja'\n\n" CUSTOM_FILE="99_custom_panel_conf.setting" DCONF_DB_PATH="/etc/dconf/db/lliurex.d/" DCONF_DB_FILE=DCONF_DB_PATH+CUSTOM_FILE def __init__(self): pass #def init def startup(self,options): self.internal_variable=copy.deepcopy(objects["VariablesManager"].get_variable("PANELDESIGNMANAGER")) if self.internal_variable==None: try: self.initialize_variable() objects["VariablesManager"].add_variable("PANELDESIGNMANAGER",copy.deepcopy(self.internal_variable),"","Panel Design Manager internal variable","n4d-panel-design-manager-server") except Exception as e: print e #def startup def initialize_variable(self): self.internal_variable={} self.internal_variable["status"]=False self.internal_variable["dconf"]=None self.internal_variable["date"]=None self.internal_variable["plank"]=True self.internal_variable["replicate"]=True #def initialize_variable def check_variable(self,variable): try: if not type(variable)==dict: return False if not type(variable["status"])==bool: return False if not type(variable["dconf"])==str: return False if not type(variable["date"])==str: return False if not type(variable["plank"])==bool: return False if not type(variable["replicate"])==bool: return False except: return False return True #def check_variable def save_configuration(self,data): if not self.check_variable(data): return {"status":False,"msg":"Variable does not have the expected structure"} if data["status"]: if data["dconf"]!=self.internal_variable["dconf"] or data["plank"]!=self.internal_variable["plank"] or not self.internal_variable["status"]: self._delete_dconf_file() self._write_dconf_file(data["dconf"],data["plank"]) else: self._delete_dconf_file() self.internal_variable=copy.deepcopy(data) objects["VariablesManager"].set_variable("PANELDESIGNMANAGER",data) return {"status":True,"msg":""} #def save_configuration def get_configuration(self): return {"status":True,"msg":self.internal_variable} #def load_configuration def _delete_dconf_file(self): if os.path.exists(PanelDesignManager.DCONF_DB_FILE): os.remove(PanelDesignManager.DCONF_DB_FILE) os.system("dconf update") #def _remove_dconf_file def _write_dconf_file(self,dconf_content,use_plank=True): dock="" if use_plank: dock="plank" f=open(PanelDesignManager.DCONF_DB_FILE,"w") f.write(dconf_content) f.write(PanelDesignManager.DOCK_SKEL%(dock)) f.close() os.system("dconf update") #def _write_dconf_file