import pickle import os import shutil class Configuration_Manager: def __init__(self): self.cfg_file="../rsrc/arturito.cfg" self.joy_name=None self.list_triggers=[] self.grid_counter=None #def __init__ def load_cfg_file(self): file=open(self.cfg_file, 'rb') cfg=pickle.load(file) file.close() self.joy_name=cfg.joy_name self.list_triggers=cfg.list_triggers self.grid_counter=cfg.grid_counter #def load_cnf_file def write_cfg_file(self): output = open(self.cfg_file+".tmp", 'wb') pickle.dump(self, output, -1) output.close() shutil.copy(self.cfg_file+".tmp",self.cfg_file) os.remove(self.cfg_file+".tmp") #def write_cfg_file def print_variables(self): print "" print ("#Joy [%s]"%self.joy_name) print ("#Trigger list %s"%self.list_triggers) print ("#Grid Counter [%s]"%self.grid_counter) print "" #def print_variables def update_variables(self,name,list): self.joy_name=name self.list_triggers=list self.write_cfg_file() # def update_variables #class Configuration_Manager if __name__=="__main__": print "# DEBUG #" cfg=Configuration_Manager() cfg.load_cfg_file() #cfg.write_cfg_file() cfg.print_variables()