OSDN Git Service

Move ThreadInvoker and FileWrap to misc.py
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 4 Sep 2006 01:21:35 +0000 (10:21 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 4 Sep 2006 01:21:35 +0000 (10:21 +0900)
src/FukuiNoNamari/misc.py
src/FukuiNoNamari/thread_window.py

index 0382536..0ece770 100644 (file)
@@ -18,6 +18,7 @@
 import os.path
 import re
 import time
+import threading
 
 import config
 
@@ -192,3 +193,39 @@ def httpdate_to_secs(httpdate):
             - time.timezone)
     else:
         raise ValueError
+
+
+class ThreadInvoker(threading.Thread):
+    def __init__(self, on_end, *methods):
+        super(ThreadInvoker, self).__init__()
+        self.on_end = on_end
+        self.methods = methods
+    def run(self):
+        try:
+            for m in self.methods:
+                m()
+        finally:
+            self.on_end()
+
+
+class FileWrap:
+    def __init__(self, path):
+        self._file = None
+        self._path = path
+    def __del__(self):
+        self.close()
+    def seek(self, size):
+        self.file().seek(size)
+    def write(self, data):
+        self.file().write(data)
+    def close(self):
+        if self._file:
+            self._file.close()
+            self._file = None
+    def file(self):
+        if not self._file:
+            basedir = os.path.dirname(self._path)
+            if not os.path.isdir(basedir):
+                os.makedirs(basedir)
+            self._file = file(self._path, "a+")
+        return self._file
index e31c2e3..41728ac 100644 (file)
@@ -32,6 +32,7 @@ import gconf
 import traceback
 
 import misc
+from misc import FileWrap, ThreadInvoker
 import datfile
 import barehtmlparser
 import idxfile
@@ -72,42 +73,6 @@ def open_thread(uri, update=False):
     winwrap.jump_to_res(bbs_type.uri)
 
 
-class ThreadInvoker(threading.Thread):
-    def __init__(self, on_end, *methods):
-        super(ThreadInvoker, self).__init__()
-        self.on_end = on_end
-        self.methods = methods
-    def run(self):
-        try:
-            for m in self.methods:
-                m()
-        finally:
-            self.on_end()
-
-
-class FileWrap:
-    def __init__(self, path):
-        self._file = None
-        self._path = path
-    def __del__(self):
-        self.close()
-    def seek(self, size):
-        self.file().seek(size)
-    def write(self, data):
-        self.file().write(data)
-    def close(self):
-        if self._file:
-            self._file.close()
-            self._file = None
-    def file(self):
-        if not self._file:
-            basedir = os.path.dirname(self._path)
-            if not os.path.isdir(basedir):
-                os.makedirs(basedir)
-            self._file = file(self._path, "a+")
-        return self._file
-
-
 class WinWrap(winwrapbase.WinWrapBase):
     hovering_over_link = False
     hand_cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)