comparison src/tools/memory.py @ 417:f1bf8b6143b7

core: removed former save_data method
author Goffi <goffi@goffi.org>
date Tue, 01 Nov 2011 23:04:48 +0100
parents 32dc8b18c2ae
children 199cf4ebcc74
comparison
equal deleted inserted replaced
416:32dc8b18c2ae 417:f1bf8b6143b7
103 def save_xml(self, file): 103 def save_xml(self, file):
104 """Save parameters template to xml file""" 104 """Save parameters template to xml file"""
105 with open(file, 'wb') as xml_file: 105 with open(file, 'wb') as xml_file:
106 xml_file.write(self.dom.toxml('utf-8')) 106 xml_file.write(self.dom.toxml('utf-8'))
107 107
108 def save_data(self, file):
109 """Save parameters data to file"""
110 #TODO: save properly in a separate file/database,
111 # use different behaviour depending of the data type (e.g. password encrypted)
112
113 #general params
114 with open(file+'_gen', 'w') as param_gen_pickle:
115 pickle.dump(self.params_gen, param_gen_pickle)
116
117 #then individual params
118 with open(file+'_ind', 'w') as param_ind_pickle:
119 pickle.dump(self.params, param_ind_pickle)
120
121 def __init__(self, host, storage): 108 def __init__(self, host, storage):
122 debug("Parameters init") 109 debug("Parameters init")
123 self.host = host 110 self.host = host
124 self.storage = storage 111 self.storage = storage
125 self.default_profile = None 112 self.default_profile = None
432 categories.append(cat.getAttribute("name")) 419 categories.append(cat.getAttribute("name"))
433 return categories 420 return categories
434 421
435 def setParam(self, name, value, category, profile_key='@NONE@'): 422 def setParam(self, name, value, category, profile_key='@NONE@'):
436 """Set a parameter, return None if the parameter is not in param xml""" 423 """Set a parameter, return None if the parameter is not in param xml"""
424 #TODO: use different behaviour depending of the data type (e.g. password encrypted)
437 if profile_key!="@NONE@": 425 if profile_key!="@NONE@":
438 profile = self.getProfileName(profile_key) 426 profile = self.getProfileName(profile_key)
439 if not profile: 427 if not profile:
440 error(_('Trying to set parameter for an unknown profile')) 428 error(_('Trying to set parameter for an unknown profile'))
441 return #TODO: throw an error 429 return #TODO: throw an error
588 self.host.get_const('savefile_history')) 576 self.host.get_const('savefile_history'))
589 private_file = os.path.expanduser(self.getConfig('','local_dir')+ 577 private_file = os.path.expanduser(self.getConfig('','local_dir')+
590 self.host.get_const('savefile_private')) 578 self.host.get_const('savefile_private'))
591 579
592 self.params.save_xml(param_file_xml) 580 self.params.save_xml(param_file_xml)
593 self.params.save_data(param_file_data)
594 debug(_("params saved")) 581 debug(_("params saved"))
595 with open(history_file, 'w') as history_pickle: 582 with open(history_file, 'w') as history_pickle:
596 pickle.dump(self.history, history_pickle) 583 pickle.dump(self.history, history_pickle)
597 debug(_("history saved")) 584 debug(_("history saved"))
598 with open(private_file, 'w') as private_pickle: 585 with open(private_file, 'w') as private_pickle: