OSDN Git Service

Not load idx files when update, and convert lastModified before merging subject.txt.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 24 Sep 2006 19:21:11 +0000 (04:21 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 24 Sep 2006 19:21:11 +0000 (04:21 +0900)
src/FukuiNoNamari/board_data.py
src/FukuiNoNamari/board_window.py

index 8edd30c..20d1395 100644 (file)
@@ -86,7 +86,7 @@ class BoardData:
         else:
             datalist[id] = {"id": id, "num": num, "title": title,
                             "res": res, "lineCount": BOARD_DATA_INVALID_VALUE,
-                            "lastModified": "", "average": average}
+                            "lastModified": 0, "average": average}
 
     def merge_local_subjecttxt(self, datalist):
         iterable = self._load_subjecttxt()
@@ -119,6 +119,17 @@ class BoardData:
                     gtk.threads_leave()
             yield fraction
 
+    def _modify_dict(self, item_dict):
+        # lastModified, httpdate to second
+        httpdate = item_dict["lastModified"]
+        try:
+            secs = misc.httpdate_to_secs(httpdate)
+        except ValueError:
+            item_dict["lastModified"] = 0
+        else:
+            item_dict["lastModified"] = secs
+        return item_dict
+
     def load_idxfiles(self):
         print "load_cache"
         try:
@@ -133,6 +144,11 @@ class BoardData:
         except IOError:
             traceback.print_exc()
 
+        # adjustment after cache save, before load subject.txt
+        iterable = datalist.itervalues()
+        iterable = itertools.imap(self._modify_dict, iterable)
+        for i in iterable: -1
+
         status = "Complete index files."
         gobject.idle_add(self.set_status, status)
         return datalist
@@ -344,7 +360,7 @@ class BoardData:
             iterable_len = itertools.imap(lambda l: len(l), iterable_len)
             iterable_len = accumulate(iterable_len)
             iterable_len = itertools.imap(
-                lambda value: float(value) / total / 2 + 0.5, iterable_len)
+                lambda value: float(value) / total, iterable_len)
             iterable_len = self._progressing(iterable_len)
 
             # union
index 820ca08..2e5eef6 100644 (file)
@@ -173,17 +173,6 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
 
     def load(self, update=False):
 
-        def modify_dict(item_dict):
-            # lastModified, httpdate to second
-            httpdate = item_dict["lastModified"]
-            try:
-                secs = misc.httpdate_to_secs(httpdate)
-            except ValueError:
-                item_dict["lastModified"] = 0
-            else:
-                item_dict["lastModified"] = secs
-            return item_dict
-
         def set_id(thread_id, item_dict):
             item_dict["id"] = thread_id
             return item_dict
@@ -192,7 +181,6 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
             key_iter = dictdict.iterkeys()
             value_iter = dictdict.itervalues()
             iterable = itertools.imap(set_id, key_iter, value_iter)
-            iterable = itertools.imap(modify_dict, iterable)
             return [item_dict for item_dict in iterable]
 
         def load_local():
@@ -201,9 +189,8 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
             new_list = conv_dictdict_to_listdict(datalist)
             gobject.idle_add(self.update_datastore, new_list)
 
-        def get_remote():
+        def get_remote(datalist):
             print "start get subject.txt"
-            datalist = self.load_idxfiles()
             self.merge_remote_subjecttxt(datalist)
             new_list = conv_dictdict_to_listdict(datalist)
             gobject.idle_add(self.update_datastore, new_list)
@@ -214,13 +201,36 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
                 self.progress.hide()
             gobject.idle_add(reset_progress)
 
+        def deep_copy():
+            def init_some(dic):
+                dic["num"] = 0
+                dic["res"] = 0
+                dic["average"] = 0
+                return dic
+
+            model = self.treeview.get_model()
+            if model:
+                iterable = model.original_list
+
+                # unmerge subject.txt
+                iterable = itertools.ifilter(
+                    lambda dic: dic["lineCount"] > 0, iterable)
+                iterable = itertools.imap(lambda dic: dic.copy(), iterable)
+                iterable = itertools.imap(init_some, iterable)
+
+                new_dict = dict([(dic["id"], dic) for dic in iterable])
+            else:
+                new_dict = {}
+            return new_dict
+
         sbj_path = misc.get_board_subjecttxt_path(self.bbs_type)
         sbj_exists = os.path.exists(sbj_path)
 
         self.progress.show()
 
         if update or not sbj_exists:
-            t = ThreadInvoker(on_end, get_remote)
+            new_dict = deep_copy()
+            t = ThreadInvoker(on_end, lambda *x: get_remote(new_dict))
             t.start()
         else:
             t = ThreadInvoker(on_end, load_local)