OSDN Git Service

record used files infomation to index.
authorhylom <hylom@users.sourceforge.jp>
Mon, 6 Apr 2009 11:55:32 +0000 (20:55 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 6 Apr 2009 11:55:32 +0000 (20:55 +0900)
markupper.py
markupper_test.py

index dd87617..81a824c 100755 (executable)
@@ -36,9 +36,9 @@ class Markupper(object):
     """
     """
     def __init__(self):
-        self.input_iter = None
-        self.index_past = {}
-        self.index = {}
+        self._input_iter = None
+        self._index_past = {}
+        self._index = {}
 
     def index_add(self, key, val):
         """
@@ -50,7 +50,13 @@ class Markupper(object):
         @param val:
         @key val:
         """
-        self.index[key] = val
+        self._index[key] = val
+
+    def index(self, key):
+        """
+        Get index
+        """
+        return self._index[key]
 
     def markup(self, input_iter):
         """
@@ -65,6 +71,8 @@ class Markupper(object):
         # dlist = ["*"]
         # tag_filter = HTMLTagFilter.HTMLTagFilter(HTMLTagFilter.DENY_ALLOW, alist, dlist)
 
+        self.index_add("figs", [])
+
         anchor = ""
         for line in self.input_iter:
             line = self._default_markup_rule(line)
@@ -144,7 +152,7 @@ class Markupper(object):
         # load index
         try:
             index_file = open(path_to_index, "r")
-            self.index_past = pickle.load(index_file)
+            self._index_past = pickle.load(index_file)
             index_file.close()
         except IOError:
             sys.stderr.write("warn: cannot read index file,\n")
@@ -159,7 +167,7 @@ class Markupper(object):
         # save index
         try:
             index_file = open(path_to_index, "w")
-            pickle.dump(self.index, index_file)
+            pickle.dump(self._index, index_file)
             index_file.close()
         except IOError:
             sys.stderr.write("warn: cannot write index file,\n")
@@ -316,25 +324,36 @@ class Markupper(object):
         print self._fig_start()
 
         line = self.input_iter.next()
+        imgname = ""
+        imgname_s = ""
         hash = ""
         hash_s = ""
         match_o1 = re.search(ur"<([^,]*?)>", line)
         match_o2 = re.search(ur"<(.*?),\s*(.*?)>", line)
         if not match_o1 == None:
+            imgname = match_o1.group(1)
             imgname_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", match_o1.group(1))
-            hash = self.hashlist.get(match_o1.group(1), "")
-            hash_s = self.hashlist.get(imgname_s, "")
-            if hash_s == "":
-                hash_s = self.hashlist.get(match_o1.group(1), "")
         elif not match_o2 == None:
-            hash = self.hashlist.get(match_o2.group(1), "")
-            hash_s = self.hashlist.get(match_o2.group(2), "")
+            imgname = match_o1.group(1)
+            imgname_s = match_o1.group(2)
+
+
+        hash = self.hashlist.get(imgname, "")
+        hash_s = self.hashlist.get(imgname_s, "")
+        if hash_s == "":
+            hash_s = hash
 
         print """<a href="/blob.pl?id=%s">
     <slash type="image" id="%s" title="%s">
     </a>
     """ % (hash, hash_s, str_title)
 
+
+        dic = self.index("figs")
+        dic.append(imgname)
+        if imgname_s != "":
+            dic.append(imgname_s)
+
         print self._fig_end(str_title);
 
 
@@ -352,7 +371,7 @@ class Markupper(object):
             str_title = re.search(ur"^☆(表.*)$", line).group(1)
         except AttributeError:
             str_title = ""
-        print _self.table_start(str_title)
+        print self._table_start(str_title)
 
         num_row = 0
         table_contents = []
@@ -360,7 +379,7 @@ class Markupper(object):
             line = line.strip(" \n")
             if re.search(ur"^\s*$", line):
                 break
-            line = default_markup_rule(line)
+            line = self._default_markup_rule(line)
             if re.search(ur"^〓", line):
                 line = re.sub(ur"^〓", "", line)
                 tag_mode = "th"
index 4b8e9c7..dfb210f 100755 (executable)
@@ -5,6 +5,9 @@ import sys
 import os
 import codecs
 
+rootpath = r"C:\Users\hirom\bin\otptools"
+sys.path.insert(0, rootpath)
+
 import markupper