Mercurial > ec-dotfiles
comparison bin/recompress @ 98:9be628347dce
Worst thing about unix: it allows control character and newline in its filename. Added handler to ensure that shit doesn't pass through. Makes things slow but it can't be helped (tm).
| author | Edho Prima Arief <edho@myconan.net> |
|---|---|
| date | Thu, 14 Jul 2011 01:11:18 +0700 |
| parents | a5324d2cc0eb |
| children | 97e24e89388f |
comparison
equal
deleted
inserted
replaced
| 97:65ce115fd21d | 98:9be628347dce |
|---|---|
| 19 while outbyte > 1000: | 19 while outbyte > 1000: |
| 20 outbyte /= 1000 | 20 outbyte /= 1000 |
| 21 current_unit += 1 | 21 current_unit += 1 |
| 22 return "%.2f %s" % (outbyte, units[current_unit]) | 22 return "%.2f %s" % (outbyte, units[current_unit]) |
| 23 | 23 |
| 24 def sane_fn(filename): | |
| 25 import re | |
| 26 return re.sub(r"[\x00-\x1F\x7F\n\r]", "?", filename) | |
| 27 | |
| 24 if __name__ == "__main__": | 28 if __name__ == "__main__": |
| 25 for filename in sys.argv[1:]: | 29 for filename in sys.argv[1:]: |
| 26 print "Recompressing %s:" % filename, | 30 print "Recompressing %s:" % sane_fn(filename), |
| 27 sys.stdout.flush() | 31 sys.stdout.flush() |
| 28 try: | 32 try: |
| 29 byte_orig = os.path.getsize(filename) | 33 byte_orig = os.path.getsize(filename) |
| 30 repng(filename) | 34 repng(filename) |
| 31 byte_new = os.path.getsize(filename) | 35 byte_new = os.path.getsize(filename) |
