- Timestamp:
- 07/09/06 14:53:14 (2 years ago)
- Files:
-
- 1 modified
-
storage/bookmarks_store.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
storage/bookmarks_store.py
r31 r32 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 import sys, string, xml.dom.minidom 3 import sys, string, xml.dom.minidom, os 4 4 try: 5 5 import gtk … … 8 8 sys.exit(1) 9 9 10 bmark_file="bookmarks.xml" 11 10 12 # this class represent the whole bookmarks list 11 13 class bookmarks_store : … … 13 15 # differents bookmarks for differents protocols. 14 16 def __init__(self, bts_name) : 15 #listing is : Title of the bookmarks, number of the search method, argumentsof the search17 #listing is : Title of the bookmarks, description of the search 16 18 # search method : 17 19 # 1- bug number … … 19 21 # 3- package search 20 22 # 4- advanced search 21 self.listing = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_INT, gobject.TYPE_STRING) 22 # essai temporaire 23 # normalement ici on lit le fichier de préférences 24 self.listing.insert_before(None, ["Evo 2 results", 2, "<?xml version=\"1.0\" ?>\n<bookmark title=\"(evolution) imap filter\" type=\"3\"><search>imap filter</search><product>evolution</product></bookmark>"]) 25 self.listing.insert_before(None, ["many results", 2, "<?xml version=\"1.0\" ?>\n<bookmark title=\"microsoft has majority\" type=\"2\"><search>microsoft has majority</search></bookmark>"]) 26 self.listing.insert_before(None, ["Evo's bugs", 3, "<?xml version=\"1.0\" ?>\n<bookmark title=\"(evolution)\" type=\"3\"><product>evolution</product></bookmark>"]) 27 self.listing.insert_before(None, ["Bug #42", 1, "<?xml version=\"1.0\" ?>\n<bookmark title=\"bug #42\" type=\"1\"><bug>42</bug></bookmark>"]) 28 self.listing.insert_before(None, ["Content in +text mode", 1, "<?xml version=\"1.0\" ?>\n<bookmark title=\"bug #51835\" type=\"1\"><bug>51835</bug></bookmark>"]) 29 self.listing.insert_before(None, ["Search in bugs+text", 1, "<?xml version=\"1.0\" ?>\n<bookmark title=\"bug #51836\" type=\"1\"><bug>51836</bug></bookmark>"]) 23 self.listing = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 24 if os.path.exists(bmark_file) : 25 doc = xml.dom.minidom.parse(bmark_file) 26 for bmark in doc.getElementsByTagName("bookmark") : 27 title = bmark.getAttribute("title") 28 self.listing.insert_before(None, [title, bmark.toxml()]) 29 else : 30 doc = xml.dom.minidom.Document() 31 store = doc.createElement("store") 32 doc.appendChild(store) 33 #here we can put hardcoded default 34 # 35 #then we create the file 36 f = open(bmark_file, mode='a+') 37 f.write(doc.toprettyxml()) 38 f.close() 30 39 31 40 … … 33 42 return self.listing 34 43 35 def add(self, title,searchMethod,args) :44 def add(self,args) : 36 45 #TODO : do not forget to also add the bookmarks to 37 46 #the stored bookmarks. (sync with storage) 38 self.listing.insert_before(None, [title, searchMethod, args]) 47 doc2 = xml.dom.minidom.parseString(args) 48 bmark = doc2.getElementsByTagName("bookmark")[0] 49 title = bmark.getAttribute("title") 50 self.listing.insert_before(None, [title, args]) 51 self.sync_file() 39 52 40 53 def delete(self, to_delete) : … … 42 55 #the stored bookmarks. (sync with storage) 43 56 self.listing.remove(to_delete) 57 self.sync_file() 58 59 def sync_file(self) : 60 doc = xml.dom.minidom.Document() 61 store = doc.createElement("store") 62 doc.appendChild(store) 63 for i in self.listing : 64 doc2 = xml.dom.minidom.parseString(i[1]) 65 bmark = doc2.getElementsByTagName("bookmark")[0] 66 store.appendChild(bmark) 67 #it's maybe not optimal to open/close the file each time we sync 68 # but I'm not sure that those operations are so frequent 69 # might be changed in the future. 70 f = open(bmark_file, mode='w+') 71 f.write(doc.toprettyxml()) 72 f.close() 73 44 74 45 75 # this is a lonely bookmark in the store … … 52 82 title = '' 53 83 zetuple = path.get_selection().get_selected() 54 method = zetuple[0].get_value(zetuple[1],1)55 string = zetuple[0].get_value(zetuple[1], 2)84 #method = zetuple[0].get_value(zetuple[1],1) 85 string = zetuple[0].get_value(zetuple[1],1) 56 86 doc2 = xml.dom.minidom.parseString(string) 57 87 bmark = doc2.getElementsByTagName("bookmark")[0] 58 #method = int(bmark.getAttribute("type"))88 method = int(bmark.getAttribute("type")) 59 89 if method == 1: 60 90 # besoin de programmation défensive ici FIXME … … 73 103 else : 74 104 search = s_element[0].childNodes[0].nodeValue 75 self.bug = bug105 self.bug = str(bug) 76 106 self.method = method 77 107 self.search = search 78 108 self.product = product 79 self.title = zetuple[0].get_value(zetuple[1],0)109 self.title = bmark.getAttribute("title") 80 110 81 111 def get_method(self) :
