Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint and flake8 issues #194

Merged
merged 3 commits into from
Sep 9, 2019
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
5 changes: 5 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
[MESSAGES CONTROL]
disable=
bad-option-value,
cyclic-import,
duplicate-code,
fixme,
invalid-name,
line-too-long,
locally-disabled,
missing-docstring,
no-self-use,
old-style-class,
too-few-public-methods,
too-many-arguments,
too-many-instance-attributes,
too-many-locals,
too-many-public-methods,
too-many-return-statements,
too-many-statements,
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ python:
#- '3.7'

env:
PYTHONPATH: .:modules:resources/lib:test
PYTHONPATH: .:modules/enum:modules/mysql-connector-python:resources/lib:test
PYTHONIOENCODING: utf-8

install:
- pip install -r requirements.txt

script:
#- tox
#- tox -e flake8
#- pylint resources/lib/ test/
- tox
- tox -e flake8
- pylint resources/lib/ test/
#- kodi-addon-checker . --branch=leia
#- coverage run service.py
#- coverage run test/run.py /
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ENVS := flake8,py27,py36
export PYTHONPATH := :$(CURDIR)/modules:$(CURDIR)/resources/lib:$(CURDIR)/test
export PYTHONPATH := .:$(CURDIR)/modules/enum:$(CURDIR)/modules/mysql-connector-python:$(CURDIR)/resources/lib:$(CURDIR)/test
addon_xml := addon.xml

