From 08e16666916ac5793ddb483bfe2a4e5efc100029 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 23 Mar 2019 15:51:25 +0100 Subject: [PATCH] Add txtp_maker -O option to rename repeated files --- cli/txtp_maker.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cli/txtp_maker.py b/cli/txtp_maker.py index f970e328..1ef06a98 100644 --- a/cli/txtp_maker.py +++ b/cli/txtp_maker.py @@ -44,6 +44,7 @@ def print_help(appname): " -d (dir): add dir in TXTP (if the file will reside in a subdir)\n" " -m: create mini-txtp\n" " -o: overwrite existing .txtp (beware when using with internal names)\n" + " -O: rename rather than overwritting\n" " -in: name TXTP using the subsong's internal name if found\n" " -ie: remove internal name's extension\n" " -ii: add subsong number when using internal name\n" @@ -112,6 +113,8 @@ class ConfigHelper(object): subdir = '' mini_txtp = False overwrite = False + overwrite_rename = False + rename_map = {} layers = 0 use_internal_name = False @@ -193,6 +196,7 @@ class ConfigHelper(object): self.mini_txtp = self.read_bool('-m', self.mini_txtp) self.overwrite = self.read_bool('-o', self.overwrite) + self.overwrite_rename = self.read_bool('-O', self.overwrite_rename) self.layers = self.read_int('-l', self.layers) self.use_internal_name = self.read_bool('-in', self.use_internal_name) @@ -370,6 +374,15 @@ class TxtpMaker(object): cfg = self.cfg outname += '.txtp' + + if cfg.overwrite_rename and os.path.exists(outname): + if outname in cfg.rename_map: + rename_count = cfg.rename_map[outname] + else: + rename_count = 0 + cfg.rename_map[outname] = rename_count + 1 + outname = outname.replace(".txtp", "_{}.txtp".format(rename_count)) + if not cfg.overwrite and os.path.exists(outname): raise ValueError('TXTP exists in path: ' + outname) ftxtp = open(outname,"w+")