From 5bede27d1e7c303da8036919e851c75de93ccc63 Mon Sep 17 00:00:00 2001 From: Christophe Henry Date: Thu, 16 Dec 2021 12:57:59 +0100 Subject: [PATCH] Add command-line option to delete file when conversion is done --- bin/soundconverter | 4 ++++ setup.py | 3 ++- soundconverter/interface/batch.py | 2 +- tests/testcases/batch.py | 13 +++++++++++++ tests/testcases/integration.py | 20 ++++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/bin/soundconverter b/bin/soundconverter index 9e9df74..60293ed 100644 --- a/bin/soundconverter +++ b/bin/soundconverter @@ -144,6 +144,10 @@ def parse_command_line(): '-j', '--jobs', action='store', type='int', dest='forced-jobs', metavar='NUM', help=_('Force number of concurrent conversions.') ) + parser.add_option( + '-D', '--delete-original', action='store_true', dest='delete-original', + help=_('Deletes the original file when conversion is done.') + ) # batch mode settings batch_option_group = OptionGroup( diff --git a/setup.py b/setup.py index e1d8a57..5f98132 100644 --- a/setup.py +++ b/setup.py @@ -64,5 +64,6 @@ def run(self): ], cmdclass={ 'install': Install - } + }, + scripts=["bin/soundconverter"] ) diff --git a/soundconverter/interface/batch.py b/soundconverter/interface/batch.py index d33191b..2857906 100644 --- a/soundconverter/interface/batch.py +++ b/soundconverter/interface/batch.py @@ -64,7 +64,7 @@ def use_memory_gsettings(options): gio_settings = Gio.Settings.new_with_backend('org.soundconverter', backend) set_gio_settings(gio_settings) - gio_settings.set_boolean('delete-original', False) + gio_settings.set_boolean('delete-original', options.get('delete-original', False)) if options.get('main') == 'batch': # the number of jobs is only applied, when limit-jobs is true diff --git a/tests/testcases/batch.py b/tests/testcases/batch.py index e01a8d7..dc648e6 100644 --- a/tests/testcases/batch.py +++ b/tests/testcases/batch.py @@ -336,6 +336,19 @@ def test_set_delete_original_false(self): gio_settings = get_gio_settings() self.assertFalse(gio_settings.get_boolean('delete-original')) + def test_set_delete_original_true(self): + gio_settings = get_gio_settings() + gio_settings.set_boolean('delete-original', False) + use_memory_gsettings({ + 'output-path': '.', + 'main': 'batch', + 'format': 'ogg', + 'quality': '0.5', + 'delete-original': True + }) + gio_settings = get_gio_settings() + self.assertTrue(gio_settings.get_boolean('delete-original')) + if __name__ == "__main__": unittest.main() diff --git a/tests/testcases/integration.py b/tests/testcases/integration.py index ec0de63..1faa918 100644 --- a/tests/testcases/integration.py +++ b/tests/testcases/integration.py @@ -432,6 +432,26 @@ def test_set_delete_original_false(self): gio_settings = get_gio_settings() self.assertFalse(gio_settings.get_boolean('delete-original')) + def test_set_delete_original_true(self): + gio_settings = get_gio_settings() + gio_settings.set_boolean('delete-original', False) + gio_settings = get_gio_settings() + self.assertFalse(gio_settings.get_boolean('delete-original')) + + os.system('cp "tests/test data/audio/a.wav" "tests/tmp/a.wav"') + self.assertTrue(os.path.isfile('tests/tmp/a.wav')) + + launch([ + '-b', 'tests/tmp/a.wav', + '-o', 'tests/tmp', + '-f', 'm4a', + '-D', + ]) + + gio_settings = get_gio_settings() + self.assertTrue(gio_settings.get_boolean('delete-original')) + self.assertFalse(os.path.isfile('tests/tmp/a.wav')) + def test_conversion_no_tags(self): launch([ '-b', 'tests/test data/no tags',