Skip to content

Commit

Permalink
Fix docstrings
Browse files Browse the repository at this point in the history
This fixes docstrings as done in other projects. (PEP 257)
https://www.python.org/dev/peps/pep-0257/
  • Loading branch information
dagwieers committed Jan 21, 2020
1 parent 8fd7cca commit 25b743e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@


class Api:
''' Main API class '''
"""Main API class"""
_shared_state = {}

def __init__(self):
''' Constructor for Api class '''
"""Constructor for Api class"""
self.__dict__ = self._shared_state
self.data = {}
self.encoding = 'base64'

def log(self, msg, level=2):
''' Log wrapper '''
"""Log wrapper"""
ulog(msg, name=self.__class__.__name__, level=level)

def has_addon_data(self):
Expand Down
10 changes: 5 additions & 5 deletions resources/lib/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@


class UpNextMonitor(Monitor):
''' Service monitor for Kodi '''
"""Service monitor for Kodi"""

def __init__(self):
''' Constructor for Monitor '''
"""Constructor for Monitor"""
self.player = UpNextPlayer()
self.api = Api()
self.playback_manager = PlaybackManager()
Monitor.__init__(self)

def log(self, msg, level=1):
''' Log wrapper '''
"""Log wrapper"""
ulog(msg, name=self.__class__.__name__, level=level)

def run(self):
''' Main service loop '''
"""Main service loop"""
self.log('Service started', 0)

while not self.abortRequested():
Expand Down Expand Up @@ -82,7 +82,7 @@ def run(self):
self.log('Service stopped', 0)

def onNotification(self, sender, method, data): # pylint: disable=invalid-name
''' Notification event handler for accepting data from add-ons '''
"""Notification event handler for accepting data from add-ons"""
if not method.endswith('upnext_data'): # Method looks like Other.upnext_data
return

Expand Down
10 changes: 5 additions & 5 deletions resources/lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class UpNextPlayer(Player):
''' Service class for playback monitoring '''
"""Service class for playback monitoring"""
last_file = None
track = False

Expand All @@ -30,7 +30,7 @@ def disable_tracking(self):
self.state.track = False

def onPlayBackStarted(self): # pylint: disable=invalid-name
''' Will be called when kodi starts playing a file '''
"""Will be called when kodi starts playing a file"""
sleep(5000) # Delay for slower devices, should really use onAVStarted for Leia
if not getCondVisibility('videoplayer.content(episodes)'):
return
Expand All @@ -43,16 +43,16 @@ def onPlayBackResumed(self): # pylint: disable=invalid-name
self.state.pause = False

def onPlayBackStopped(self): # pylint: disable=invalid-name
''' Will be called when user stops playing a file '''
"""Will be called when user stops playing a file"""
self.api.reset_addon_data()
self.state = State() # Reset state

def onPlayBackEnded(self): # pylint: disable=invalid-name
''' Will be called when Kodi has ended playing a file '''
"""Will be called when Kodi has ended playing a file"""
self.api.reset_addon_data()
self.state = State() # Reset state

def onPlayBackError(self): # pylint: disable=invalid-name
''' Will be called when when playback stops due to an error '''
"""Will be called when when playback stops due to an error"""
self.api.reset_addon_data()
self.state = State() # Reset state
4 changes: 2 additions & 2 deletions resources/lib/script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# GNU General Public License v2.0 (see COPYING or https://www.gnu.org/licenses/gpl-2.0.txt)
''' This is the actual Up Next API script '''
"""This is the actual Up Next API script"""

from __future__ import absolute_import, division, unicode_literals
from datetime import datetime, timedelta
Expand Down Expand Up @@ -102,7 +102,7 @@ def open_settings():


def run(argv):
''' Route to API method '''
"""Route to API method"""
if len(argv) == 3 and argv[1] == 'test_window':
test_popup(argv[2])
else:
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/script_entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# GNU General Public License v2.0 (see COPYING or https://www.gnu.org/licenses/gpl-2.0.txt)
''' This is the Up Next script entry point '''
"""This is the Up Next script entry point"""

