From b5e36047f518ef50f0d798098b982f30a178ea55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Mon, 11 May 2020 14:12:13 +0200 Subject: [PATCH] Add option for debug logging and fix CI (#27) --- .github/workflows/addon-check.yml | 28 +++++++------- .github/workflows/ci.yml | 37 +++++++------------ addon_entry.py | 8 ++-- .../resource.language.en_gb/strings.po | 12 ++++++ .../resource.language.nl_nl/strings.po | 12 ++++++ resources/lib/kodilogging.py | 13 +++++-- resources/lib/modules/player.py | 4 +- resources/lib/service.py | 6 +-- resources/lib/viervijfzes/auth.py | 2 +- resources/settings.xml | 4 ++ tests/xbmcgui.py | 2 +- 11 files changed, 76 insertions(+), 52 deletions(-) diff --git a/.github/workflows/addon-check.yml b/.github/workflows/addon-check.yml index efec0fb..c6229a3 100644 --- a/.github/workflows/addon-check.yml +++ b/.github/workflows/addon-check.yml @@ -1,24 +1,17 @@ name: Kodi - on: - push: - branches: - - master - pull_request: - branches: - - master - + - pull_request + - push jobs: tests: - name: Kodi Add-on checker + name: Addon checker runs-on: ubuntu-latest strategy: fail-fast: false matrix: kodi-branch: [leia, matrix] steps: - - name: Check out ${{ github.sha }} from repository ${{ github.repository }} - uses: actions/checkout@v2 + - uses: actions/checkout@v2 with: path: ${{ github.repository }} - name: Set up Python 3.8 @@ -27,15 +20,20 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - sudo apt-get install libxml2-utils xmlstarlet + sudo apt-get install xmlstarlet python -m pip install --upgrade pip - pip install kodi-addon-checker + # FIXME: Requires changes from xbmc/addon-check#217 + #pip install kodi-addon-checker + pip install git+git://github.com/xbmc/addon-check.git@master - name: Remove unwanted files run: awk '/export-ignore/ { print $1 }' .gitattributes | xargs rm -rf -- working-directory: ${{ github.repository }} - name: Rewrite addon.xml for Matrix - run: xmlstarlet ed -L -u '/addon/requires/import[@addon="xbmc.python"]/@version' -v "3.0.0" addon.xml + run: | + xmlstarlet ed -L -u '/addon/requires/import[@addon="xbmc.python"]/@version' -v "3.0.0" addon.xml + version=$(xmlstarlet sel -t -v 'string(/addon/@version)' addon.xml) + xmlstarlet ed -L -u '/addon/@version' -v "${version}+matrix.99" addon.xml working-directory: ${{ github.repository }} if: matrix.kodi-branch == 'matrix' - name: Run kodi-addon-checker - run: kodi-addon-checker --branch=${{ matrix.kodi-branch }} ${{ github.repository }}/ + run: kodi-addon-checker --branch=${{ matrix.kodi-branch }} ${{ github.repository }}/ \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 949c6cf..ee5d28e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,16 +1,10 @@ name: CI - on: - push: - branches: - - master - pull_request: - branches: - - master - + - pull_request + - push jobs: tests: - name: Unit tests + name: Add-on testing runs-on: ubuntu-latest env: PYTHONIOENCODING: utf-8 @@ -33,26 +27,21 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - name: Run pylint - run: | - make check-pylint + run: make check-pylint - name: Run tox - run: | - make check-tox + run: make check-tox - name: Check translations - run: | - make check-translations + run: make check-translations - name: Run unit tests + run: coverage run -m unittest discover env: - ADDON_USERNAME: ${{ secrets.ADDON_USERNAME }} ADDON_PASSWORD: ${{ secrets.ADDON_PASSWORD }} - run: | - coverage run -m unittest discover - - name: Run addon - run: | - coverage run -a tests/run.py / - - name: Run add-on service - run: | - coverage run -a service_entry.py + ADDON_USERNAME: ${{ secrets.ADDON_USERNAME }} + - name: Run addon service + run: coverage run -a service_entry.py + env: + ADDON_PASSWORD: ${{ secrets.ADDON_PASSWORD }} + ADDON_USERNAME: ${{ secrets.ADDON_USERNAME }} - name: Upload code coverage to CodeCov uses: codecov/codecov-action@v1 continue-on-error: true diff --git a/addon_entry.py b/addon_entry.py index d63bec4..f2ba730 100644 --- a/addon_entry.py +++ b/addon_entry.py @@ -3,11 +3,13 @@ from __future__ import absolute_import, division, unicode_literals -import xbmcaddon +from xbmcaddon import Addon -from resources.lib import kodiutils +from resources.lib import kodiutils, kodilogging -kodiutils.ADDON = xbmcaddon.Addon() +# Reinitialise ADDON every invocation to fix an issue that settings are not fresh. +kodiutils.ADDON = Addon() +kodilogging.ADDON = Addon() if __name__ == '__main__': from sys import argv diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 88fc21b..54b37de 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -181,3 +181,15 @@ msgstr "" msgctxt "#30831" msgid "Update local metadata now" msgstr "" + +msgctxt "#30880" +msgid "Expert" +msgstr "" + +msgctxt "#30881" +msgid "Logging" +msgstr "" + +msgctxt "#30882" +msgid "Enable debug logging" +msgstr "" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 83edf0d..f7f7d2f 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -182,3 +182,15 @@ msgstr "Vernieuw de lokale metdata automatisch in de achtergrond" msgctxt "#30831" msgid "Update local metadata now" msgstr "De lokale metadata nu vernieuwen" + +msgctxt "#30880" +msgid "Expert" +msgstr "Expert" + +msgctxt "#30881" +msgid "Logging" +msgstr "Logboek" + +msgctxt "#30882" +msgid "Enable debug logging" +msgstr "Activeer debug logging" diff --git a/resources/lib/kodilogging.py b/resources/lib/kodilogging.py index 83d1b67..16521e0 100644 --- a/resources/lib/kodilogging.py +++ b/resources/lib/kodilogging.py @@ -8,14 +8,15 @@ import logging import xbmc import xbmcaddon +ADDON = xbmcaddon.Addon() + class KodiLogHandler(logging.StreamHandler): """ A log handler for Kodi """ def __init__(self): logging.StreamHandler.__init__(self) - addon_id = xbmcaddon.Addon().getAddonInfo("id") - formatter = logging.Formatter("[{}] [%(name)s] %(message)s".format(addon_id)) + formatter = logging.Formatter("[{}] [%(name)s] %(message)s".format(ADDON.getAddonInfo("id"))) self.setFormatter(formatter) def emit(self, record): @@ -24,10 +25,16 @@ class KodiLogHandler(logging.StreamHandler): logging.CRITICAL: xbmc.LOGFATAL, logging.ERROR: xbmc.LOGERROR, logging.WARNING: xbmc.LOGWARNING, - logging.INFO: xbmc.LOGINFO, + logging.INFO: xbmc.LOGNOTICE, logging.DEBUG: xbmc.LOGDEBUG, logging.NOTSET: xbmc.LOGNONE, } + + # Map DEBUG level to LOGNOTICE if debug logging setting has been activated + # This is for troubleshooting only + if ADDON.getSetting('debug_logging') == 'true': + levels[logging.DEBUG] = xbmc.LOGNOTICE + try: xbmc.log(self.format(record), levels[record.levelno]) except UnicodeEncodeError: diff --git a/resources/lib/modules/player.py b/resources/lib/modules/player.py index 571c711..28eac26 100644 --- a/resources/lib/modules/player.py +++ b/resources/lib/modules/player.py @@ -38,12 +38,12 @@ class Player: # We already have a resolved stream. Nice! # We don't need credentials for these streams. resolved_stream = episode.stream - _LOGGER.info('Already got a resolved stream: %s', resolved_stream) + _LOGGER.debug('Already got a resolved stream: %s', resolved_stream) if episode.uuid: # Lookup the stream resolved_stream = self._resolve_stream(episode.uuid) - _LOGGER.info('Resolved stream: %s', resolved_stream) + _LOGGER.debug('Resolved stream: %s', resolved_stream) if resolved_stream: titleitem = Menu.generate_titleitem(episode) diff --git a/resources/lib/service.py b/resources/lib/service.py index 9f1c5fb..11440be 100644 --- a/resources/lib/service.py +++ b/resources/lib/service.py @@ -28,7 +28,7 @@ class BackgroundService(Monitor): def run(self): """ Background loop for maintenance tasks """ - _LOGGER.info('Service started') + _LOGGER.debug('Service started') while not self.abortRequested(): # Update every `update_interval` after the last update @@ -39,12 +39,12 @@ class BackgroundService(Monitor): if self.waitForAbort(10): break - _LOGGER.info('Service stopped') + _LOGGER.debug('Service stopped') def onSettingsChanged(self): # pylint: disable=invalid-name """ Callback when a setting has changed """ if self._has_credentials_changed(): - _LOGGER.info('Clearing auth tokens due to changed credentials') + _LOGGER.debug('Clearing auth tokens due to changed credentials') self._auth.clear_tokens() # Refresh container diff --git a/resources/lib/viervijfzes/auth.py b/resources/lib/viervijfzes/auth.py index b7651b6..2096ff8 100644 --- a/resources/lib/viervijfzes/auth.py +++ b/resources/lib/viervijfzes/auth.py @@ -39,7 +39,7 @@ class AuthApi: self._refresh_token = data_json.get('refresh_token') self._expiry = int(data_json.get('expiry', 0)) except (IOError, TypeError, ValueError): - _LOGGER.info('We could not use the cache since it is invalid or non-existent.') + _LOGGER.warning('We could not use the cache since it is invalid or non-existent.') def get_token(self): """ Get a valid token """ diff --git a/resources/settings.xml b/resources/settings.xml index 277f2de..404e5b6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -11,4 +11,8 @@ + + + + diff --git a/tests/xbmcgui.py b/tests/xbmcgui.py index 115d669..2edf819 100644 --- a/tests/xbmcgui.py +++ b/tests/xbmcgui.py @@ -270,7 +270,7 @@ class ListItem: class Window: """A reimplementation of the xbmcgui Window""" - def __init__(self, windowId): + def __init__(self, existingwindowId=-1): """A stub constructor for the xbmcgui Window class""" return None