mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-08-02 15:37:49 +00:00
docker: fix python addon (rev 132)
- Retry connection on error - Add periodically kodi termination check via timeout - Remove unneeded thread - Do not import oe
This commit is contained in:
parent
33be452d25
commit
afa2e54219
@ -1,3 +1,6 @@
|
||||
132
|
||||
- Fix python addon
|
||||
|
||||
131
|
||||
- Update to docker 19.03.14
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
PKG_NAME="docker"
|
||||
PKG_VERSION="19.03.14"
|
||||
PKG_SHA256="0b8838b0da1f1368fc1a0809a2ed11840bd7d58df1f090e668de209faddcef7c"
|
||||
PKG_REV="131"
|
||||
PKG_REV="132"
|
||||
PKG_ARCH="any"
|
||||
PKG_LICENSE="ASL"
|
||||
PKG_SITE="http://www.docker.com/"
|
||||
|
@ -5,20 +5,16 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
import xbmcgui
|
||||
|
||||
sys.path.append('/usr/share/kodi/addons/@DISTRO_PKG_SETTINGS_ID@')
|
||||
import oe
|
||||
|
||||
__author__ = 'lrusak'
|
||||
__addon__ = xbmcaddon.Addon()
|
||||
__path__ = __addon__.getAddonInfo('path')
|
||||
|
||||
sys.path.append(__path__ + '/lib')
|
||||
sys.path.append(__path__ + 'lib')
|
||||
import dockermon
|
||||
|
||||
# docker events for api 1.23 (docker version 1.11.x)
|
||||
@ -236,24 +232,11 @@ def print_notification(json_data):
|
||||
try:
|
||||
if message != '':
|
||||
length = int(__addon__.getSetting('notification_length')) * 1000
|
||||
dialog.notification('Docker', message, '/storage/.kodi/addons/service.system.docker/resources/icon.png', length)
|
||||
dialog.notification('Docker', message, __path__ + 'resources/icon.png', length)
|
||||
xbmc.log('## service.system.docker ## %s' % message)
|
||||
except NameError as e:
|
||||
pass
|
||||
|
||||
class dockermonThread(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
self._is_running = True
|
||||
|
||||
def run(self):
|
||||
while self._is_running:
|
||||
dockermon.watch(print_notification)
|
||||
|
||||
def stop(self):
|
||||
self._is_running = False
|
||||
|
||||
class Main(object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -284,8 +267,8 @@ class Main(object):
|
||||
restart_docker = True
|
||||
|
||||
if restart_docker:
|
||||
oe.execute('systemctl enable /storage/.kodi/addons/service.system.docker/system.d/service.system.docker.service')
|
||||
oe.execute('systemctl restart /storage/.kodi/addons/service.system.docker/system.d/service.system.docker.service')
|
||||
subprocess.run(['systemctl','enable','/storage/.kodi/addons/service.system.docker/system.d/service.system.docker.service'], close_fds=True)
|
||||
subprocess.run(['systemctl','restart','service.system.docker.service'], close_fds=True)
|
||||
|
||||
# end temp cleanup
|
||||
#############################
|
||||
@ -293,9 +276,11 @@ class Main(object):
|
||||
monitor = DockerMonitor(self)
|
||||
|
||||
while not monitor.abortRequested():
|
||||
if monitor.waitForAbort():
|
||||
# we don't want to stop or disable docker while it's installed
|
||||
pass
|
||||
try:
|
||||
dockermon.watch(print_notification, run=lambda: not monitor.abortRequested())
|
||||
except Exception:
|
||||
monitor.waitForAbort(1)
|
||||
del monitor
|
||||
|
||||
class DockerMonitor(xbmc.Monitor):
|
||||
|
||||
@ -306,8 +291,6 @@ class DockerMonitor(xbmc.Monitor):
|
||||
pass
|
||||
|
||||
if ( __name__ == "__main__" ):
|
||||
dockermonThread().start()
|
||||
Main()
|
||||
|
||||
del DockerMonitor
|
||||
dockermonThread().stop()
|
||||
del __addon__
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
from contextlib import closing
|
||||
from functools import partial
|
||||
from socket import socket, AF_UNIX
|
||||
from socket import socket, AF_UNIX, timeout
|
||||
from subprocess import Popen, PIPE
|
||||
from sys import stdout, version_info
|
||||
import json
|
||||
@ -70,12 +70,14 @@ def connect(url):
|
||||
return sock, hostname
|
||||
|
||||
|
||||
def watch(callback, url=default_sock_url):
|
||||
def watch(callback, url=default_sock_url, run=None):
|
||||
"""Watch docker events. Will call callback with each new event (dict).
|
||||
|
||||
url can be either tcp://<host>:port or ipc://<path>
|
||||
"""
|
||||
sock, hostname = connect(url)
|
||||
if run:
|
||||
sock.settimeout(1.5)
|
||||
request = 'GET /events HTTP/1.1\nHost: %s\n\n' % hostname
|
||||
request = request.encode('utf-8')
|
||||
|
||||
@ -89,7 +91,13 @@ def watch(callback, url=default_sock_url):
|
||||
# Messages are \r\n<size in hex><JSON payload>\r\n
|
||||
buf = [payload]
|
||||
while True:
|
||||
chunk = sock.recv(bufsize)
|
||||
try:
|
||||
chunk = sock.recv(bufsize)
|
||||
except timeout:
|
||||
if run():
|
||||
continue
|
||||
if run and not run():
|
||||
raise DockermonError('stopped')
|
||||
if not chunk:
|
||||
raise EOFError('socket closed')
|
||||
buf.append(chunk.decode('utf-8'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user