mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +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.
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pony.orm import db_session, ObjectNotFound
|
from pony.orm import db_session, ObjectNotFound
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
from subprocess import Popen, DEVNULL
|
from subprocess import Popen
|
||||||
from threading import Thread, Event, RLock
|
from threading import Thread, Event, RLock
|
||||||
|
|
||||||
from .db import Track
|
from .db import Track
|
||||||
@ -27,6 +28,8 @@ class Jukebox(object):
|
|||||||
self.__playlist = []
|
self.__playlist = []
|
||||||
self.__index = 0
|
self.__index = 0
|
||||||
|
|
||||||
|
self.__devnull = None
|
||||||
|
|
||||||
self.__thread = None
|
self.__thread = None
|
||||||
self.__lock = RLock()
|
self.__lock = RLock()
|
||||||
self.__skip = Event()
|
self.__skip = Event()
|
||||||
@ -39,6 +42,18 @@ class Jukebox(object):
|
|||||||
gain = property(lambda self: 1.0)
|
gain = property(lambda self: 1.0)
|
||||||
playlist = property(lambda self: list(self.__playlist))
|
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):
|
def set(self, tracks):
|
||||||
self.clear()
|
self.clear()
|
||||||
self.add(tracks)
|
self.add(tracks)
|
||||||
@ -126,6 +141,7 @@ class Jukebox(object):
|
|||||||
|
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
self._close_devnull()
|
||||||
|
|
||||||
def __play_file(self):
|
def __play_file(self):
|
||||||
path = self.__playlist[self.__index]
|
path = self.__playlist[self.__index]
|
||||||
@ -133,7 +149,12 @@ class Jukebox(object):
|
|||||||
|
|
||||||
logger.debug("Start playing with command %s", args)
|
logger.debug("Start playing with command %s", args)
|
||||||
try:
|
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:
|
except:
|
||||||
logger.exception("Failed running play command")
|
logger.exception("Failed running play command")
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user