Skip to content

Commit

Permalink
Add command-line option to delete file when conversion is done
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehenry committed Dec 18, 2021
1 parent 8c305c3 commit 5bede27
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bin/soundconverter
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ def run(self):
],
cmdclass={
'install': Install
}
},
scripts=["bin/soundconverter"]
)
2 changes: 1 addition & 1 deletion soundconverter/interface/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/testcases/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
20 changes: 20 additions & 0 deletions tests/testcases/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 5bede27

Please sign in to comment.