Skip to content

Commit 7936cc2

Browse files
author
bossanova808
committed
[script.module.bossanova808] 1.0.1
1 parent c5dbd8c commit 7936cc2

File tree

8 files changed

+277
-117
lines changed

8 files changed

+277
-117
lines changed

script.module.bossanova808/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ _script.module.bossanova808_
77
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/bossanova808)
88

99

10-
Common code for all bossanova808 Kodi addons, including:
10+
Common code for all bossanova808 Kodi addons.
1111

12-
**Available from the Kodi Official Repository:**
12+
## Available from the Kodi Official Repository
1313

14-
* OzWeather
15-
* Unpause Jumpback
16-
* Playback Resumer
17-
* Check Previous Episode
18-
* Caber Toss
14+
* [OzWeather](https://kodi.wiki/view/Add-on:Oz_Weather)
15+
* [Unpause Jumpback](https://kodi.wiki/view/Add-on:Unpause_Jumpback)
16+
* [Playback Resumer](https://kodi.wiki/view/Add-on:Kodi_Playback_Resumer)
17+
* [Check Previous Episode](https://kodi.wiki/view/Add-on:XBMC_Check_Previous_Episode)
18+
* [Caber Toss](https://kodi.wiki/view/Add-on:Caber_Toss)
19+
* [Switchback](https://kodi.wiki/view/Add-on:Switchback)
1920

2021

21-
**Available from the [Bossanova808 Repository](https://github.com/bossanova808/repository.bossanova808):**
22+
## Available from the [Bossanova808 Repository](https://github.com/bossanova808/repository.bossanova808)
2223

23-
* OzWeather Skin Patcher
24-
* YoctoDisplay
24+
* [OzWeather Skin Patcher](https://github.com/bossanova808/repository.bossanova808)
25+
* [YoctoDisplay](https://github.com/bossanova808/repository.bossanova808)
2526

2627

2728

script.module.bossanova808/addon.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.bossanova808" name="Bossanova808 Dependencies" version="1.0.0" provider-name="bossanova808">
2+
<addon id="script.module.bossanova808" name="Bossanova808 Dependencies" version="1.0.1" provider-name="bossanova808">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
</requires>
66
<extension point="xbmc.python.module" library="resources/lib" />
77
<extension point="xbmc.addon.metadata">
8-
<description lang="en_GB">Common code needed by bossanova808 addons</description>
8+
<description lang="en_GB">Common code needed by Bossanova808 addons</description>
99
<platform>all</platform>
1010
<license>GPL-3.0-only</license>
1111
<website>https://github.com/bossanova808/script.module.bossanova808</website>
1212
<source>https://github.com/bossanova808/script.module.bossanova808</source>
13-
<news>v1.0.0 Initial release</news>
13+
<news>v1.0.1
14+
- Updates for Piers and some defensive programming</news>
1415
<assets>
1516
<icon>resources/icon.png</icon>
1617
</assets>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v1.0.1
2+
- Updates for Piers and some defensive programming
3+
4+
v1.0.0
5+
- Initial release
6+
17
v0.0.1
2-
Alpha pre-release
8+
- Alpha pre-release
39

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# -*- coding: utf-8 -*-
2-
31
import sys
2+
import re
43
import xbmc
54
import xbmcvfs
65
import xbmcgui
76
import xbmcaddon
87

9-
""" Just a bunch of very handy Kodi constants """
8+
""" Handy Kodi constants """
109

1110
ADDON = xbmcaddon.Addon()
1211
ADDON_NAME = ADDON.getAddonInfo('name')
@@ -15,12 +14,16 @@
1514
ADDON_AUTHOR = ADDON.getAddonInfo('author')
1615
ADDON_VERSION = ADDON.getAddonInfo('version')
1716
ADDON_ARGUMENTS = f'{sys.argv}'
18-
CWD = ADDON.getAddonInfo('path')
19-
LANGUAGE = ADDON.getLocalizedString
20-
PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
17+
ADDON_SETTINGS_PATH = PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
18+
ADDON_PATH = CWD = xbmcvfs.translatePath(ADDON.getAddonInfo('path'))
19+
TRANSLATE = LANGUAGE = ADDON.getLocalizedString
2120
LOG_PATH = xbmcvfs.translatePath('special://logpath')
2221
KODI_VERSION = xbmc.getInfoLabel('System.BuildVersion')
23-
KODI_VERSION_INT = int(KODI_VERSION.split(".")[0])
22+
# Parse System.BuildVersion (e.g. "21.0", "21.0-Beta1", "21.0 (20.90.801)") if possible, otherwise default to 21 (Omega)
23+
# (Have never seen the parsing fail - in practice, the fallback to 21 only happens when unit testing modules outside of Kodi)
24+
version_label = KODI_VERSION or ''
25+
version_match = re.search(r'\d+', version_label)
26+
KODI_MAJOR_VERSION = int(version_match.group(0)) if version_match else 21
2427
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"
2528
HOME_WINDOW = xbmcgui.Window(10000)
2629
WEATHER_WINDOW = xbmcgui.Window(12600)

script.module.bossanova808/resources/lib/bossanova808/exception_logger.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# coding: utf-8
2-
31
# (c) Roman Miroshnychenko <[email protected]> 2020
4-
# Retrieved from:
2+
# Originally retrieved from:
53
# https://github.com/thetvdb/metadata.tvshows.thetvdb.com.v4.python/blob/master/metadata.tvshows.thetvdb.com.v4.python/resources/lib/exception_logger.py
64
# (Thanks Roman! - Modified by bossanova808 as needed...)
75
#
@@ -21,13 +19,15 @@
2119
"""Exception logger with extended diagnostic info"""
2220

2321
import inspect
24-
import sys
2522
from contextlib import contextmanager
2623
from platform import uname
2724
from pprint import pformat
2825
from typing import Text, Callable, Generator
26+
import sys
27+
28+
# noinspection PyUnresolvedReferences
2929
import xbmc
30-
from .constants import *
30+
# noinspection PyPackages
3131
from .logger import Logger
3232

3333

@@ -118,20 +118,20 @@ def log_exception(logger_func=Logger.error):
118118
- Python version
119119
- Kodi version
120120
- Module path.
121-
- Stack trace including:
121+
- Stack trace including
122122
* File path and line number where the exception happened
123123
* Code fragment where the exception has happened.
124124
* Local variables at the moment of the exception.
125125
126126
After logging the diagnostic info the exception is re-raised.
127127
128-
Example::
128+
Example:
129129
130130
with debug_exception():
131131
# Some risky code
132132
raise RuntimeError('Fatal error!')
133133
134-
:param logger_func: logger function that accepts a single argument
134+
:param logger_func: Logger function that accepts a single argument
135135
that is a log message.
136136
"""
137137
try:
Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,99 @@
1-
# -*- coding: utf-8 -*-
1+
from pprint import pprint, pformat
2+
import sys
23

34
import xbmc
4-
from .constants import *
5+
6+
from typing import Any
7+
# noinspection PyPackages
8+
from .constants import ADDON_NAME, ADDON_VERSION, KODI_VERSION, KODI_MAJOR_VERSION, ADDON_ARGUMENTS
59

610

711
class Logger:
812

913
@staticmethod
10-
def log(message, level=xbmc.LOGDEBUG):
14+
def log(message: Any, level: int = xbmc.LOGDEBUG) -> None:
1115
"""
12-
Log a message to the Kodi log file.
13-
If we're unit testing a module outside Kodi, print to the console instead.
16+
Logs a message using the Kodi logging system. If the user agent is unavailable
17+
(e.g. during unit testing), it will print the message to the console using pprint.
1418
15-
:param message: the message to log
16-
:param level: the kodi log level to log at, default xbmc.LOGDEBUG
17-
:return:
19+
:param message: The message to be logged. If the message is not a string, it will
20+
be formatted using `pformat` before logging.
21+
:param level: The log level for the message, default `xbmc.LOGDEBUG`.
1822
"""
19-
#
23+
# (The below test will fail if we're unit testing a module)
2024
if xbmc.getUserAgent():
21-
xbmc.log(f'### {ADDON_NAME} {ADDON_VERSION}: {str(message)}', level)
25+
if isinstance(message, str):
26+
xbmc.log(f'### {ADDON_NAME.replace("Kodi ","")} {ADDON_VERSION}: {message}', level)
27+
else:
28+
xbmc.log(pformat(message), level)
2229
else:
23-
print(str(message))
30+
# ONLY USED WHEN UNIT TESTING A MODULE!
31+
pprint(message)
2432

2533
@staticmethod
26-
def info(message):
34+
def info(*messages: Any) -> None:
2735
"""
28-
Log a message to the Kodi log file at INFO level.
36+
Log messages to the Kodi log file at the INFO level.
2937
30-
:param message: the message to log
31-
:return:
38+
:param messages: The messages to log
3239
"""
33-
Logger.log(message, xbmc.LOGINFO)
40+
for message in messages:
41+
Logger.log(message, xbmc.LOGINFO)
3442

3543
@staticmethod
36-
def warning(message):
44+
def warning(*messages: Any) -> None:
3745
"""
38-
Log a message to the Kodi log file at WARNING level.
46+
Log messages to the Kodi log file at the WARNING level.
3947
40-
:param message: the message to log
41-
:return:
48+
:param messages: The messages to log
4249
"""
43-
Logger.log(message, xbmc.LOGWARNING)
50+
for message in messages:
51+
Logger.log(message, xbmc.LOGWARNING)
4452

4553
@staticmethod
46-
def error(message):
54+
def error(*messages: Any) -> None:
4755
"""
48-
Log a message to the Kodi log file at ERROR level.
56+
Log messages to the Kodi log file at the ERROR level.
4957
50-
:param message: the message to log
51-
:return:
58+
:param messages: The messages to log
5259
"""
53-
Logger.log(message, xbmc.LOGERROR)
60+
for message in messages:
61+
Logger.log(message, xbmc.LOGERROR)
5462

5563
@staticmethod
56-
def debug(*messages):
64+
def debug(*messages: Any) -> None:
5765
"""
5866
Log messages to the Kodi log file at DEBUG level.
5967
60-
:param messages: the message(s) to log
61-
:return:
68+
:param messages: The message(s) to log
6269
"""
6370
for message in messages:
6471
Logger.log(message, xbmc.LOGDEBUG)
6572

73+
@staticmethod
74+
def start(*extra_messages: Any) -> None:
75+
"""
76+
Log key information at the start of an addon run.
77+
78+
:param extra_messages: Any extra things to log, such as "(Service)" or "(Plugin)" if it helps to identify component elements.
79+
"""
80+
Logger.info(f'Start {ADDON_NAME}')
81+
if extra_messages:
82+
Logger.info(*extra_messages)
83+
Logger.info(f'Kodi {KODI_VERSION} (Major version {KODI_MAJOR_VERSION})')
84+
Logger.info(f'Python {sys.version}')
85+
if ADDON_ARGUMENTS != "['']":
86+
Logger.info(f'Run {ADDON_ARGUMENTS}')
87+
else:
88+
Logger.info('No arguments supplied to addon')
89+
90+
@staticmethod
91+
def stop(*extra_messages: Any) -> None:
92+
"""
93+
Log key information at the end of an addon run.
94+
95+
:param extra_messages: Any extra things to log, such as "(Service)" or "(Plugin)" if it helps to identify component elements.
96+
"""
97+
Logger.info(f'Finish {ADDON_NAME}')
98+
if extra_messages:
99+
Logger.info(*extra_messages)
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,52 @@
1-
# -*- coding: utf-8 -*-
2-
1+
# noinspection PyUnresolvedReferences
32
import xbmcgui
4-
from .constants import *
3+
# noinspection PyPackages
4+
from .constants import ADDON_NAME
55

66

77
class Notify:
88

99
@staticmethod
10-
def kodi_notification(message, duration=5000, icon=xbmcgui.NOTIFICATION_INFO):
10+
def kodi_notification(message: str, duration: int = 5000, icon: str = xbmcgui.NOTIFICATION_INFO) -> None:
1111
"""
1212
Send a custom notification to the user via the Kodi GUI
1313
1414
:param message: the message to send
1515
:param duration: time to display notification in milliseconds, default 5000
16-
:param icon: xbmcgui.NOTIFICATION_INFO (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_ERROR (or custom icon)
17-
:return: None
16+
:param icon: xbmcgui.NOTIFICATION_INFO (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_ERROR, or custom icon
1817
"""
1918
dialog = xbmcgui.Dialog()
20-
2119
dialog.notification(heading=ADDON_NAME,
2220
message=message,
2321
icon=icon,
2422
time=duration)
2523

2624
@staticmethod
27-
def info(message, duration=5000):
25+
def info(message: str, duration: int = 5000) -> None:
2826
"""
2927
Send an info level notification to the user via the Kodi GUI
3028
3129
:param message: the message to display
32-
:param duration: the duration to show the message, default 5000ms
33-
:return:
30+
:param duration: the duration to show the message, default 5000 ms
3431
"""
3532
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_INFO)
3633

3734
@staticmethod
38-
def warning(message, duration=5000):
35+
def warning(message: str, duration: int = 5000) -> None:
3936
"""
4037
Send a warning notification to the user via the Kodi GUI
4138
4239
:param message: the message to display
43-
:param duration: the duration to show the message, default 5000ms
44-
:return:
40+
:param duration: the duration to show the message, default 5000 ms
4541
"""
4642
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_WARNING)
4743

4844
@staticmethod
49-
def error(message, duration=5000):
45+
def error(message: str, duration: int = 5000) -> None:
5046
"""
5147
Send an error level notification to the user via the Kodi GUI
5248
5349
:param message: the message to display
54-
:param duration: the duration to show the message, default 5000ms
55-
:return:
50+
:param duration: the duration to show the message, default 5000 ms
5651
"""
57-
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_ERROR)
52+
Notify.kodi_notification(message, duration, xbmcgui.NOTIFICATION_ERROR)

0 commit comments

Comments
 (0)