]> git.phdru.name Git - dotfiles.git/blobdiff - bin/iconvx.py
Feat(recode-filenames-recursive): Allow to omit parameters
[dotfiles.git] / bin / iconvx.py
index 9352e73bd5f2e6829f8a162028ba06a7a379de0c..b4c990e1aeee6e1c93dd4339ec52cbb5e035b14c 100755 (executable)
@@ -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))