mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 21:42:48 +01:00
Refactor util/interactive_open: multiple targets
interactive_open should now be invoked with at least the list of targets and optionally the command to open the targets with. This allows beets-play to pass multiple file paths directly to the configured command. The changes to the existing invocations are pretty trivial in order to comply to this refactor.
This commit is contained in:
parent
4eb563a08c
commit
9c663432bd
4 changed files with 14 additions and 14 deletions
|
|
@ -1485,7 +1485,7 @@ def config_edit():
|
|||
try:
|
||||
if not os.path.isfile(path):
|
||||
open(path, 'w+').close()
|
||||
util.interactive_open(path, editor)
|
||||
util.interactive_open([path], editor)
|
||||
except OSError as exc:
|
||||
message = "Could not edit configuration: {0}".format(exc)
|
||||
if not editor:
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ def open_anything():
|
|||
return base_cmd
|
||||
|
||||
|
||||
def interactive_open(target=None, command=None, multiple_targets=[]):
|
||||
def interactive_open(targets, command=None):
|
||||
"""Open the file `target` by `exec`ing a new command. (The new
|
||||
program takes over, and Python execution ends: this does not fork a
|
||||
subprocess.)
|
||||
|
|
@ -756,8 +756,7 @@ def interactive_open(target=None, command=None, multiple_targets=[]):
|
|||
else:
|
||||
base_cmd = open_anything()
|
||||
command = [base_cmd, base_cmd]
|
||||
if multiple_targets:
|
||||
command = command + multiple_targets
|
||||
else:
|
||||
command.append(target)
|
||||
|
||||
command += targets
|
||||
|
||||
return os.execlp(*command)
|
||||
|
|
|
|||
|
|
@ -119,19 +119,20 @@ class PlayPlugin(BeetsPlugin):
|
|||
if raw:
|
||||
passed_to_command = paths
|
||||
else:
|
||||
passed_to_command, m3u = self._create_tmp_playlist(paths)
|
||||
passed_to_command = self._create_tmp_playlist(paths)
|
||||
|
||||
self._log.debug('executing command: {} {}', command_str,
|
||||
passed_to_command)
|
||||
b'"' + b' '.join(passed_to_command) + b'"')
|
||||
try:
|
||||
util.interactive_open(multiple_targets=passed_to_command,
|
||||
command=command_str)
|
||||
util.interactive_open(passed_to_command, command_str)
|
||||
except OSError as exc:
|
||||
raise ui.UserError("Could not play the music playlist: "
|
||||
"{0}".format(exc))
|
||||
finally:
|
||||
if not raw:
|
||||
util.remove(m3u.name)
|
||||
self._log.debug('Removing temporary playlist: {}',
|
||||
passed_to_command[0])
|
||||
util.remove(passed_to_command[0])
|
||||
|
||||
def _create_tmp_playlist(self, paths_list):
|
||||
# Create temporary m3u file to hold our playlist.
|
||||
|
|
@ -139,4 +140,4 @@ class PlayPlugin(BeetsPlugin):
|
|||
for item in paths_list:
|
||||
m3u.write(item + b'\n')
|
||||
m3u.close()
|
||||
return [m3u.name], m3u
|
||||
return [m3u.name]
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ class UtilTest(unittest.TestCase):
|
|||
@patch('beets.util.open_anything')
|
||||
def test_interactive_open(self, mock_open, mock_execlp):
|
||||
mock_open.return_value = 'tagada'
|
||||
util.interactive_open('foo')
|
||||
util.interactive_open(['foo'])
|
||||
mock_execlp.assert_called_once_with('tagada', 'tagada', 'foo')
|
||||
mock_execlp.reset_mock()
|
||||
|
||||
util.interactive_open('foo', 'bar')
|
||||
util.interactive_open(['foo'], 'bar')
|
||||
mock_execlp.assert_called_once_with('bar', 'bar', 'foo')
|
||||
|
||||
def test_sanitize_unix_replaces_leading_dot(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue