OSDN Git Service

add wp_imgswap2.py for new OSDN Magazine
[otptools/otptools.git] / otp_imgswap.py
index 0a2d72b..87d5c1a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/env python
+#!/usr/bin/env python
 # -*- encoding: utf-8 -*-
 #
 # otp_imgswap.py : otp image tag swapper
@@ -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,