changeset 93:4f954c1e2fdc

Stop being pretentious and only return 0 or 1 in case of success or failure. Everything else is handled by exception handler.
author Edho Prima Arief <edho@myconan.net>
date Thu, 14 Jul 2011 00:39:09 +0700
parents 03b02463cc16
children 9790bc126ea6
files bin/recompress
diffstat 1 files changed, 7 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/bin/recompress	Thu Jul 14 00:34:46 2011 +0700
+++ b/bin/recompress	Thu Jul 14 00:39:09 2011 +0700
@@ -11,16 +11,10 @@
 # 3 = not a png file
 def repng(filename):
   retcode = 0
-  try:
-    im = Image.open(filename)
-    if im.format == "PNG":
-      try:
-        im.save(filename, optimize=1)
-      except:
-        retcode = 3
-    else:
-      retcode = 2
-  except:
+  im = Image.open(filename)
+  if im.format == "PNG":
+    im.save(filename, optimize=1)
+  else:
     retcode = 1
   return retcode
 
@@ -44,14 +38,10 @@
         byte_new = os.path.getsize(filename)
         print "OK (%s => %s, %.2f%% saving)" % (hbytes(byte_orig), hbytes(byte_new), (byte_orig - byte_new)*100/float(byte_orig)),
       elif re == 1:
-        print "Not an image or corrupt file",
-      elif re == 2:
-        print "No write permission",
-      elif re == 3:
-        print "Not a PNG file",
+        print "Not a PNG image file",
     except:
-      print "(%s: %s)" % (sys.exc_type, sys.exc_value)
-      print "Not a file or no read permission",
+      print "Failed",
+      print "(%s: %s)" % (sys.exc_type, sys.exc_value),
       re = 1
     print "[%s]" % re