Changeset 62 for management.py

Show
Ignore:
Timestamp:
03/26/07 08:49:51 (22 months ago)
Author:
ploum
Message:

#73 - account.xml file empty

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • management.py

    r60 r62  
    1919                        f = open(self.accounts_file,mode='r') 
    2020                        if self.open_file(f) == 0 : 
    21                                 print "Accounts not in a valid format." 
    22                                 print "Please remove the %s file" %self.accounts_file    
     21                                self.account_error()     
    2322                        f.close()                
    2423                else : 
     
    3332                        f.close() 
    3433                         
     34        def account_error(self) : 
     35                message = "Accounts are not in a valid format. \n Please remove the %s file and restart Conseil" %self.accounts_file 
     36                #error_window = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_CLOSE, message_format=message) 
     37                #error_window.show() 
     38                print message 
     39                         
    3540        def open_file(self,f) : 
    3641                #programmation défensive needed ici !!! 
     
    4146                        self.doc = xml.dom.minidom.parseString(stringed) 
    4247                except : 
     48                        return 0 
     49                if self.doc.hasChildNodes() and self.doc.firstChild.nodeName == "store" : 
     50                        if not self.doc.firstChild.hasChildNodes() : 
     51                                self.add_account() 
     52                else : 
    4353                        return 0 
    4454                self.read_value() 
     
    5161                self.open_file(self.f) 
    5262                self.update_display() 
     63                self.f.close() 
    5364                 
    5465 
     
    5667                self.widget.hide() 
    5768                self.sync() 
    58                 self.f.close() 
     69                 
    5970                 
    6071        def sync(self) : 
     72                self.f = open(self.accounts_file, mode='w') 
    6173                self.f.write(self.doc.toprettyxml().encode("utf-8")) 
     74                self.f.close() 
    6275                 
    6376        def read_value(self) : 
     
    132145                new.appendChild(self.doc.createTextNode(value)) 
    133146                self.account.replaceChild(new,old) 
     147                self.sync() 
    134148                 
    135149        def get_url(self) :