1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 BOARD_DATA_INVALID_VALUE = 0
30 def merge_new_thread(oldlist, newlist, id, title, res):
31 num = len(newlist) + 1
33 item = oldlist.pop(id)
39 newlist[id] = {"num": num, "title": title,
40 "res": res, "lineCount": BOARD_DATA_INVALID_VALUE,
43 def merge_cached_thread(oldlist, newlist):
44 for id, value in oldlist.iteritems():
45 if value["lineCount"] != BOARD_DATA_INVALID_VALUE:
46 value["num"] = BOARD_DATA_INVALID_VALUE
47 value["res"] = BOARD_DATA_INVALID_VALUE
50 def merge_local_subjecttxt(bbs, board, datalist):
51 oldlist = datalist.copy()
54 h = lambda id,title,res: merge_new_thread(oldlist,datalist,id,title,res)
55 subjecttxtfile.load_subjecttxt(bbs, board, h)
56 merge_cached_thread(oldlist, datalist)
58 def merge_subjecttxt(subjecttxt, datalist):
59 oldlist = datalist.copy()
62 h = lambda id,title,res: merge_new_thread(oldlist,datalist,id,title,res)
63 subjecttxtfile.analyze_subjecttxt(subjecttxt, h)
64 merge_cached_thread(oldlist, datalist)
66 def load_idxfiles(bbs, board):
69 def on_load_record(id, metadata_dic):
70 idxfile_path = misc.get_thread_idx_path(bbs, board, id)
71 if os.path.exists(idxfile_path):
72 datalist[id] = metadata_dic
75 cachefile.load_cache(bbs, board, on_load_record)
77 load_modified_idxfiles(bbs, board, datalist)
79 cachefile.save_cache(bbs, board, datalist)
83 def load_modified_idxfiles(bbs, board, datalist):
84 basedir = misc.get_thread_idx_dir_path(bbs, board)
85 if os.path.isdir(basedir):
86 for idxfile_path in glob.glob(os.path.join(basedir, "*.idx")):
87 thread_id, ext = os.path.splitext(os.path.basename(idxfile_path))
88 idxlastModified = os.path.getmtime(idxfile_path)
89 if thread_id not in datalist:
91 dic = idxfile.load_idx(bbs, board, thread_id)
93 dic["idxlastModified"] = idxlastModified
94 datalist[thread_id] = dic
95 elif idxlastModified > datalist[thread_id]["idxlastModified"]:
97 datalist[thread_id]["idxlastModified"] = idxlastModified
98 dic = idxfile.load_idx(bbs, board, thread_id)
99 for name in idxfile.metadata_namelist:
100 datalist[thread_id][name] = dic[name]
103 class LoadLocal(threading.Thread):
104 def __init__(self, bbs, board, on_end):
105 super(LoadLocal, self).__init__()
111 datalist = load_idxfiles(self.bbs, self.board)
112 merge_local_subjecttxt(self.bbs, self.board, datalist)
113 lastmod = subjecttxtfile.load_board_idx(self.bbs, self.board)
114 gobject.idle_add(self.on_end, datalist, lastmod)
117 class GetRemote(threading.Thread):
118 def __init__(self, bbs, board, uri, on_end):
119 super(GetRemote, self).__init__()
126 print "start get subject.txt"
127 subjecttxt, lastmod = subjecttxtfile.get_subjecttxt(
128 self.bbs, self.board, self.uri)
129 datalist = load_idxfiles(self.bbs, self.board)
130 merge_subjecttxt(subjecttxt, datalist)
131 gobject.idle_add(self.on_end, datalist, lastmod)