Resolve pylint warnings for rascsi-web (#579)

* Add venv hook to .pylintrc

* Add to readme about pylint-venv

* Resolve pylint warnings

* Flesh out readme
This commit is contained in:
Daniel Markstedt
2021-12-28 12:09:47 -08:00
committed by GitHub
parent 9385483624
commit fecdc44629
6 changed files with 72 additions and 34 deletions

View File

@@ -15,7 +15,14 @@ ignore-patterns=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
init-hook=
# venv hook for pylint
# Requires pylint-venv package:
# $ pip install pylint-venv
try: import pylint_venv
except ImportError: pass
else: pylint_venv.inithook()
# Use multiple processes to speed up Pylint.
jobs=1

View File

@@ -24,9 +24,12 @@ A separate mocking solution will be needed for this interface.
It is recommended to run pylint against new code to protect against bugs
and keep the code readable and maintainable.
The local pylint configuration lives in .pylintrc
In order for pylint to recognize venv libraries, the pylint-venv package is required.
```
sudo apt install pylint3
sudo pip install pylint-venv
source venv/bin/activate
pylint3 python_source_file.py
```

View File

@@ -300,18 +300,16 @@ def download_file_to_iso(url, *iso_args):
delete_file(tmp_full_path)
try:
iso_proc = (
run(
[
"genisoimage",
*iso_args,
"-o",
iso_filename,
tmp_dir,
],
capture_output=True,
check=True,
)
run(
[
"genisoimage",
*iso_args,
"-o",
iso_filename,
tmp_dir,
],
capture_output=True,
check=True,
)
except CalledProcessError as error:
logging.warning("Executed shell command: %s", " ".join(error.cmd))
@@ -320,7 +318,10 @@ def download_file_to_iso(url, *iso_args):
return {
"status": True,
"msg": _(u"Created CD-ROM ISO image with arguments \"%(value)s\"", value=" ".join(iso_args)),
"msg": _(
u"Created CD-ROM ISO image with arguments \"%(value)s\"",
value=" ".join(iso_args),
),
"file_name": iso_filename,
}
@@ -393,7 +394,10 @@ def write_config(file_name):
json_file,
indent=4
)
return {"status": True, "msg": _(u"Saved configuration file to %(file_name)s", file_name=file_name)}
return {
"status": True,
"msg": _(u"Saved configuration file to %(file_name)s", file_name=file_name),
}
except (IOError, ValueError, EOFError, TypeError) as error:
logging.error(str(error))
delete_file(file_name)

View File

@@ -2,11 +2,11 @@
Module for commands sent to the RaSCSI backend service.
"""
from settings import REMOVABLE_DEVICE_TYPES
from socket_cmds import send_pb_command
from flask import current_app, session
from flask_babel import _
import rascsi_interface_pb2 as proto
from settings import REMOVABLE_DEVICE_TYPES
from socket_cmds import send_pb_command
def get_server_info():

View File

@@ -3,9 +3,9 @@ Module for sending and receiving data over a socket connection with the RaSCSI b
"""
import logging
from time import sleep
from flask import abort
from flask_babel import _
from time import sleep
def send_pb_command(payload):
"""

View File

@@ -4,7 +4,6 @@ Module for the Flask app rendering and endpoints
import logging
import argparse
from sys import argv
from pathlib import Path
from functools import wraps
@@ -115,7 +114,13 @@ def index():
Sets up data structures for and renders the index page
"""
if not is_token_auth()["status"] and not APP.config["TOKEN"]:
abort(403, _(u"RaSCSI is password protected. Start the Web Interface with the --password parameter."))
abort(
403,
_(
u"RaSCSI is password protected. "
u"Start the Web Interface with the --password parameter."
),
)
locales = get_supported_locales()
server_info = get_server_info()
@@ -211,7 +216,13 @@ def drive_list():
return redirect(url_for("index"))
conf = process["conf"]
else:
flash(_("Could not read drive properties from %(properties_file)s", properties_file=drive_properties), "error")
flash(
_(
"Could not read drive properties from %(properties_file)s",
properties_file=drive_properties,
),
"error",
)
return redirect(url_for("index"))
hd_conf = []
@@ -275,7 +286,13 @@ def login():
if authenticate(str(username), str(password)):
session["username"] = request.form["username"]
return redirect(url_for("index"))
flash(_(u"You must log in with credentials for a user in the '%(group)s' group", group=AUTH_GROUP), "error")
flash(
_(
u"You must log in with credentials for a user in the '%(group)s' group",
group=AUTH_GROUP,
),
"error",
)
return redirect(url_for("index"))
@@ -413,7 +430,7 @@ def config_load():
flash(process['msg'], "error")
return redirect(url_for("index"))
elif "delete" in request.form:
if "delete" in request.form:
process = delete_file(f"{CFG_DIR}/{file_name}")
if process["status"]:
flash(process["msg"])
@@ -609,8 +626,8 @@ def detach():
id_number=scsi_id, unit_number=unit))
return redirect(url_for("index"))
flash(_(u"Failed to detach %(file_name)s from SCSI ID %(id_number)s LUN %(unit_number)s",
file_name=file_name, id_number=scsi_id, unit_number=unit), "error")
flash(_(u"Failed to detach SCSI ID %(id_number)s LUN %(unit_number)s",
id_number=scsi_id, unit_number=unit), "error")
flash(process["msg"], "error")
return redirect(url_for("index"))
@@ -630,8 +647,8 @@ def eject():
id_number=scsi_id, unit_number=unit))
return redirect(url_for("index"))
flash(_(u"Failed to eject %(file_name)s from SCSI ID %(id_number)s LUN %(unit_number)s",
file_name=file_name, id_number=scsi_id, unit_number=unit), "error")
flash(_(u"Failed to eject SCSI ID %(id_number)s LUN %(unit_number)s",
id_number=scsi_id, unit_number=unit), "error")
flash(process["msg"], "error")
return redirect(url_for("index"))
@@ -837,10 +854,14 @@ def upload_file():
if current_chunk + 1 == total_chunks:
# Validate the resulting file size after writing the last chunk
if path.getsize(save_path) != int(request.form["dztotalfilesize"]):
log.error("Finished transferring %s, "
"but it has a size mismatch with the original file."
"Got %s but we expected %s.",
file_object.filename, path.getsize(save_path), request.form['dztotalfilesize'])
log.error(
"Finished transferring %s, "
"but it has a size mismatch with the original file. "
"Got %s but we expected %s.",
file_object.filename,
path.getsize(save_path),
request.form['dztotalfilesize'],
)
return make_response(_(u"Transferred file corrupted!"), 500)
log.info("File %s has been uploaded successfully", file_object.filename)
@@ -973,6 +994,9 @@ def unzip():
@APP.route("/language", methods=["POST"])
def change_language():
"""
Changes the session language locale and refreshes the Flask app context
"""
locale = request.form.get("locale")
session["language"] = locale
refresh()
@@ -1013,9 +1037,9 @@ if __name__ == "__main__":
action="store",
help="Token password string for authenticating with RaSCSI",
)
args = parser.parse_args()
APP.config["TOKEN"] = args.password
arguments = parser.parse_args()
APP.config["TOKEN"] = arguments.password
import bjoern
print("Serving rascsi-web...")
bjoern.run(APP, "0.0.0.0", args.port)
bjoern.run(APP, "0.0.0.0", arguments.port)