mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-09 19:52:16 +00:00
Fix for python 2.7
This commit is contained in:
parent
4e69cd0551
commit
9de96bb530
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user