From a8043d025948fd54d13dda0fb7e42e9cfa996e87 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sat, 6 Apr 2019 22:59:51 -0400 Subject: [PATCH 1/6] Add flake8-docstrings to tox.ini --- tox.ini | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tox.ini b/tox.ini index 56d21272..2111ddc6 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,22 @@ ignore = ; E501 line too long E501 +; -- flake8-docstrings -- +; D100 Missing docstring in public module +; D101 Missing docstring in public class +; D102 Missing docstring in public method +; D103 Missing docstring in public function +; D104 Missing docstring in public package +; D105 Missing docstring in magic method +; D107 Missing docstring in __init__ +; D200 One-line docstring should fit on one line with quotes +; D202 No blank lines allowed after function docstring +; D205 1 blank line required between summary line and description +; D400 First line should end with a period +; D401 First line should be in imperative mood +; D402 First line should not be the function's "signature" + D100, D101, D102, D103, D104, D105, D107 + per-file-ignores = ; F401 imported but unused ; E402 module level import not at top of file @@ -51,6 +67,7 @@ deps = flake8 flake8-commas flake8-comprehensions + flake8-docstrings flake8-quotes skip_install = true commands = From 4dd58afaf60ac4b8c9cc42a7b7459084ded60521 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 14:45:48 -0400 Subject: [PATCH 2/6] Fix flake8-docstrings D200 One-line docstring should fit on one line with quotes --- core/github_api.py | 8 ++------ core/logger.py | 4 +--- core/version_check.py | 8 ++------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/core/github_api.py b/core/github_api.py index 6e44f9f3..b6fb0856 100644 --- a/core/github_api.py +++ b/core/github_api.py @@ -4,9 +4,7 @@ import requests class GitHub(object): - """ - Simple api wrapper for the Github API v3. - """ + """Simple api wrapper for the Github API v3.""" def __init__(self, github_repo_user, github_repo, branch='master'): @@ -15,9 +13,7 @@ class GitHub(object): self.branch = branch def _access_api(self, path, params=None): - """ - Access the API at the path given and with the optional params given. - """ + """Access API at given an API path and optional parameters.""" url = 'https://api.github.com/{path}'.format(path='/'.join(path)) data = requests.get(url, params=params, verify=False) return data.json() if data.ok else [] diff --git a/core/logger.py b/core/logger.py index f7fbf9c4..701881cf 100644 --- a/core/logger.py +++ b/core/logger.py @@ -111,9 +111,7 @@ class NTMRotatingLogHandler(object): self.close_log(old_handler) def _config_handler(self): - """ - Configure a file handler to log at file_name and return it. - """ + """Configure a file handler to log at file_name and return it.""" file_handler = logging.FileHandler(self.log_file_path, encoding='utf-8') diff --git a/core/version_check.py b/core/version_check.py index d865b9f3..b39a8b08 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -19,9 +19,7 @@ from core import github_api as github, logger class CheckVersion(object): - """ - Version check class meant to run as a thread object with the SB scheduler. - """ + """Version checker that runs in a thread with the SB scheduler.""" def __init__(self): self.install_type = self.find_install_type() @@ -435,9 +433,7 @@ class SourceUpdateManager(UpdateManager): return def update(self): - """ - Downloads the latest source tarball from github and installs it over the existing version. - """ + """Download and install latest source tarball from github.""" tar_download_url = 'https://github.com/{org}/{repo}/tarball/{branch}'.format( org=self.github_repo_user, repo=self.github_repo, branch=self.branch) version_path = os.path.join(core.APP_ROOT, u'version.txt') From 777bc7e35d821cb26c89c2828d54c64aae805d5a Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 14:48:25 -0400 Subject: [PATCH 3/6] Fix flake8-docstrings D202 No blank lines allowed after function docstring --- core/logger.py | 3 --- core/utils/naming.py | 2 -- core/version_check.py | 6 ------ 3 files changed, 11 deletions(-) diff --git a/core/logger.py b/core/logger.py index 701881cf..243e3bde 100644 --- a/core/logger.py +++ b/core/logger.py @@ -112,7 +112,6 @@ class NTMRotatingLogHandler(object): def _config_handler(self): """Configure a file handler to log at file_name and return it.""" - file_handler = logging.FileHandler(self.log_file_path, encoding='utf-8') file_handler.setLevel(DB) @@ -133,7 +132,6 @@ class NTMRotatingLogHandler(object): i: Log number to ues """ - return self.log_file_path + ('.{0}'.format(i) if i else '') def _num_logs(self): @@ -142,7 +140,6 @@ class NTMRotatingLogHandler(object): Returns: The number of the last used file (eg. mylog.log.3 would return 3). If there are no logs it returns -1 """ - cur_log = 0 while os.path.isfile(self._log_file_name(cur_log)): cur_log += 1 diff --git a/core/utils/naming.py b/core/utils/naming.py index b54e3258..27ea8c02 100644 --- a/core/utils/naming.py +++ b/core/utils/naming.py @@ -12,7 +12,6 @@ def sanitize_name(name): >>> sanitize_name('.a.b..') 'a.b' """ - # remove bad chars from the filename name = re.sub(r'[\\/*]', '-', name) name = re.sub(r'[:\'<>|?]', '', name) @@ -34,7 +33,6 @@ def clean_file_name(filename): Is basically equivalent to replacing all _ and . with a space, but handles decimal numbers in string, for example: """ - filename = re.sub(r'(\D)\.(?!\s)(\D)', r'\1 \2', filename) filename = re.sub(r'(\d)\.(\d{4})', r'\1 \2', filename) # if it ends in a year then don't keep the dot filename = re.sub(r'(\D)\.(?!\s)', r'\1 ', filename) diff --git a/core/version_check.py b/core/version_check.py index b39a8b08..a5c98abf 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -45,7 +45,6 @@ class CheckVersion(object): 'git': running from source using git 'source': running from source without git """ - # check if we're a windows build if os.path.isdir(os.path.join(core.APP_ROOT, u'.git')): install_type = 'git' @@ -62,7 +61,6 @@ class CheckVersion(object): force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced """ - if not core.VERSION_NOTIFY and not force: logger.log(u'Version checking is disabled, not checking for the newest version') return False @@ -215,7 +213,6 @@ class GitUpdateManager(UpdateManager): Returns: True for success or False for failure """ - output, err, exit_status = self._run_git(self._git_path, 'rev-parse HEAD') # @UnusedVariable if exit_status == 0 and output: @@ -245,7 +242,6 @@ class GitUpdateManager(UpdateManager): Uses git commands to check if there is a newer version that the provided commit hash. If there is a newer version it sets _num_commits_behind. """ - self._newest_commit_hash = None self._num_commits_behind = 0 self._num_commits_ahead = 0 @@ -325,7 +321,6 @@ class GitUpdateManager(UpdateManager): Calls git pull origin in order to update Sick Beard. Returns a bool depending on the call's success. """ - output, err, exit_status = self._run_git(self._git_path, 'pull origin {branch}'.format(branch=self.branch)) # @UnusedVariable if exit_status == 0: @@ -385,7 +380,6 @@ class SourceUpdateManager(UpdateManager): commit_hash: hash that we're checking against """ - self._num_commits_behind = 0 self._newest_commit_hash = None From 1d7dba8aebb9078e3c68aecbd6fd63bc3be94266 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 15:02:50 -0400 Subject: [PATCH 4/6] Fix flake8-docstrings D205 1 blank line required between summary line and description --- core/logger.py | 6 ++++-- core/main_db.py | 2 ++ core/utils/naming.py | 7 ++++--- core/version_check.py | 20 ++++++++++++++------ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/core/logger.py b/core/logger.py index 243e3bde..c569bfb3 100644 --- a/core/logger.py +++ b/core/logger.py @@ -127,8 +127,10 @@ class NTMRotatingLogHandler(object): def _log_file_name(self, i): """ - Returns a numbered log file name depending on i. If i==0 it just uses logName, if not it appends - it to the extension (blah.log.3 for i == 3) + Returns a numbered log file name depending on i. + + If i==0 it just uses logName, if not it appends it to the extension + e.g. (blah.log.3 for i == 3) i: Log number to ues """ diff --git a/core/main_db.py b/core/main_db.py index 241b3adf..14a75d21 100644 --- a/core/main_db.py +++ b/core/main_db.py @@ -14,6 +14,8 @@ from core import logger def db_filename(filename='nzbtomedia.db', suffix=None): """ + Return the correct location of the database file. + @param filename: The sqlite database filename to use. If not specified, will be made to be nzbtomedia.db @param suffix: The suffix to append to the filename. A '.' will be added diff --git a/core/utils/naming.py b/core/utils/naming.py index 27ea8c02..964fb6fd 100644 --- a/core/utils/naming.py +++ b/core/utils/naming.py @@ -3,6 +3,8 @@ import re def sanitize_name(name): """ + Remove bad chars from the filename. + >>> sanitize_name('a/b/c') 'a-b-c' >>> sanitize_name('abc') @@ -12,7 +14,6 @@ def sanitize_name(name): >>> sanitize_name('.a.b..') 'a.b' """ - # remove bad chars from the filename name = re.sub(r'[\\/*]', '-', name) name = re.sub(r'[:\'<>|?]', '', name) @@ -27,8 +28,8 @@ def sanitize_name(name): def clean_file_name(filename): - """Cleans up nzb name by removing any . and _ - characters, along with any trailing hyphens. + """ + Cleans up nzb name by removing any . and _ characters and trailing hyphens. Is basically equivalent to replacing all _ and . with a space, but handles decimal numbers in string, for example: diff --git a/core/version_check.py b/core/version_check.py index a5c98abf..ac7fdd6d 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -239,8 +239,11 @@ class GitUpdateManager(UpdateManager): def _check_github_for_update(self): """ - Uses git commands to check if there is a newer version that the provided - commit hash. If there is a newer version it sets _num_commits_behind. + Check Github for a new version. + + Uses git commands to check if there is a newer version than + the provided commit hash. If there is a newer version it + sets _num_commits_behind. """ self._newest_commit_hash = None self._num_commits_behind = 0 @@ -318,8 +321,10 @@ class GitUpdateManager(UpdateManager): def update(self): """ - Calls git pull origin in order to update Sick Beard. Returns a bool depending - on the call's success. + Check git for a new version. + + Calls git pull origin in order to update Sick Beard. + Returns a bool depending on the call's success. """ output, err, exit_status = self._run_git(self._git_path, 'pull origin {branch}'.format(branch=self.branch)) # @UnusedVariable @@ -375,8 +380,11 @@ class SourceUpdateManager(UpdateManager): def _check_github_for_update(self): """ - Uses pygithub to ask github if there is a newer version that the provided - commit hash. If there is a newer version it sets Sick Beard's version text. + Check Github for a new version. + + Uses pygithub to ask github if there is a newer version than + the provided commit hash. If there is a newer version it sets + Sick Beard's version text. commit_hash: hash that we're checking against """ From 6f6c9bcc9d5732d543550b7c9eb57e0068564faa Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 15:16:06 -0400 Subject: [PATCH 5/6] Fix flake8-docstrings D400 First line should end with a period --- core/logger.py | 2 +- core/utils/files.py | 2 +- core/utils/paths.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/logger.py b/core/logger.py index c569bfb3..dba98947 100644 --- a/core/logger.py +++ b/core/logger.py @@ -138,7 +138,7 @@ class NTMRotatingLogHandler(object): def _num_logs(self): """ - Scans the log folder and figures out how many log files there are already on disk + Scans the log folder and figures out how many log files there are already on disk. Returns: The number of the last used file (eg. mylog.log.3 would return 3). If there are no logs it returns -1 """ diff --git a/core/utils/files.py b/core/utils/files.py index 895125e1..edb968ae 100644 --- a/core/utils/files.py +++ b/core/utils/files.py @@ -88,7 +88,7 @@ def is_min_size(input_name, min_size): def is_archive_file(filename): - """Check if the filename is allowed for the Archive""" + """Check if the filename is allowed for the Archive.""" for regext in core.COMPRESSED_CONTAINER: if regext.search(filename): return regext.split(filename)[0] diff --git a/core/utils/paths.py b/core/utils/paths.py index fe049ae7..cdb2c3ff 100644 --- a/core/utils/paths.py +++ b/core/utils/paths.py @@ -74,7 +74,7 @@ def get_dir_size(input_path): def remove_empty_folders(path, remove_root=True): - """Function to remove empty folders""" + """Function to remove empty folders.""" if not os.path.isdir(path): return From 10b2eab3c571b42fef29b3f5531a23375f980075 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 15:20:23 -0400 Subject: [PATCH 6/6] Fix flake8-docstrings D401 First line should be in imperative mood --- core/github_api.py | 4 ++-- core/logger.py | 4 ++-- core/utils/naming.py | 2 +- core/utils/paths.py | 2 +- core/version_check.py | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/github_api.py b/core/github_api.py index b6fb0856..b1a4f566 100644 --- a/core/github_api.py +++ b/core/github_api.py @@ -20,7 +20,7 @@ class GitHub(object): def commits(self): """ - Uses the API to get a list of the 100 most recent commits from the specified user/repo/branch, starting from HEAD. + Get the 100 most recent commits from the specified user/repo/branch, starting from HEAD. user: The github username of the person whose repo you're querying repo: The repo name to query @@ -35,7 +35,7 @@ class GitHub(object): def compare(self, base, head, per_page=1): """ - Uses the API to get a list of compares between base and head. + Get compares between base and head. user: The github username of the person whose repo you're querying repo: The repo name to query diff --git a/core/logger.py b/core/logger.py index dba98947..df5a5120 100644 --- a/core/logger.py +++ b/core/logger.py @@ -127,7 +127,7 @@ class NTMRotatingLogHandler(object): def _log_file_name(self, i): """ - Returns a numbered log file name depending on i. + Return a numbered log file name depending on i. If i==0 it just uses logName, if not it appends it to the extension e.g. (blah.log.3 for i == 3) @@ -138,7 +138,7 @@ class NTMRotatingLogHandler(object): def _num_logs(self): """ - Scans the log folder and figures out how many log files there are already on disk. + Scan the log folder and figure out how many log files there are already on disk. Returns: The number of the last used file (eg. mylog.log.3 would return 3). If there are no logs it returns -1 """ diff --git a/core/utils/naming.py b/core/utils/naming.py index 964fb6fd..64cd6d70 100644 --- a/core/utils/naming.py +++ b/core/utils/naming.py @@ -29,7 +29,7 @@ def sanitize_name(name): def clean_file_name(filename): """ - Cleans up nzb name by removing any . and _ characters and trailing hyphens. + Clean up nzb name by removing any . and _ characters and trailing hyphens. Is basically equivalent to replacing all _ and . with a space, but handles decimal numbers in string, for example: diff --git a/core/utils/paths.py b/core/utils/paths.py index cdb2c3ff..a2a96996 100644 --- a/core/utils/paths.py +++ b/core/utils/paths.py @@ -74,7 +74,7 @@ def get_dir_size(input_path): def remove_empty_folders(path, remove_root=True): - """Function to remove empty folders.""" + """Remove empty folders.""" if not os.path.isdir(path): return diff --git a/core/version_check.py b/core/version_check.py index ac7fdd6d..23384a44 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -38,7 +38,7 @@ class CheckVersion(object): def find_install_type(self): """ - Determines how this copy of SB was installed. + Determine how this copy of SB was installed. returns: type of installation. Possible values are: 'win': any compiled windows build @@ -55,7 +55,7 @@ class CheckVersion(object): def check_for_new_version(self, force=False): """ - Checks the internet for a newer version. + Check the internet for a newer version. returns: bool, True for new version or False for no new version. @@ -207,7 +207,7 @@ class GitUpdateManager(UpdateManager): def _find_installed_version(self): """ - Attempts to find the currently installed version of Sick Beard. + Attempt to find the currently installed version of Sick Beard. Uses git show to get commit version.