X-Git-Url: https://git.phdru.name/?p=dotfiles.git;a=blobdiff_plain;f=bin%2Ficonvx.py;h=d3c20d10ecff2ee0e5ceaec72e2943cc8ee5b782;hp=9352e73bd5f2e6829f8a162028ba06a7a379de0c;hb=HEAD;hpb=c5883d2a782366c0a3468a989e756cf37dabbd46 diff --git a/bin/iconvx.py b/bin/iconvx.py index 9352e73..b4c990e 100755 --- a/bin/iconvx.py +++ b/bin/iconvx.py @@ -1,37 +1,38 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 "iconv wrapper" -import sys from getopt import getopt +import os, shutil, sys, tempfile options, arguments = getopt(sys.argv[1:], 'f:t:') from_charset = to_charset = None for option, value in options: - if option == '-f': - from_charset = value - elif option == '-t': - to_charset = value + if option == '-f': + from_charset = value + elif option == '-t': + to_charset = value if from_charset is None: - raise ValueError, "you must use -f param to name source charset" + raise ValueError("you must use -f param to name source charset") if to_charset is None: - raise ValueError, "you must use -t param to name destination charset" + raise ValueError("you must use -t param to name destination charset") -import tempfile, os, shutil tempfname = "_iconvx" + tempfile.gettempprefix() + "tmp" if arguments: - try: - for file in arguments: - os.system("iconv.py -f '%s' -t '%s' '%s' > '%s'" % (from_charset, to_charset, file, tempfname)) + try: + for file in arguments: + os.system( + "iconv.py -f '%s' -t '%s' '%s' > '%s'" % ( + from_charset, to_charset, file, tempfname)) shutil.copy2(tempfname, file) - finally: - os.unlink(tempfname) + finally: + os.unlink(tempfname) -else: # filter stdin => stdout - os.system("iconv.py -f '%s' -t '%s'" % (from_charset, to_charset)) +else: # filter stdin => stdout + os.system("iconv.py -f '%s' -t '%s'" % (from_charset, to_charset))