Skip to content

Commit

Permalink
revert busaddress patch and limit the number of districa call to solv…
Browse files Browse the repository at this point in the history
…e infinite loop, ported the web interface
  • Loading branch information
pat1 committed Sep 27, 2021
1 parent 1122a2b commit 30015c4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
3 changes: 1 addition & 2 deletions autoplayergui
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ class Main(object):

#Connect to player
DBusGMainLoop(set_as_default=True)
#uris = get_players_uri(pattern=".",busaddress=busaddress)
uris = list(get_players_uri(pattern="."))
uris = list(get_players_uri(pattern=".",busaddress=busaddress))

if len(uris) >0 :
uri=uris[0]
Expand Down
2 changes: 1 addition & 1 deletion autoradio/autompris2.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self,player="AutoPlayer",session=0, busaddress=settings.busaddressp

DBusGMainLoop(set_as_default=True)

uris = get_players_uri(pattern=".*"+player+"$",busaddress=busaddress)
uris = list(get_players_uri(pattern=".*"+player+"$",busaddress=busaddress))

if len(uris) >0 :
uri=uris[0]
Expand Down
14 changes: 11 additions & 3 deletions autoradio/autoradio_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ class schedules(list):
"""
multiple schedule object
"""

def __init__(self, *args, **kwargs):
super(schedules, self).__init__(*args, **kwargs)
self.districatimes=0


def districa(self):
'''
english:
Expand All @@ -159,7 +163,9 @@ def districa(self):
logging.debug("execute districa")

needrecompute=False

recomputedtimes=0
self.districatimes += 0

#Spots
#v=0
for v,schedulej in enumerate(self):
Expand Down Expand Up @@ -436,7 +442,9 @@ def get_all_refine(self,now=None,genfile=True):

self.get_all(now,genfile)
while self.districa():
pass
if (self.districatimes >= 20 ):
logging.error("districa do not converge: too many programs in few time")
break
self.purge()
self.sort()

Expand Down
13 changes: 9 additions & 4 deletions autoradio/mpris2/decorator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ def _match_uri(name, pattern='.+'):
'''
return re.match(pattern, name)

def get_session():

def get_session(busaddress=None):
'''
@return: dbus.SessionBus.get_session()
'''
return dbus.SessionBus.get_session()

def get_uri(pattern='.'):
if busaddress is None:
return dbus.SessionBus.get_session()
else:
return dbus.bus.BusConnection(busaddress)

def get_uri(pattern='.',busaddress=None):
'''
Return string of player bus name
@param pattern=None: string RegEx that filter response
@return: array string of players bus name
'''
for item in get_session().list_names():
for item in get_session(busaddress).list_names():
if _match_uri(item, pattern):
yield item

Expand Down
4 changes: 2 additions & 2 deletions autoradio/mpris2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from .decorator.utils import list_interfaces as _list_interfaces
from .decorator.utils import implements as _implements

def get_players_uri(pattern=''):
def get_players_uri(pattern='',busaddress=None):
'''
Return string of player bus name
@param pattern=None: string RegEx that filter response
@return: array string of players bus name
'''
return get_uri(Interfaces.MEDIA_PLAYER + '.*' + pattern)
return get_uri(Interfaces.MEDIA_PLAYER + '.*' + pattern,busaddress)


def get_player_id_from_uri(uri):
Expand Down

0 comments on commit 30015c4

Please sign in to comment.