Merge pull request #4797 from mglae/le10_docker_python_fix

docker: fix python addon (rev 132)
This commit is contained in:
CvH 2021-01-11 18:13:08 +01:00 committed by GitHub
commit 36e5928677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 31 deletions

View File

@ -1,3 +1,6 @@
132
- Fix python addon
131 131
- Update to docker 19.03.14 - Update to docker 19.03.14

View File

@ -5,7 +5,7 @@
PKG_NAME="docker" PKG_NAME="docker"
PKG_VERSION="19.03.14" PKG_VERSION="19.03.14"
PKG_SHA256="0b8838b0da1f1368fc1a0809a2ed11840bd7d58df1f090e668de209faddcef7c" PKG_SHA256="0b8838b0da1f1368fc1a0809a2ed11840bd7d58df1f090e668de209faddcef7c"
PKG_REV="131" PKG_REV="132"
PKG_ARCH="any" PKG_ARCH="any"
PKG_LICENSE="ASL" PKG_LICENSE="ASL"
PKG_SITE="http://www.docker.com/" PKG_SITE="http://www.docker.com/"

View File

@ -5,20 +5,16 @@
import os import os
import subprocess import subprocess
import sys import sys
import threading
import time import time
import xbmc import xbmc
import xbmcaddon import xbmcaddon
import xbmcgui import xbmcgui
sys.path.append('/usr/share/kodi/addons/@DISTRO_PKG_SETTINGS_ID@')
import oe
__author__ = 'lrusak' __author__ = 'lrusak'
__addon__ = xbmcaddon.Addon() __addon__ = xbmcaddon.Addon()
__path__ = __addon__.getAddonInfo('path') __path__ = __addon__.getAddonInfo('path')
sys.path.append(__path__ + '/lib') sys.path.append(__path__ + 'lib')
import dockermon import dockermon
# docker events for api 1.23 (docker version 1.11.x) # docker events for api 1.23 (docker version 1.11.x)
@ -236,24 +232,11 @@ def print_notification(json_data):
try: try:
if message != '': if message != '':
length = int(__addon__.getSetting('notification_length')) * 1000 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) xbmc.log('## service.system.docker ## %s' % message)
except NameError as e: except NameError as e:
pass 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): class Main(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -284,8 +267,8 @@ class Main(object):
restart_docker = True restart_docker = True
if restart_docker: if restart_docker:
oe.execute('systemctl enable /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)
oe.execute('systemctl restart /storage/.kodi/addons/service.system.docker/system.d/service.system.docker.service') subprocess.run(['systemctl','restart','service.system.docker.service'], close_fds=True)
# end temp cleanup # end temp cleanup
############################# #############################
@ -293,9 +276,11 @@ class Main(object):
monitor = DockerMonitor(self) monitor = DockerMonitor(self)
while not monitor.abortRequested(): while not monitor.abortRequested():
if monitor.waitForAbort(): try:
# we don't want to stop or disable docker while it's installed dockermon.watch(print_notification, run=lambda: not monitor.abortRequested())
pass except Exception:
monitor.waitForAbort(1)
del monitor
class DockerMonitor(xbmc.Monitor): class DockerMonitor(xbmc.Monitor):
@ -306,8 +291,6 @@ class DockerMonitor(xbmc.Monitor):
pass pass
if ( __name__ == "__main__" ): if ( __name__ == "__main__" ):
dockermonThread().start()
Main() Main()
del DockerMonitor del __addon__
dockermonThread().stop()

View File

@ -4,7 +4,7 @@
from contextlib import closing from contextlib import closing
from functools import partial from functools import partial
from socket import socket, AF_UNIX from socket import socket, AF_UNIX, timeout
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from sys import stdout, version_info from sys import stdout, version_info
import json import json
@ -70,12 +70,14 @@ def connect(url):
return sock, hostname 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). """Watch docker events. Will call callback with each new event (dict).
url can be either tcp://<host>:port or ipc://<path> url can be either tcp://<host>:port or ipc://<path>
""" """
sock, hostname = connect(url) sock, hostname = connect(url)
if run:
sock.settimeout(1.5)
request = 'GET /events HTTP/1.1\nHost: %s\n\n' % hostname request = 'GET /events HTTP/1.1\nHost: %s\n\n' % hostname
request = request.encode('utf-8') 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 # Messages are \r\n<size in hex><JSON payload>\r\n
buf = [payload] buf = [payload]
while True: 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: if not chunk:
raise EOFError('socket closed') raise EOFError('socket closed')
buf.append(chunk.decode('utf-8')) buf.append(chunk.decode('utf-8'))