#!/usr/bin/env python import os import threading import tempfile import time class PanelDesignManagerClient: CUSTOM_FILE="99_custom_panel_conf.setting" DCONF_DB_PATH="/etc/dconf/db/lliurex.d/" DCONF_DB_FILE=DCONF_DB_PATH+CUSTOM_FILE DOCK_SKEL="\ [org/mate/desktop/session/required-components]\n\ dock='%s'\n\ windowmanager='marco'\n\ filemanager='caja'\n\n" def __init__(self): pass #def init def startup(self,options): t = threading.Thread(target=self._startup) t.daemon = True t.start() #def startup def _startup(self): try: if objects.has_key("VariablesManager"): objects["VariablesManager"].register_trigger("PANELDESIGNMANAGER","PanelDesignManagerClient",self.design_trigger) self.get_value_and_execute() except Exception as e: print str(e) #def _startup def get_value_and_execute(self): # Making sure we're able to read PANELDESIGNMANAGER var from server tries=10 var=None for x in range(0,tries): var=objects["VariablesManager"].get_variable("PANELDESIGNMANAGER") if var != None: self.design_trigger(var) break else: time.sleep(1) #def get_value def design_trigger(self,data): if data["status"] and data["replicate"]: self._write_dconf_file(data) else: self._delete_dconf_file() #def design_trigger def _write_dconf_file(self,data): content=data["dconf"] dock="" if data["plank"]: dock="plank" content+=PanelDesignManagerClient.DOCK_SKEL%(dock) if os.path.exists(PanelDesignManagerClient.DCONF_DB_FILE): f=open(PanelDesignManagerClient.DCONF_DB_FILE) lines=f.readlines() f.close() current_content="".join(lines) if current_content==content: return True else: self._delete_dconf_file() f=open(PanelDesignManagerClient.DCONF_DB_FILE,"w") f.write(content) f.close() os.system("dconf update") #def _write_dconf_file def _delete_dconf_file(self): if os.path.exists(PanelDesignManagerClient.DCONF_DB_FILE): os.remove(PanelDesignManagerClient.DCONF_DB_FILE) os.system("dconf update") #def _delete_dconf_file