Changeset 35 for storage

Show
Ignore:
Timestamp:
07/10/06 16:22:28 (2 years ago)
Author:
ploum
Message:

You can now import a bookmark file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • storage/bookmarks_store.py

    r34 r35  
    3434                self.listing.connect("row-deleted", deleted_callback) 
    3535                if os.path.exists(self.bmark_file) : 
    36                         f = open(self.bmark_file,mode='r') 
    37                         # sanitize the pretty XML 
    38                         stringed = f.read().replace('\n','').replace('\t','') 
    39                         doc = xml.dom.minidom.parseString(stringed) 
    40                         for bmark in doc.getElementsByTagName("bookmark") : 
    41                                 title = bmark.getAttribute("title") 
    42                                 self.listing.insert_before(None, [title, bmark.toxml()]) 
     36                        if self.import_file(self.bmark_file) == 0 : 
     37                                print "Bookmarks not in a valid format." 
     38                                print "Please remove the %s file" %self.bmark_file 
    4339                else : 
    4440                        doc = xml.dom.minidom.Document() 
     
    5147                        f.write(doc.toxml().encode("utf-8")) 
    5248                        f.close() 
     49         
     50        def import_file(self,zefile) : 
     51                #programmation défensive needed ici !!! 
     52                # !!!!!!!! 
     53                f = open(zefile,mode='r') 
     54                # sanitize the pretty XML 
     55                stringed = f.read().replace('\n','').replace('\t','') 
     56                try : 
     57                        doc = xml.dom.minidom.parseString(stringed) 
     58                except : 
     59                        return 0 
     60                for bmark in doc.getElementsByTagName("bookmark") : 
     61                        title = bmark.getAttribute("title") 
     62                        self.listing.insert_before(None, [title, bmark.toxml()]) 
     63                return 1 
    5364 
    5465