X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=bin%2Frecode_filenames.py;h=7e25a1637f77e6ea266116aec67ede5ae62069f4;hb=7ba9017ba0901c03c5337f8df1c6f30d291e2f81;hp=93b76cb607cef5c9346161a594c1b4014c9a9fb3;hpb=f46bd4d41cc7f243bc8a321effee5200aa69e709;p=dotfiles.git diff --git a/bin/recode_filenames.py b/bin/recode_filenames.py index 93b76cb..7e25a16 100755 --- a/bin/recode_filenames.py +++ b/bin/recode_filenames.py @@ -1,7 +1,6 @@ #! /usr/bin/env python # -*- coding: koi8-r -*- - import sys src_encoding = sys.argv[1] @@ -13,7 +12,7 @@ if src_encoding == "translit": elif dst_encoding == "cp1251": from m_lib.rus.lat2rus import lat2win as _recode else: - raise NotImplementedError, "destination encoding must be koi8-r or cp1251, not `%s'" % dst_encoding + raise NotImplementedError("destination encoding must be koi8-r or cp1251, not `%s'" % dst_encoding) elif dst_encoding == "translit": if src_encoding == "koi8-r": @@ -21,7 +20,7 @@ elif dst_encoding == "translit": elif src_encoding == "cp1251": from m_lib.rus.rus2lat import win2lat as _recode else: - raise NotImplementedError, "source encoding must be koi8-r or cp1251, not `%s'" % src_encoding + raise NotImplementedError("source encoding must be koi8-r or cp1251, not `%s'" % src_encoding) from m_lib.rus.rus2lat import koi2lat_d koi2lat_d["ΓΏ"] = '' # remove apostrophs - @@ -38,7 +37,7 @@ elif src_encoding == "url": import urllib def _recode(s): s = urllib.unquote(s) - if src_encoding <> dst_encoding: + if src_encoding != dst_encoding: s = recode(s, src_encoding, dst_encoding, "replace") return s @@ -50,7 +49,7 @@ elif dst_encoding == "url": from m_lib.opstring import recode import urllib def _recode(s): - if src_encoding <> dst_encoding: + if src_encoding != dst_encoding: s = recode(s, src_encoding, dst_encoding, "replace") return urllib.quote(s, safe=";/?:@&=+$,()'") # wget treats them as safe @@ -64,5 +63,5 @@ if __name__ == "__main__": import os for filename in sys.argv[3:]: new_name = _recode(filename) - if new_name <> filename: + if new_name != filename: os.rename(filename, new_name)