Skip to content

Commit a0e10f9

Browse files
committed
Merge branch 'master' into feature/album-art
2 parents be4776c + 8cbb441 commit a0e10f9

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

mopidy_mpd/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class Extension(ext.Extension):
11-
1211
dist_name = "Mopidy-MPD"
1312
ext_name = "mpd"
1413
version = __version__

mopidy_mpd/network.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
CONTROL_CHARS = dict.fromkeys(range(32))
1616

1717

18+
def get_systemd_socket():
19+
"""Attempt to get a socket from systemd."""
20+
fdnames = os.environ.get("LISTEN_FDNAMES", "").split(":")
21+
if "mpd" not in fdnames:
22+
return None
23+
fd = fdnames.index("mpd") + 3 # 3 is the first systemd file handle
24+
return socket.socket(fileno=fd)
25+
26+
1827
def get_unix_socket_path(socket_path):
1928
match = re.search("^unix:(.*)", socket_path)
2029
if not match:
@@ -37,7 +46,7 @@ def get_socket_address(host, port):
3746
return (host, port)
3847

3948

40-
class ShouldRetrySocketCall(Exception):
49+
class ShouldRetrySocketCallError(Exception):
4150

4251
"""Indicate that attempted socket call should be retried"""
4352

@@ -122,6 +131,10 @@ def __init__(
122131
self.watcher = self.register_server_socket(self.server_socket.fileno())
123132

124133
def create_server_socket(self, host, port):
134+
sock = get_systemd_socket()
135+
if sock is not None:
136+
return sock
137+
125138
socket_path = get_unix_socket_path(host)
126139
if socket_path is not None: # host is a path so use unix socket
127140
sock = create_unix_socket()
@@ -157,7 +170,7 @@ def register_server_socket(self, fileno):
157170
def handle_connection(self, fd, flags):
158171
try:
159172
sock, addr = self.accept_connection()
160-
except ShouldRetrySocketCall:
173+
except ShouldRetrySocketCallError:
161174
return True
162175

163176
if self.maximum_connections_exceeded():
@@ -174,7 +187,7 @@ def accept_connection(self):
174187
return sock, addr
175188
except OSError as e:
176189
if e.errno in (errno.EAGAIN, errno.EINTR):
177-
raise ShouldRetrySocketCall
190+
raise ShouldRetrySocketCallError
178191
raise
179192

180193
def maximum_connections_exceeded(self):

mopidy_mpd/protocol/current_playlist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def delete(context, songrange):
9393
tl_tracks = context.core.tracklist.slice(start, end).get()
9494
if not tl_tracks:
9595
raise exceptions.MpdArgError("Bad song index", command="delete")
96-
for (tlid, _) in tl_tracks:
96+
for tlid, _ in tl_tracks:
9797
context.core.tracklist.remove({"tlid": [tlid]})
9898

9999

@@ -325,7 +325,7 @@ def plchangesposid(context, version):
325325
# XXX Naive implementation that returns all tracks as changed
326326
if int(version) != context.core.tracklist.get_version().get():
327327
result = []
328-
for (position, (tlid, _)) in enumerate(
328+
for position, (tlid, _) in enumerate(
329329
context.core.tracklist.get_tl_tracks().get()
330330
):
331331
result.append(("cpos", position))

tests/dummy_audio.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def __init__(self, config=None, mixer=None):
2121
self.state = audio.PlaybackState.STOPPED
2222
self._volume = 0
2323
self._position = 0
24-
self._callback = None
24+
self._source_setup_callback = None
25+
self._about_to_finish_callback = None
2526
self._uri = None
2627
self._stream_changed = False
2728
self._live_stream = False
@@ -58,6 +59,7 @@ def pause_playback(self):
5859

5960
def prepare_change(self):
6061
self._uri = None
62+
self._source_setup_callback = None
6163
return True
6264

6365
def stop_playback(self):
@@ -76,8 +78,11 @@ def set_metadata(self, track):
7678
def get_current_tags(self):
7779
return self._tags
7880

81+
def set_source_setup_callback(self, callback):
82+
self._source_setup_callback = callback
83+
7984
def set_about_to_finish_callback(self, callback):
80-
self._callback = callback
85+
self._about_to_finish_callback = callback
8186

8287
def enable_sync_handler(self):
8388
pass
@@ -93,13 +98,13 @@ def _change_state(self, new_state):
9398
self._stream_changed = True
9499
self._uri = None
95100

96-
if self._uri is not None:
97-
audio.AudioListener.send("position_changed", position=0)
98-
99101
if self._stream_changed:
100102
self._stream_changed = False
101103
audio.AudioListener.send("stream_changed", uri=self._uri)
102104

105+
if self._uri is not None:
106+
audio.AudioListener.send("position_changed", position=0)
107+
103108
old_state, self.state = self.state, new_state
104109
audio.AudioListener.send(
105110
"state_changed",
@@ -121,14 +126,22 @@ def trigger_fake_tags_changed(self, tags):
121126
self._tags.update(tags)
122127
audio.AudioListener.send("tags_changed", tags=self._tags.keys())
123128

129+
def get_source_setup_callback(self):
130+
# This needs to be called from outside the actor or we lock up.
131+
def wrapper():
132+
if self._source_setup_callback:
133+
self._source_setup_callback()
134+
135+
return wrapper
136+
124137
def get_about_to_finish_callback(self):
125138
# This needs to be called from outside the actor or we lock up.
126139
def wrapper():
127-
if self._callback:
140+
if self._about_to_finish_callback:
128141
self.prepare_change()
129-
self._callback()
142+
self._about_to_finish_callback()
130143

131-
if not self._uri or not self._callback:
144+
if not self._uri or not self._about_to_finish_callback:
132145
self._tags = {}
133146
audio.AudioListener.send("reached_end_of_stream")
134147
else:

tests/network/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_accept_connection_recoverable_error(self):
250250

251251
for error in (errno.EAGAIN, errno.EINTR):
252252
sock.accept.side_effect = socket.error(error, "")
253-
with self.assertRaises(network.ShouldRetrySocketCall):
253+
with self.assertRaises(network.ShouldRetrySocketCallError):
254254
network.Server.accept_connection(self.mock)
255255

256256
# FIXME decide if this should be allowed to propegate

tests/protocol/test_regression.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def test(self):
169169

170170

171171
class IssueGH113RegressionTest(protocol.BaseTestCase):
172-
173172
r"""
174173
The issue: https://github.com/mopidy/mopidy/issues/113
175174

0 commit comments

Comments
 (0)