Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mzfr authored and mzfr committed Mar 19, 2019
1 parent 8ab6f49 commit 3b4a7e5
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 7 deletions.
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():
"""Returns all the dependencies of an addon
"""
def __init__(self, addon_xml: ET.Element):
super(Addon, self).__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 @@ -11,6 +11,8 @@


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


class Repository():
"""Get information of all the addons
"""
def __init__(self, version, path):
super(Repository, self).__init__()
self.version = version
Expand All @@ -29,18 +31,34 @@ def __init__(self, version, path):
self.addons.append(Addon(addon))

def __contains__(self, addonId):
"""Check if addon is present in the list or not
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
Arguments:
addonId {str} -- Id of addon that is to be looked for
"""
for addon in self.addons:
if addon.id == addonId:
return addon
return None

def rdepends(self, addonId):
"""Check if addon is dependent on any other 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 @@ -15,6 +15,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
3 changes: 2 additions & 1 deletion kodi_addon_checker/check_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def check_url(report: Report, parsed_xml):
report.add(Record(WARNING, "{} redirects to {}".format(source.text, r.url)))
r.raise_for_status()
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout, requests.exceptions.HTTPError,
requests.exceptions.MissingSchema, requests.exceptions.ReadTimeout, requests.exceptions.SSLError) as e:
requests.exceptions.MissingSchema, requests.exceptions.ReadTimeout, requests.exceptions.SSLError
) as e:
report.add(Record(WARNING, e))
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):
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):
log_file_name = os.path.join(os.getcwd(), "kodi-addon-checker-report.log")
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,10 +12,11 @@


class Record():
"""Create a record which is the low level entry in Report to represent logs.
"""
def __init__(self, log_level, message, start_line=-1, end_line=-1, start_char_position=-1,
end_char_position=-1):
"""
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
:param start_line: for text files, provide the start line of issue
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 @@ -115,6 +115,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
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 = ['leia', 'krypton', 'jarvis', 'isengard', 'helix', 'gotham']
branches = all_branches[all_branches.index(branch_name)::1]
for branch in branches:
Expand Down

0 comments on commit 3b4a7e5

Please sign in to comment.