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

Add docstrings #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions kodi_addon_checker/addons/Addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


class Addon():
"""Gather all the dependencies of an addon
"""
def __init__(self, addon_xml: ET.Element):
super().__init__()
self.id = addon_xml.get('id')
Expand All @@ -21,9 +23,19 @@ def __init__(self, addon_xml: ET.Element):
self.dependencies.append(AddonDependency(dependency))

def __eq__(self, other):
"""Check if the addon and it's version is equivalent or not.

This compares instances of two addons
"""
return self.id == other.id and self.version == other.version

def dependsOn(self, addonId):
"""Check if addon is dependent on any other addon.

Arguments:
addonId {str} -- Id of addon whose dependencies
are to be looked
"""
for dependency in self.dependencies:
if dependency.id == addonId:
return True
Expand Down
2 changes: 2 additions & 0 deletions kodi_addon_checker/addons/AddonDependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from ..versions import AddonVersion

class AddonDependency():
"""Get the minimum version of the dependency of an addon
"""
def __init__(self, import_xml: ET.Element):
super().__init__()
self.id = import_xml.get('addon')
Expand Down
19 changes: 19 additions & 0 deletions kodi_addon_checker/addons/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class Repository():
"""Get information of all the addons
"""
def __init__(self, version, path):
super().__init__()
self.version = version
Expand All @@ -40,12 +42,23 @@ def __init__(self, version, path):
self.addons.append(Addon(addon))

def __contains__(self, addonId):
"""Check if addon is present in the list or not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

present in the repository


Arguments:
addonId {str} -- Id of addon that is to be looked for
"""
for addon in self.addons:
if addon.id == addonId:
return True
return False

def find(self, addonId):
"""If the addon exists in the list then return it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the repository


Arguments:
addonId {str} -- Id of addon that is to be looked for
"""

# multiple copies of the same addon might exist on the repository, however
# kodi always uses the highest version available
addon_instances = []
Expand All @@ -61,6 +74,12 @@ def find(self, addonId):
return addon_instances[0]

def rdepends(self, addonId):
"""Check if addon is dependent on any other addon.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this function returns the reverse dependencies for a specific addon.


Arguments:
addonId {str} -- Id of addon whose dependencies
are to be looked
"""
rdepends = []
for addon in self.addons:
if addon.dependsOn(addonId):
Expand Down
5 changes: 5 additions & 0 deletions kodi_addon_checker/check_py3_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@


class KodiRefactoringTool(refactor.RefactoringTool):
"""Report possible refactoring error detected by lib2to3

Extends:
refactor.RefactoringTool
"""

def __init__(self, report, log_level, *args, **kwargs):
self.report = report
Expand Down
19 changes: 18 additions & 1 deletion kodi_addon_checker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@


class Config():
"""Create Config object using .tests-config.json and command line arguments.
"""
def __init__(self, repo_path, cmd_args=None):
"""
Create Config object using .tests-config.json and command line arguments.
:param repo_path: the repo path which contains .tests-config.json.
:param cmd_args: argparse object
"""
self.configs = {} if cmd_args is None else vars(cmd_args)
self._load_config(repo_path)

def _load_config(self, repo_path):
"""Load the config file

Arguments:
repo_path {str} -- the repo path which contains .tests-config.json.
"""
if repo_path is None:
return
config_path = os.path.join(repo_path, '.tests-config.json')
Expand All @@ -37,28 +43,39 @@ def _load_config(self, repo_path):
self.configs = file_config

def is_enabled(self, value):
"""Check if the certain value in the
config file is enabled or not
"""
return self.configs.get(value, False)

def __getitem__(self, item):
return self.configs.get(item)


class ConfigManager():
"""Manages Config file
"""
configurations = {}

@classmethod
def register(cls, config, description, default_value, action):
"""registers all the config
"""
cls.configurations[config] = [description, default_value, action]

@classmethod
def fill_cmd_args(cls, parser: ArgumentParser):
"""Add an argument for the reporter
"""
# Add --reporter
parser.add_argument("--reporter", action="append", choices=list(ReportManager.reporters.keys()),
help="""enable a reporter with the given name.
You can use this option multiple times to enable more than one reporters""")

@classmethod
def process_config(cls, config):
"""Get the reporters
"""
reporters = config["reporter"]
if reporters is not None:
# To disable all, pass empty array in .tests-config.json
Expand Down
2 changes: 2 additions & 0 deletions kodi_addon_checker/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


class Logger:
"""Logger class the provokes the create_logger function.
"""

@staticmethod
def create_logger(debug_filename, logger_name, enabled=False):
Expand Down
5 changes: 5 additions & 0 deletions kodi_addon_checker/plugins/array_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

@reporter(name="array", enabled=False)
class ArrayReporter(Reporter):
"""Setup array report for Reporter class

Extends:
Reporter
"""
def __init__(self):
self.reports = []

Expand Down
5 changes: 5 additions & 0 deletions kodi_addon_checker/plugins/log_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

@reporter(name="log", enabled=False)
class LogReporter(Reporter):
"""Report logs to the log file

Extends:
Reporter
"""

def __init__(self):
self.logger = None
Expand Down
3 changes: 2 additions & 1 deletion kodi_addon_checker/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@


class Record():
"""Create a record which is the low level entry in Report to represent logs.
"""
def __init__(self, log_level, message):
"""
Create a record which is the low level entry in Report to represent logs.
:param log_level: "ERROR", "WARN" or "INFO"
:param message: the actual log message
"""
Expand Down
6 changes: 2 additions & 4 deletions kodi_addon_checker/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@


class Report():
"""Create a new report for the given artifact. The artifact can be a repo, add-on or file.
"""
def __init__(self, artifact_name):
"""
Create a new report for the given artifact. The artifact can be a repo, add-on or file.
:param artifact_name: the artifact name
"""
self.artifact_name = artifact_name
self.problem_count = 0
self.warning_count = 0
Expand Down
8 changes: 8 additions & 0 deletions kodi_addon_checker/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ def report(self, report):


class ReportManager():
"""Manage all the reporters
"""
reporters = {}

@classmethod
def register(cls, reporter_clazz: Reporter, name, enabled):
"""Register the reporters
"""
cls.reporters[name] = [reporter_clazz(), enabled]

@classmethod
Expand All @@ -35,10 +39,14 @@ def enable(cls, names):

@classmethod
def getEnabledReporters(cls):
"""Get all the reporters that are enabled
"""
return [reporter[0] for reporter in cls.reporters.values() if reporter[1]]


def reporter(name, enabled=False):
"""Report all the enabled reporters to ReportManager
"""
def _reporter(clazz):
if inspect.isclass(clazz):
if not hasattr(clazz, "report") or len(inspect.signature(getattr(clazz, "report")).parameters.items()) != 2:
Expand Down
12 changes: 12 additions & 0 deletions kodi_addon_checker/schema_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ def _validate(xml, schemapath):


def check_version(branch_name, schema_file):
"""Check whether the schema files for the specific
branch exists or not and if not then return the
highest available variant of the schema file or None

Arguments:
branch_name {str} -- Name of the branch the schema
is being validated of
schema_file {str} -- Schema file to look for.

Returns:
[str] -- full path to the schema file.
"""
all_branches = ValidKodiVersions[::-1]
branches = all_branches[all_branches.index(branch_name)::1]
for branch in branches:
Expand Down