From 180adcbbe46d480f835c3ec736a209df85123705 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sun, 25 May 2025 11:29:34 -0700 Subject: [PATCH 1/4] Nudge version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a84d995..71b83cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mfbatch" -version = "0.5.2" +version = "0.6.0" description = "MetaFlac batch editor" authors = ["Jamie Hardt "] readme = "README.md" From cb10eec36ac240141397fbb9c96cd5267d55ebf8 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sun, 25 May 2025 12:18:15 -0700 Subject: [PATCH 2/4] implemented rename --- mfbatch/commands.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/mfbatch/commands.py b/mfbatch/commands.py index 1f1b8e6..745fa4e 100644 --- a/mfbatch/commands.py +++ b/mfbatch/commands.py @@ -192,13 +192,25 @@ they appear in the batchfile. def _handle_comment(self, _): pass - def _write_metadata_impl(self, line): + def _write_metadata_and_rename_impl(self, line): if self.dry_run: print("DRY RUN would write metadata here.", file=self.outstream) else: self.outstream.write("Writing metadata... ") self.write_metadata_f(line, self.env.metadatums) - self.outstream.write("Complete!") + self.outstream.write("Complete!\n") + + if '_NEW_BASENAME' in self.env.metadatums: + self.outstream.write("Attempting to rename... ") + new_name = os.path.basename(line) + \ + self.env.metadatums['_NEW_BASENAME'] + + if not os.path.exists(new_name): + os.rename(line, new_name) + self.outstream.write('File renamed!\n') + else: + self.outstream.write('File by new name already exists, ' + 'rename was not performed.\n') self.env.increment_all() self.env.revert_onces() @@ -234,10 +246,16 @@ they appear in the batchfile. self._print_kv_columnar(key, value) + if '_NEW_BASENAME' in self.env.metadatums: + print("") + msg = "File will be renamed:" + print( + f"{msg:.<30} \033[4m{self.env.metadatums['_NEW_BASENAME']}\033[0m\n") + if interactive: val = input('Write? [Y/n/a/:] > ') if val == '' or val[0].upper() == 'Y': - self._write_metadata_impl(line) + self._write_metadata_and_rename_impl(line) break if val.startswith(self.COMMAND_LEADER): self._handle_command(val.lstrip(self.COMMAND_LEADER), @@ -246,7 +264,7 @@ they appear in the batchfile. print("Aborting write session...", file=sys.stdout) break else: - self._write_metadata_impl(line) + self._write_metadata_and_rename_impl(line) break def set(self, args): @@ -322,6 +340,17 @@ they appear in the batchfile. repl = args[3] self.env.set_pattern(key, inp, pattern, repl) + def rename(self, args): + """ + rename NEW-BASENAME + Renames the next file to NEW-BASENAME. The existing file is renamed + while keeping it in the same directory by appending the dirname and + NEW-BASENAME and performing an mv(1). Renaming occurs after metadata + writing. If a file with NEW-BASENAME already exists in the directory, + the action will not be performed. + """ + self.env.set_once('_NEW_BASENAME', args[0]) + def d(self, args): """ d VALUE From 33fd0597cd758c048bd18dab35edf7894b4af682 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Mon, 26 May 2025 12:10:22 -0700 Subject: [PATCH 3/4] Rename tested and addressed bugs --- mfbatch/commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mfbatch/commands.py b/mfbatch/commands.py index 745fa4e..fd5db9c 100644 --- a/mfbatch/commands.py +++ b/mfbatch/commands.py @@ -114,6 +114,9 @@ class CommandEnv: del self.metadatums['_ABSPATH'] del self.metadatums['_FILENAME'] del self.metadatums['_FOLDER'] + + if '_NEW_BASENAME' in self.metadatums: + del self.metadatums['_NEW_BASENAME'] def revert_onces(self): """ @@ -195,6 +198,9 @@ they appear in the batchfile. def _write_metadata_and_rename_impl(self, line): if self.dry_run: print("DRY RUN would write metadata here.", file=self.outstream) + + if '_NEW_BASENAME' in self.env.metadatums: + self.outstream.write('DRY RUN would rename file here.\n') else: self.outstream.write("Writing metadata... ") self.write_metadata_f(line, self.env.metadatums) @@ -202,8 +208,9 @@ they appear in the batchfile. if '_NEW_BASENAME' in self.env.metadatums: self.outstream.write("Attempting to rename... ") - new_name = os.path.basename(line) + \ - self.env.metadatums['_NEW_BASENAME'] + full_old_path = os.path.abspath(line) + new_name = os.path.join(os.path.dirname(full_old_path), + self.env.metadatums['_NEW_BASENAME']) if not os.path.exists(new_name): os.rename(line, new_name) @@ -359,6 +366,7 @@ they appear in the batchfile. val = args[0] self.env.set_once('DESCRIPTION', val) + # def picture(self, args): # """ # picture PATH From 4241d3a4e807ab60738878cf7048a5807a88f47c Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Mon, 26 May 2025 12:11:24 -0700 Subject: [PATCH 4/4] autopep --- mfbatch/commands.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mfbatch/commands.py b/mfbatch/commands.py index fd5db9c..605efff 100644 --- a/mfbatch/commands.py +++ b/mfbatch/commands.py @@ -114,7 +114,7 @@ class CommandEnv: del self.metadatums['_ABSPATH'] del self.metadatums['_FILENAME'] del self.metadatums['_FOLDER'] - + if '_NEW_BASENAME' in self.metadatums: del self.metadatums['_NEW_BASENAME'] @@ -198,7 +198,7 @@ they appear in the batchfile. def _write_metadata_and_rename_impl(self, line): if self.dry_run: print("DRY RUN would write metadata here.", file=self.outstream) - + if '_NEW_BASENAME' in self.env.metadatums: self.outstream.write('DRY RUN would rename file here.\n') else: @@ -210,7 +210,7 @@ they appear in the batchfile. self.outstream.write("Attempting to rename... ") full_old_path = os.path.abspath(line) new_name = os.path.join(os.path.dirname(full_old_path), - self.env.metadatums['_NEW_BASENAME']) + self.env.metadatums['_NEW_BASENAME']) if not os.path.exists(new_name): os.rename(line, new_name) @@ -366,7 +366,6 @@ they appear in the batchfile. val = args[0] self.env.set_once('DESCRIPTION', val) - # def picture(self, args): # """ # picture PATH