1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix for python 2.7

This commit is contained in:
Alban Féron 2019-09-07 17:01:04 +02:00
parent 4e69cd0551
commit 9de96bb530
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -8,12 +8,13 @@
# Distributed under terms of the GNU AGPLv3 license.
import logging
import os
import shlex
import time
from pony.orm import db_session, ObjectNotFound
from random import shuffle
from subprocess import Popen, DEVNULL
from subprocess import Popen
from threading import Thread, Event, RLock
from .db import Track
@ -27,6 +28,8 @@ class Jukebox(object):
self.__playlist = []
self.__index = 0
self.__devnull = None
self.__thread = None
self.__lock = RLock()
self.__skip = Event()
@ -39,6 +42,18 @@ class Jukebox(object):
gain = property(lambda self: 1.0)
playlist = property(lambda self: list(self.__playlist))
# subprocess.DEVNULL doesn't exist on Python 2.7
def _get_devnull(self):
if self.__devnull is None:
self.__devnull = os.open(os.devnull, os.O_RDWR)
return self.__devnull
def _close_devnull(self):
if self.__devnull is None:
return
os.close(self.__devnull)
self.__devnull = None
def set(self, tracks):
self.clear()
self.add(tracks)
@ -126,6 +141,7 @@ class Jukebox(object):
proc.terminate()
proc.wait()
self._close_devnull()
def __play_file(self):
path = self.__playlist[self.__index]
@ -133,7 +149,12 @@ class Jukebox(object):
logger.debug("Start playing with command %s", args)
try:
return Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
return Popen(
args,
stdin=self._get_devnull(),
stdout=self._get_devnull(),
stderr=self._get_devnull(),
)
except:
logger.exception("Failed running play command")
return None