Skip to content
Merged
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
21 changes: 11 additions & 10 deletions script.module.bossanova808/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ _script.module.bossanova808_
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/bossanova808)


Common code for all bossanova808 Kodi addons, including:
Common code for all bossanova808 Kodi addons.

**Available from the Kodi Official Repository:**
## Available from the Kodi Official Repository

* OzWeather
* Unpause Jumpback
* Playback Resumer
* Check Previous Episode
* Caber Toss
* [OzWeather](https://kodi.wiki/view/Add-on:Oz_Weather)
* [Unpause Jumpback](https://kodi.wiki/view/Add-on:Unpause_Jumpback)
* [Playback Resumer](https://kodi.wiki/view/Add-on:Kodi_Playback_Resumer)
* [Check Previous Episode](https://kodi.wiki/view/Add-on:XBMC_Check_Previous_Episode)
* [Caber Toss](https://kodi.wiki/view/Add-on:Caber_Toss)
* [Switchback](https://kodi.wiki/view/Add-on:Switchback)


**Available from the [Bossanova808 Repository](https://github.com/bossanova808/repository.bossanova808):**
## Available from the [Bossanova808 Repository](https://github.com/bossanova808/repository.bossanova808)

* OzWeather Skin Patcher
* YoctoDisplay
* [OzWeather Skin Patcher](https://github.com/bossanova808/repository.bossanova808)
* [YoctoDisplay](https://github.com/bossanova808/repository.bossanova808)



Expand Down
7 changes: 4 additions & 3 deletions script.module.bossanova808/addon.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.bossanova808" name="Bossanova808 Dependencies" version="1.0.0" provider-name="bossanova808">
<addon id="script.module.bossanova808" name="Bossanova808 Dependencies" version="1.0.1" provider-name="bossanova808">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
</requires>
<extension point="xbmc.python.module" library="resources/lib" />
<extension point="xbmc.addon.metadata">
<description lang="en_GB">Common code needed by bossanova808 addons</description>
<description lang="en_GB">Common code needed by Bossanova808 addons</description>
<platform>all</platform>
<license>GPL-3.0-only</license>
<website>https://github.com/bossanova808/script.module.bossanova808</website>
<source>https://github.com/bossanova808/script.module.bossanova808</source>
<news>v1.0.0 Initial release</news>
<news>v1.0.1
- Updates for Piers and some defensive programming</news>
<assets>
<icon>resources/icon.png</icon>
</assets>
Expand Down
8 changes: 7 additions & 1 deletion script.module.bossanova808/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.0.1
- Updates for Piers and some defensive programming

v1.0.0
- Initial release

v0.0.1
Alpha pre-release
- Alpha pre-release

17 changes: 10 additions & 7 deletions script.module.bossanova808/resources/lib/bossanova808/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-

import sys
import re
import xbmc
import xbmcvfs
import xbmcgui
import xbmcaddon

""" Just a bunch of very handy Kodi constants """
""" Handy Kodi constants """

ADDON = xbmcaddon.Addon()
ADDON_NAME = ADDON.getAddonInfo('name')
Expand All @@ -15,12 +14,16 @@
ADDON_AUTHOR = ADDON.getAddonInfo('author')
ADDON_VERSION = ADDON.getAddonInfo('version')
ADDON_ARGUMENTS = f'{sys.argv}'
CWD = ADDON.getAddonInfo('path')
LANGUAGE = ADDON.getLocalizedString
PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
ADDON_SETTINGS_PATH = PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
ADDON_PATH = CWD = xbmcvfs.translatePath(ADDON.getAddonInfo('path'))
TRANSLATE = LANGUAGE = ADDON.getLocalizedString
LOG_PATH = xbmcvfs.translatePath('special://logpath')
KODI_VERSION = xbmc.getInfoLabel('System.BuildVersion')
KODI_VERSION_INT = int(KODI_VERSION.split(".")[0])
# Parse System.BuildVersion (e.g. "21.0", "21.0-Beta1", "21.0 (20.90.801)") if possible, otherwise default to 21 (Omega)
# (Have never seen the parsing fail - in practice, the fallback to 21 only happens when unit testing modules outside of Kodi)
version_label = KODI_VERSION or ''
version_match = re.search(r'\d+', version_label)
KODI_MAJOR_VERSION = int(version_match.group(0)) if version_match else 21
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
HOME_WINDOW = xbmcgui.Window(10000)
WEATHER_WINDOW = xbmcgui.Window(12600)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8

# (c) Roman Miroshnychenko <[email protected]> 2020
# Retrieved from:
# Originally retrieved from:
# https://github.com/thetvdb/metadata.tvshows.thetvdb.com.v4.python/blob/master/metadata.tvshows.thetvdb.com.v4.python/resources/lib/exception_logger.py
# (Thanks Roman! - Modified by bossanova808 as needed...)
#
Expand All @@ -21,13 +19,15 @@
"""Exception logger with extended diagnostic info"""

import inspect
import sys
from contextlib import contextmanager
from platform import uname
from pprint import pformat
from typing import Text, Callable, Generator
import sys

# noinspection PyUnresolvedReferences
import xbmc
from .constants import *
# noinspection PyPackages
from .logger import Logger


Expand Down Expand Up @@ -118,20 +118,20 @@ def log_exception(logger_func=Logger.error):
- Python version
- Kodi version
- Module path.
- Stack trace including:
- Stack trace including
* File path and line number where the exception happened
* Code fragment where the exception has happened.
* Local variables at the moment of the exception.

After logging the diagnostic info the exception is re-raised.

Example::
Example:

with debug_exception():
# Some risky code
raise RuntimeError('Fatal error!')

:param logger_func: logger function that accepts a single argument
:param logger_func: Logger function that accepts a single argument
that is a log message.
"""
try:
Expand Down
92 changes: 63 additions & 29 deletions script.module.bossanova808/resources/lib/bossanova808/logger.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,99 @@
# -*- coding: utf-8 -*-
from pprint import pprint, pformat
import sys

import xbmc
from .constants import *

from typing import Any
# noinspection PyPackages
from .constants import ADDON_NAME, ADDON_VERSION, KODI_VERSION, KODI_MAJOR_VERSION, ADDON_ARGUMENTS


class Logger:

@staticmethod
def log(message, level=xbmc.LOGDEBUG):
def log(message: Any, level: int = xbmc.LOGDEBUG) -> None:
"""
Log a message to the Kodi log file.
If we're unit testing a module outside Kodi, print to the console instead.
Logs a message using the Kodi logging system. If the user agent is unavailable
(e.g. during unit testing), it will print the message to the console using pprint.

:param message: the message to log
:param level: the kodi log level to log at, default xbmc.LOGDEBUG
:return:
:param message: The message to be logged. If the message is not a string, it will
be formatted using `pformat` before logging.
:param level: The log level for the message, default `xbmc.LOGDEBUG`.
"""
#
# (The below test will fail if we're unit testing a module)
if xbmc.getUserAgent():
xbmc.log(f'### {ADDON_NAME} {ADDON_VERSION}: {str(message)}', level)
if isinstance(message, str):
xbmc.log(f'### {ADDON_NAME.replace("Kodi ","")} {ADDON_VERSION}: {message}', level)
else:
xbmc.log(pformat(message), level)
else:
print(str(message))
# ONLY USED WHEN UNIT TESTING A MODULE!
pprint(message)

@staticmethod
def info(message):
def info(*messages: Any) -> None:
"""
Log a message to the Kodi log file at INFO level.
Log messages to the Kodi log file at the INFO level.

:param message: the message to log
:return:
:param messages: The messages to log
"""
Logger.log(message, xbmc.LOGINFO)
for message in messages:
Logger.log(message, xbmc.LOGINFO)

@staticmethod
def warning(message):
def warning(*messages: Any) -> None:
"""
Log a message to the Kodi log file at WARNING level.
Log messages to the Kodi log file at the WARNING level.

:param message: the message to log
:return:
:param messages: The messages to log
"""
Logger.log(message, xbmc.LOGWARNING)
for message in messages:
Logger.log(message, xbmc.LOGWARNING)

@staticmethod
def error(message):
def error(*messages: Any) -> None:
"""
Log a message to the Kodi log file at ERROR level.
Log messages to the Kodi log file at the ERROR level.

:param message: the message to log
:return:
:param messages: The messages to log
"""
Logger.log(message, xbmc.LOGERROR)
for message in messages:
Logger.log(message, xbmc.LOGERROR)

@staticmethod
def debug(*messages):
def debug(*messages: Any) -> None:
"""
Log messages to the Kodi log file at DEBUG level.

:param messages: the message(s) to log
:return:
:param messages: The message(s) to log
"""
for message in messages:
Logger.log(message, xbmc.LOGDEBUG)

@staticmethod
def start(*extra_messages: Any) -> None:
"""
Log key information at the start of an addon run.

:param extra_messages: Any extra things to log, such as "(Service)" or "(Plugin)" if it helps to identify component elements.
"""
Logger.info(f'Start {ADDON_NAME}')
if extra_messages:
Logger.info(*extra_messages)
Logger.info(f'Kodi {KODI_VERSION} (Major version {KODI_MAJOR_VERSION})')
Logger.info(f'Python {sys.version}')
if ADDON_ARGUMENTS != "['']":
Logger.info(f'Run {ADDON_ARGUMENTS}')
else:
Logger.info('No arguments supplied to addon')

@staticmethod
def stop(*extra_messages: Any) -> None:
"""
Log key information at the end of an addon run.

:param extra_messages: Any extra things to log, such as "(Service)" or "(Plugin)" if it helps to identify component elements.
"""
Logger.info(f'Finish {ADDON_NAME}')
if extra_messages:
Logger.info(*extra_messages)
29 changes: 12 additions & 17 deletions script.module.bossanova808/resources/lib/bossanova808/notify.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
# -*- coding: utf-8 -*-

# noinspection PyUnresolvedReferences
import xbmcgui
from .constants import *
# noinspection PyPackages
from .constants import ADDON_NAME


class Notify:

@staticmethod
def kodi_notification(message, duration=5000, icon=xbmcgui.NOTIFICATION_INFO):
def kodi_notification(message: str, duration: int = 5000, icon: str = xbmcgui.NOTIFICATION_INFO) -> None:
"""
Send a custom notification to the user via the Kodi GUI

:param message: the message to send
:param duration: time to display notification in milliseconds, default 5000
:param icon: xbmcgui.NOTIFICATION_INFO (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_ERROR (or custom icon)
:return: None
:param icon: xbmcgui.NOTIFICATION_INFO (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_ERROR, or custom icon
"""
dialog = xbmcgui.Dialog()

dialog.notification(heading=ADDON_NAME,
message=message,
icon=icon,
time=duration)

@staticmethod
def info(message, duration=5000):
def info(message: str, duration: int = 5000) -> None:
"""
Send an info level notification to the user via the Kodi GUI

:param message: the message to display
:param duration: the duration to show the message, default 5000ms
:return:
:param duration: the duration to show the message, default 5000 ms
"""
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_INFO)

@staticmethod
def warning(message, duration=5000):
def warning(message: str, duration: int = 5000) -> None:
"""
Send a warning notification to the user via the Kodi GUI

:param message: the message to display
:param duration: the duration to show the message, default 5000ms
:return:
:param duration: the duration to show the message, default 5000 ms
"""
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_WARNING)

@staticmethod
def error(message, duration=5000):
def error(message: str, duration: int = 5000) -> None:
"""
Send an error level notification to the user via the Kodi GUI

:param message: the message to display
:param duration: the duration to show the message, default 5000ms
:return:
:param duration: the duration to show the message, default 5000 ms
"""
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_ERROR)
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_ERROR)
Loading