From 370b05b5d682dffb13cf018d5bf8174bfbce0dfb Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 19 Feb 2024 23:11:34 +0300 Subject: [PATCH] Feat(recode-filenames-recursive): Allow to omit parameters --- bin/recode-filenames-recursive.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/recode-filenames-recursive.py b/bin/recode-filenames-recursive.py index b7787e4..5408563 100755 --- a/bin/recode-filenames-recursive.py +++ b/bin/recode-filenames-recursive.py @@ -1,14 +1,34 @@ #! /usr/bin/env python3 import sys, os -from recode_filenames import _recode -if len(sys.argv) == 3: +from m_lib.defenc import default_encoding + +if len(sys.argv) == 1: + src_encoding = default_encoding + if src_encoding == 'utf-8': + sys.exit("Usage: %s [[src_enc] dst_enc [start_dir]]" % sys.argv[0]) + else: + dst_encoding = 'utf-8' + start_dir = '.' +elif len(sys.argv) == 2: + src_encoding = default_encoding + dst_encoding = sys.argv[1] start_dir = '.' +elif len(sys.argv) == 3: + src_encoding = default_encoding + dst_encoding = sys.argv[1] + start_dir = sys.argv[2] elif len(sys.argv) == 4: + src_encoding = sys.argv[1] + dst_encoding = sys.argv[2] start_dir = sys.argv[3] else: - sys.exit("Usage: %s src_enc dst_enc [start_dir]" % sys.argv[0]) + sys.exit("Usage: %s [[src_enc] dst_enc [start_dir]]" % sys.argv[0]) + +# Fake for recode_filenames.py +sys.argv = ['', src_encoding, dst_encoding] +from recode_filenames import _recode def _onerror(exc): -- 2.39.5