# Collect information to build as sensible package name
Expand All @@ -18,7 +18,7 @@ blue = \e[1;34m
white = \e[1;37m
reset = \e[0m

all: clean sanity unit docs
all: clean test zip

clean:
find . -name '*.pyc' -type f -delete
Expand All @@ -44,13 +44,17 @@ addon: clean

unit:
@echo -e "$(white)=$(blue) Starting unit tests$(reset)"
python -m unittest discover

run:
@echo -e "$(white)=$(blue) Run CLI$(reset)"
# python test/run.py /action/purge_cache/
# python test/run.py /action/purge_cache/?on_disk=True
# python service.py
# python test/run.py /
# python test/run.py /directory/root
# python test/run.py /directory/search/cartoon
python -m unittest discover
# python service.py
python test/run.py /

zip: clean
@echo -e "$(white)=$(blue) Building new package$(reset)"
Expand Down
2 changes: 1 addition & 1 deletion addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License: MIT https://goo.gl/5bMj3H
# pylint: disable=wrong-import-position
"""Kodi plugin for Netflix (https://netflix.com)"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

import sys
from functools import wraps
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#
# plugin.video.netflix documentation build configuration file, created by
# sphinx-quickstart on Wed Apr 26 16:27:25 2017.
from __future__ import absolute_import, division, unicode_literals


import os
import re
import sys
from shutil import copyfile
import sphinx_rtd_theme

BASE_PATH = os.path.dirname(os.path.abspath(__file__)) + os.path.sep
Expand Down
29 changes: 15 additions & 14 deletions resources/lib/api/data_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
"""Convenience representations of datatypes returned by the API"""
# pylint: disable=too-few-public-methods
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

from collections import OrderedDict

from resources.lib.globals import g
import resources.lib.common as common

from .paths import resolve_refs
Expand Down Expand Up @@ -65,7 +64,7 @@ def __init__(self, path_response, list_id=None):
self.perpetual_range_selector = path_response.get('_perpetual_range_selector')
self.data = path_response
has_data = True if path_response.get('lists') else False
self.videos = {}
self.videos = OrderedDict()
self.artitem = None
self.contained_titles = None
self.videoids = None
Expand Down Expand Up @@ -104,7 +103,7 @@ def __init__(self, path_response, context_name, context_id, req_sort_order_type)
and path_response[context_name].get(context_id)) or \
(not context_id and path_response.get(context_name)) else False
self.data_lists = {}
self.videos = {}
self.videos = OrderedDict()
self.artitem = None
self.contained_titles = None
self.videoids = None
Expand Down Expand Up @@ -135,7 +134,7 @@ def __init__(self, path_response):
self.perpetual_range_selector = path_response.get('_perpetual_range_selector')
self.data = path_response
has_data = 'search' in path_response
self.videos = {}
self.videos = OrderedDict()
self.videoids = None
self.artitem = None
self.contained_titles = None
Expand Down Expand Up @@ -203,7 +202,7 @@ class SubgenreList(object):
"""A list of subgenre."""
def __init__(self, path_response):
common.debug('Subgenre data: {}'.format(path_response))
self.lists = {}
self.lists = []
if path_response:
self.perpetual_range_selector = path_response.get('_perpetual_range_selector')
genre_id = next(path_response.get('genres', {}).iterkeys())
Expand Down Expand Up @@ -238,13 +237,15 @@ def _get_videoids(videos):

def _filterout_contexts(data, contexts):
"""Deletes from the data all records related to the specified contexts"""
id = next(data['lolomos'].iterkeys())
_id = next(data['lolomos'].iterkeys())
for context in contexts:
for listid in data.get('lists', {}).keys():
if data['lists'][listid].get('context'):
if data['lists'][listid]['context'] == context:
for idkey in data['lolomos'][id].keys():
if listid in data['lolomos'][id][idkey]:
del data['lolomos'][id][idkey]
break
del data['lists'][listid]
if not data['lists'][listid].get('context'):
continue
if data['lists'][listid]['context'] != context:
continue
for idkey in data['lolomos'][_id].keys():
if listid in data['lolomos'][_id][idkey]:
del data['lolomos'][_id][idkey]
break
del data['lists'][listid]
2 changes: 1 addition & 1 deletion resources/lib/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Common exception types for API operations"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals


class MissingCredentialsError(Exception):
Expand Down
9 changes: 4 additions & 5 deletions resources/lib/api/paths.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
"""Path info to query the Shakti pathEvaluator"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

from resources.lib.globals import g
import resources.lib.common as common

from .exceptions import InvalidReferenceError

MAX_PATH_REQUEST_SIZE = 47 # Stands for 48 results, is the default value defined by netflix for a single request
MAX_PATH_REQUEST_SIZE = 47 # Stands for 48 results, is the default value defined by netflix for a single request

RANGE_SELECTOR = 'RANGE_SELECTOR'

Expand Down Expand Up @@ -83,7 +82,7 @@

INFO_TRANSFORMATIONS = {
'rating': lambda r: r / 10,
'playcount': lambda w: int(w)
'playcount': lambda w: int(w) # pylint: disable=unnecessary-lambda
}

REFERENCE_MAPPINGS = {
Expand Down Expand Up @@ -122,7 +121,7 @@ def iterate_references(source):

def count_references(source):
counter = 0
for index, ref in sorted({int(k): v
for index, ref in sorted({int(k): v # pylint: disable=unused-variable
for k, v in source.iteritems()
if common.is_numeric(k)}.iteritems()):
path = reference_path(ref)
Expand Down
17 changes: 8 additions & 9 deletions resources/lib/api/shakti.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Access to Netflix's Shakti API"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

from functools import wraps

Expand All @@ -15,8 +15,7 @@
SEASONS_PARTIAL_PATHS, EPISODES_PARTIAL_PATHS, ART_PARTIAL_PATHS,
GENRE_PARTIAL_PATHS, RANGE_SELECTOR, MAX_PATH_REQUEST_SIZE,
TRAILER_PARTIAL_PATHS)
from .exceptions import (InvalidVideoListTypeError, LoginFailedError, APIError,
NotLoggedInError, MissingCredentialsError)
from .exceptions import (InvalidVideoListTypeError, APIError, MissingCredentialsError)


def catch_api_errors(func):
Expand Down Expand Up @@ -269,12 +268,12 @@ def mylist_items():
"""Return a list of all the items currently contained in my list"""
common.debug('Try to perform a request to get the id list of the videos in my list')
try:
mylist_items = []
video_list = custom_video_list_basicinfo(list_id_for_type(g.MAIN_MENU_ITEMS['myList']['lolomo_contexts'][0]))
if video_list:
mylist_items = [video_id for video_id, video in video_list.videos.iteritems()
if video['queue'].get('inQueue', False)]
return mylist_items
items = []
videos = custom_video_list_basicinfo(list_id_for_type(g.MAIN_MENU_ITEMS['myList']['lolomo_contexts'][0]))
if videos:
items = [video_id for video_id, video in videos.videos.iteritems()
if video['queue'].get('inQueue', False)]
return items
except InvalidVideoListTypeError:
return []

Expand Down
4 changes: 2 additions & 2 deletions resources/lib/api/website.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Parsing of Netflix Website"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

import json
import traceback
Expand All @@ -12,7 +12,7 @@
from resources.lib.database.db_utils import (TABLE_SESSION)
from resources.lib.globals import g
from .paths import resolve_refs
from .exceptions import (InvalidProfilesError, InvalidAuthURLError, InvalidMembershipStatusError,
from .exceptions import (InvalidProfilesError, InvalidAuthURLError,
WebsiteParsingError, LoginValidateError)

PAGE_ITEMS_INFO = [
Expand Down
26 changes: 11 additions & 15 deletions resources/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
resources.lib.kodi.ui
resources.lib.services.nfsession
"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

import os
import sys
from time import time
from functools import wraps
try:
Expand Down Expand Up @@ -50,16 +49,13 @@ class UnknownCacheBucketError(Exception):
pass


'''
Logic to get the identifier
cache_output: called without params, use the first argument value of the function as identifier
cache_output: with identify_from_kwarg_name specified - get value identifier from kwarg name specified, if None value fallback to first function argument value

identify_append_from_kwarg_name - if specified append the value after the kwarg identify_from_kwarg_name, to creates a more specific identifier
identify_fallback_arg_index - to change the default fallback arg index (0), where the identifier get the value from the func arguments
fixed_identifier - note if specified all other params are ignored
'''
# Logic to get the identifier
# cache_output: called without params, use the first argument value of the function as identifier
# cache_output: with identify_from_kwarg_name, get value identifier from kwarg name specified, if None value fallback to first function argument value

# identify_append_from_kwarg_name - if specified append the value after the kwarg identify_from_kwarg_name, to creates a more specific identifier
# identify_fallback_arg_index - to change the default fallback arg index (0), where the identifier get the value from the func arguments
# fixed_identifier - note if specified all other params are ignored

def cache_output(g, bucket, fixed_identifier=None,
identify_from_kwarg_name='videoid',
Expand Down Expand Up @@ -104,7 +100,7 @@ def _get_identifier(fixed_identifier, identify_from_kwarg_name,
identifier = kwargs.get(identify_from_kwarg_name)
if identifier and identify_append_from_kwarg_name and kwargs.get(identify_append_from_kwarg_name):
identifier = identifier + '_' + kwargs.get(identify_append_from_kwarg_name)
if not identifier and len(args) > 0:
if not identifier and args:
identifier = args[identify_fallback_arg_index]
# common.debug('Get_identifier identifier value: {}'.format(identifier if identifier else 'None'))
return identifier
Expand Down Expand Up @@ -151,7 +147,7 @@ def __init__(self, common, cache_path, ttl, metadata_ttl, plugin_handle):
self.buckets = {}
self.window = xbmcgui.Window(10000)

def lock_marker(self, bucket):
def lock_marker(self):
"""Return a lock marker for this instance and the current time"""
# Return maximum timestamp for library to prevent stale lock
# overrides which may lead to inconsistencies
Expand Down Expand Up @@ -257,7 +253,7 @@ def _load_bucket_from_wndprop(self, bucket, wnd_property):

def _lock(self, bucket):
self.window.setProperty(_window_property(bucket),
self.lock_marker(bucket))
self.lock_marker())

def _get_from_disk(self, bucket, identifier):
"""Load a cache entry from disk and add it to the in memory bucket"""
Expand Down Expand Up @@ -308,7 +304,7 @@ def is_safe_to_persist(self, bucket):
# Only persist if we acquired the original lock or if the lock is older
# than 15 seconds (override stale locks)
lock = self.window.getProperty(_window_property(bucket))
is_own_lock = lock[:14] == self.lock_marker(bucket)[:14]
is_own_lock = lock[:14] == self.lock_marker()[:14]
try:
is_stale_lock = int(lock[18:] or 1) <= time() - 15
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# pylint: disable=wildcard-import, wrong-import-position
"""Common plugin operations and utilities"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

from .logging import *
from .ipc import *
Expand Down
3 changes: 1 addition & 2 deletions resources/lib/common/cookies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
"""Persistent cookie management"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

import os
from time import time
try:
import cPickle as pickle
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/common/credentials.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
"""Handling of account credentials"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

from resources.lib.globals import g
from resources.lib.api.exceptions import MissingCredentialsError

from .logging import debug, error
from .logging import error

__BLOCK_SIZE__ = 32
__CRYPT_KEY__ = None
Expand Down Expand Up @@ -106,7 +106,7 @@ def check_credentials():
decrypt_credential(email)
decrypt_credential(password)
return True
except Exception:
except Exception: # pylint: disable=broad-except
pass
return False

Expand Down
3 changes: 1 addition & 2 deletions resources/lib/common/data_conversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# pylint: disable=unused-import
"""Data type conversion"""
from __future__ import unicode_literals
from __future__ import absolute_import, division, unicode_literals

import json
import datetime
Expand Down
Loading