# HG changeset patch # User Edho Prima Arief # Date 1310578749 -25200 # Node ID 4f954c1e2fdcf1d12261fd0485b5de6e797f8373 # Parent 03b02463cc16e192419f0fb2240d29b9b5bac2b0 Stop being pretentious and only return 0 or 1 in case of success or failure. Everything else is handled by exception handler. diff -r 03b02463cc16 -r 4f954c1e2fdc bin/recompress --- 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