from __future__ import absolute_import, division, unicode_literals
from sys import argv
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/statichelper.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# -*- coding: utf-8 -*-
# GNU General Public License v2.0 (see COPYING or https://www.gnu.org/licenses/gpl-2.0.txt)
''' Implements static functions used elsewhere in the add-on '''
"""Implements static functions used elsewhere in the add-on"""

from __future__ import absolute_import, division, unicode_literals


def to_unicode(text, encoding='utf-8', errors='strict'):
''' Force text to unicode '''
"""Force text to unicode"""
if isinstance(text, bytes):
return text.decode(encoding, errors)
return text


def from_unicode(text, encoding='utf-8', errors='strict'):
''' Force unicode to text '''
"""Force unicode to text"""
import sys
if sys.version_info.major == 2 and isinstance(text, unicode): # noqa: F821; pylint: disable=undefined-variable,useless-suppression
return text.encode(encoding, errors)
Expand Down
30 changes: 15 additions & 15 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@


def get_addon_info(key):
''' Return add-on information '''
"""Return add-on information"""
return to_unicode(ADDON.getAddonInfo(key))


def addon_id():
''' Return add-on ID '''
"""Return add-on ID"""
return get_addon_info('id')


def addon_path():
''' Return add-on path '''
"""Return add-on path"""
return get_addon_info('path')


def get_property(key, window_id=10000):
''' Get a Window property '''
"""Get a Window property"""
return to_unicode(Window(window_id).getProperty(key))


def set_property(key, value, window_id=10000):
''' Set a Window property '''
"""Set a Window property"""
return Window(window_id).setProperty(key, from_unicode(str(value)))


def clear_property(key, window_id=10000):
''' Clear a Window property '''
"""Clear a Window property"""
return Window(window_id).clearProperty(key)


def get_setting(key, default=None):
''' Get an add-on setting '''
"""Get an add-on setting"""
# We use Addon() here to ensure changes in settings are reflected instantly
try:
value = to_unicode(Addon().getSetting(key))
Expand All @@ -55,7 +55,7 @@ def get_setting(key, default=None):


def encode_data(data, encoding='base64'):
''' Encode data for a notification event '''
"""Encode data for a notification event"""
json_data = json.dumps(data).encode()
if encoding == 'base64':
from base64 import b64encode
Expand All @@ -72,7 +72,7 @@ def encode_data(data, encoding='base64'):


def decode_data(encoded):
''' Decode data coming from a notification event '''
"""Decode data coming from a notification event"""
encoding = 'base64'
from binascii import Error, unhexlify
try:
Expand All @@ -94,7 +94,7 @@ def decode_json(data):


def event(message, data=None, sender=None, encoding='base64'):
''' Send internal notification event '''
"""Send internal notification event"""
data = data or {}
sender = sender or addon_id()

Expand All @@ -110,7 +110,7 @@ def event(message, data=None, sender=None, encoding='base64'):


def log(msg, name=None, level=1):
''' Log information to the Kodi log '''
"""Log information to the Kodi log"""
log_level = int(get_setting('logLevel', level))
debug_logging = get_global_setting('debug.showloginfo')
set_property('logLevel', log_level)
Expand All @@ -121,14 +121,14 @@ def log(msg, name=None, level=1):


def calculate_progress_steps(period):
''' Calculate a progress step '''
"""Calculate a progress step"""
if int(period) == 0: # Avoid division by zero
return 10.0
return (100.0 / int(period)) / 10


def jsonrpc(**kwargs):
''' Perform JSONRPC calls '''
"""Perform JSONRPC calls"""
if 'id' not in kwargs:
kwargs.update(id=1)
if 'jsonrpc' not in kwargs:
Expand All @@ -137,13 +137,13 @@ def jsonrpc(**kwargs):


def get_global_setting(setting):
''' Get a Kodi setting '''
"""Get a Kodi setting"""
result = jsonrpc(method='Settings.GetSettingValue', params=dict(setting=setting))
return result.get('result', {}).get('value')


def localize(string_id):
''' Return the translated string from the .po language files, optionally translating variables '''
"""Return the translated string from the .po language files, optionally translating variables"""
return ADDON.getLocalizedString(string_id)


Expand Down

0 comments on commit 25b743e

Please sign in to comment.