From 56e669fa6f37112f928919198e7f6cec7c3c0f3c Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 23 Oct 2020 00:47:12 +0200 Subject: Make PEP8 happy --- README.md | 9 ++++++++- gui.py | 4 ++-- moodle.py | 13 +++++++++++-- muddle.py | 11 ++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4f45bd2..b7a0f0b 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,14 @@ muddle $ ./muddle --gui The code is a bit garbage, as I hacked it toghether in one morning, though I've tried to clean it up a bit. -## Compilation / Release +### Coding style + +Use PEP8 except where Qt bindings are used (`gui.py`). To check use +``` +$ pep8 --show-source --ignore=E501 moodle.py muddle.py +``` + +### Compilation / Release To create an executable you need PyInstaller, you can get it with ``` $ pip3 install pyinstaller diff --git a/gui.py b/gui.py index 32d4a9e..eb5fe86 100644 --- a/gui.py +++ b/gui.py @@ -111,7 +111,7 @@ class MoodleFetcher(QThread): sectionsReq = self.api.core_course_get_contents(courseid = str(course["id"])) if not sectionsReq: - return + return [] sections = sectionsReq.json() return sections @@ -150,7 +150,7 @@ class MoodleTreeView(QTreeWidget): @pyqtSlot(QTreeWidgetItem, int) def onItemDoubleClicked(self, item, col): log.debug(f"double clicked on item with type {str(item.metadata.type)}") - if item.type == MoodleItem.Type.FILE: + if item.metadata.type == MoodleItem.Type.FILE: # TODO: download in a temp folder and open pass diff --git a/moodle.py b/moodle.py index 5d0f9bd..7f3ccf5 100644 --- a/moodle.py +++ b/moodle.py @@ -7,15 +7,22 @@ log = logging.getLogger("muddle.moodle") # # magic moodle api wrapper # + + def request_token(url, user, password): token_url = f"{url}/login/token.php" - data = { "username": user, "password": password, "service": "moodle_mobile_app" } + data = { + "username": user, + "password": password, + "service": "moodle_mobile_app" + } log.debug(f"requesting token with POST to {api_url} with DATA {data}") return requests.post(token_url, data=data) + def api_call(url, token, function, **kwargs): api_url = f"{url}/webservice/rest/server.php?moodlewsrestformat=json" - data = { "wstoken": token, "wsfunction": function } + data = {"wstoken": token, "wsfunction": function} for k, v in kwargs.items(): data[str(k)] = v @@ -31,6 +38,7 @@ def api_call(url, token, function, **kwargs): log.error(f"Failed to connect for POST request:\n{str(e)}") return None + class RestApi: def __init__(self, instance_url, token): self._url = instance_url @@ -39,6 +47,7 @@ class RestApi: def __getattr__(self, key): return lambda **kwargs: api_call(self._url, self._token, str(key), **kwargs) + class ApiHelper: def __init__(self, api): self.api = api diff --git a/muddle.py b/muddle.py index b4e4311..b1dc7f1 100644 --- a/muddle.py +++ b/muddle.py @@ -36,14 +36,15 @@ log.setLevel(logging.DEBUG) if args.verbose: cli_handler = colorlog.StreamHandler() cli_handler.setLevel(logging.DEBUG) - cli_formatter = colorlog.ColoredFormatter("%(name)-13s - %(log_color)s%(levelname)-8s%(reset)s: %(message)s", + cli_formatter = colorlog.ColoredFormatter( + "%(name)-13s - %(log_color)s%(levelname)-8s%(reset)s: %(message)s", datefmt=None, reset=True, log_colors={ - 'DEBUG': 'cyan', - 'INFO': 'green', - 'WARNING': 'yellow', - 'ERROR': 'red', + 'DEBUG': 'cyan', + 'INFO': 'green', + 'WARNING': 'yellow', + 'ERROR': 'red', 'CRITICAL': 'red,bg_white', } ) -- cgit v1.2.1