OSDN Git Service

add exception routine in A tag convertion.
[otptools/otptools.git] / otp_imgswap.py
index 0a2d72b..5bfad97 100755 (executable)
@@ -53,10 +53,12 @@ for line in in_f:
     if match:
         tagstr = match.group(0)
         path = match.group(1)
-        if os.path.isfile(path):
-            md5 = get_md5(path)
+        try:
+            if os.path.isfile(path):
+                md5 = get_md5(path)
             # tag has alt ?
-            slashtag = """<A HREF="/blob.pl?id=%s">""" % (md5,)
-            line = line.replace(tagstr, slashtag)
-    
+                slashtag = """<A HREF="/blob.pl?id=%s">""" % (md5,)
+                line = line.replace(tagstr, slashtag)
+        except UnicodeEncodeError:
+            print >> sys.stderr, "invalid path: %s (%s)" % (path.encode("utf-8"), line.strip().encode("utf-8"))
     print >> out_f, line,