Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port pulseaudio_dlna to python3.8 and fix issues #404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

python ?= python2.7
python ?= python3.8
user ?= $(shell whoami)

all: pulseaudio_dlna.egg-info
Expand Down
6 changes: 3 additions & 3 deletions pulseaudio_dlna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import os
import pkg_resources

import utils.git
from .utils import git

try:
version = pkg_resources.get_distribution(__package__).version
Expand All @@ -30,7 +30,7 @@
if os.environ.get('USE_PKG_VERSION', None) == '1':
branch, rev = None, None
else:
branch, rev = utils.git.get_head_version()
branch, rev = git.get_head_version()

__version__ = '{version}{rev}'.format(
version=version,
Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
'''


from __future__ import unicode_literals


import sys
import os
Expand Down
18 changes: 9 additions & 9 deletions pulseaudio_dlna/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import multiprocessing
import signal
Expand Down Expand Up @@ -157,11 +157,11 @@ def run(self, options):
SSDPDiscover.MSEARCH_PORT = int(msearch_port)

if options['--create-device-config']:
self.create_device_config()
self.create_device_config(host=host)
sys.exit(0)

if options['--update-device-config']:
self.create_device_config(update=True)
self.create_device_config(update=True, host=host)
sys.exit(0)

device_config = None
Expand Down Expand Up @@ -213,7 +213,7 @@ def run(self, options):
logger.info(' {}'.format(encoder))

logger.info('Codec settings:')
for identifier, _type in pulseaudio_dlna.codecs.CODECS.iteritems():
for identifier, _type in pulseaudio_dlna.codecs.CODECS.items():
codec = _type()
logger.info(' {}'.format(codec))

Expand Down Expand Up @@ -291,10 +291,10 @@ def run(self, options):
signal.signal(signal.SIGHUP, self.shutdown)
signal.pause()

def create_device_config(self, update=False):
def create_device_config(self, update=False, host=None):
logger.info('Starting discovery ...')
holder = pulseaudio_dlna.holder.Holder(plugins=self.PLUGINS)
holder.search(ttl=5)
holder.search(ttl=20, host=host)
logger.info('Discovery complete.')

def device_filter(obj):
Expand Down Expand Up @@ -331,9 +331,9 @@ def obj_to_dict(obj):
continue
try:
with open(config_file, 'w') as h:
h.write(json_text.encode(self.ENCODING))
h.write(json_text)
logger.info('Found the following devices:')
for device in holder.devices.values():
for device in list(holder.devices.values()):
logger.info('{name} ({flavour})'.format(
name=device.name, flavour=device.flavour))
for codec in device.codecs:
Expand All @@ -356,7 +356,7 @@ def read_device_config(self):
if os.path.isfile(config_file) and \
os.access(config_file, os.R_OK):
with open(config_file, 'r') as h:
json_text = h.read().decode(self.ENCODING)
json_text = h.read()
logger.debug('Device configuration:\n{}'.format(json_text))
json_text = json_text.replace('\n', '')
try:
Expand Down
8 changes: 4 additions & 4 deletions pulseaudio_dlna/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import functools
import logging
Expand Down Expand Up @@ -67,7 +67,7 @@ def set_backend(backend):
def set_codecs(identifiers):
step = 3
priority = (len(CODECS) + 1) * step
for identifier, _type in CODECS.iteritems():
for identifier, _type in CODECS.items():
_type.ENABLED = False
_type.PRIORITY = 0
for identifier in identifiers:
Expand All @@ -81,7 +81,7 @@ def set_codecs(identifiers):

def enabled_codecs():
codecs = []
for identifier, _type in CODECS.iteritems():
for identifier, _type in CODECS.items():
if _type.ENABLED:
codecs.append(_type())
return codecs
Expand Down Expand Up @@ -168,7 +168,7 @@ def __str__(self, detailed=False):
def to_json(self):
attributes = ['priority', 'suffix', 'mime_type']
d = {
k: v for k, v in self.__dict__.iteritems()
k: v for k, v in self.__dict__.items()
if k not in attributes
}
d['mime_type'] = self.specific_mime_type
Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/covermodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import sys
import inspect
Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


from gi.repository import GObject

Expand Down
19 changes: 8 additions & 11 deletions pulseaudio_dlna/encoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import distutils.spawn
import inspect
Expand Down Expand Up @@ -66,10 +66,7 @@ def _find_executable(path):
# The distutils module uses python's ascii default encoding and is
# therefore not capable of handling unicode properly when it contains
# non-ascii characters.
encoding = 'utf-8'
result = distutils.spawn.find_executable(path.encode(encoding))
if result is not None and type(result) is str:
result = result.decode(encoding)
result = distutils.spawn.find_executable(path)
return result


Expand Down Expand Up @@ -113,7 +110,7 @@ def supported_bit_rates(self):
def __str__(self):
return '<{} available="{}">'.format(
self.__class__.__name__,
unicode(self.available),
str(self.available),
)


Expand All @@ -139,8 +136,8 @@ def supported_bit_rates(self):
def __str__(self):
return '<{} available="{}" bit-rate="{}">'.format(
self.__class__.__name__,
unicode(self.available),
unicode(self.bit_rate),
str(self.available),
str(self.bit_rate),
)


Expand All @@ -165,9 +162,9 @@ def channels(self, value):
def __str__(self):
return '<{} available="{}" sample-rate="{}" channels="{}">'.format(
self.__class__.__name__,
unicode(self.available),
unicode(self.sample_rate),
unicode(self.channels),
str(self.available),
str(self.sample_rate),
str(self.channels),
)


Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/encoders/avconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import logging

Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/encoders/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import logging

Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/encoders/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import logging

Expand Down
4 changes: 2 additions & 2 deletions pulseaudio_dlna/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import logging
import threading
Expand Down Expand Up @@ -96,7 +96,7 @@ def lookup(self, locations):
'Connection refused.'.format(url=url))

for plugin in self.plugins:
for url, xml in xmls.items():
for url, xml in list(xmls.items()):
device = plugin.lookup(url, xml)
self.add_device(device)

Expand Down
4 changes: 2 additions & 2 deletions pulseaudio_dlna/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals
from __future__ import with_statement



import tempfile
import logging
Expand Down
2 changes: 1 addition & 1 deletion pulseaudio_dlna/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import logging

Expand Down
1 change: 0 additions & 1 deletion pulseaudio_dlna/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import functools

Expand Down
1 change: 0 additions & 1 deletion pulseaudio_dlna/plugins/chromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import logging

Expand Down
3 changes: 1 addition & 2 deletions pulseaudio_dlna/plugins/chromecast/mdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from gi.repository import GObject

Expand Down Expand Up @@ -66,6 +65,7 @@ def run(self, ttl=None):
self.__running = True
self.__mainloop = GObject.MainLoop()
context = self.__mainloop.get_context()
logger.info('MDNSListener.run()')
try:
while self.__running:
if context.pending():
Expand All @@ -75,7 +75,6 @@ def run(self, ttl=None):
except KeyboardInterrupt:
pass
self.zeroconf.close()
logger.info('MDNSListener.run()')

def shutdown(self):
logger.info('MDNSListener.shutdown()')
Expand Down
6 changes: 3 additions & 3 deletions pulseaudio_dlna/plugins/chromecast/pycastv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with pulseaudio-dlna. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


import time
import logging

import commands
import cast_socket
from . import commands
from . import cast_socket

logger = logging.getLogger('pycastv2')

Expand Down
Loading