mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-01 09:30:29 +00:00
Introduce flake8 checking - #58
This introduces flake8 and fixes a bunch of flake8 errors. flake8 is run with: ./venv/bin/flake8 plinth if you're using a python3 venv. We can eventually further integrate this with gitlab ci. https://salsa.debian.org/freedombox-team/plinth/issues/58 Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
d2e987ef3c
commit
ace339eabf
1
debian/control
vendored
1
debian/control
vendored
@ -29,6 +29,7 @@ Build-Depends:
|
||||
python3-django-axes (>= 3.0.3),
|
||||
python3-django-captcha,
|
||||
python3-django-stronghold (>= 0.3.0),
|
||||
python3-flake8,
|
||||
python3-gi,
|
||||
python3-paramiko,
|
||||
python3-psutil,
|
||||
|
||||
@ -66,7 +66,7 @@ def run_setup_and_exit(module_list, allow_install=True):
|
||||
error_code = 0
|
||||
try:
|
||||
setup.run_setup_on_modules(module_list, allow_install)
|
||||
except Exception as exception:
|
||||
except Exception:
|
||||
error_code = 1
|
||||
|
||||
sys.exit(error_code)
|
||||
|
||||
@ -26,4 +26,5 @@ class AppConfig(apps.AppConfig):
|
||||
|
||||
def ready(self):
|
||||
# Signals must be loaded for axes to get the login_failed signals
|
||||
# flake8: noqa
|
||||
from axes import signals # isort:skip pylint: disable=unused-import
|
||||
|
||||
@ -22,7 +22,6 @@ import collections
|
||||
import django
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
@ -157,7 +156,8 @@ def get_modules_to_load():
|
||||
# './setup.py install' has not been executed yet. Pickup files to load
|
||||
# from local module directories.
|
||||
directory = pathlib.Path(__file__).parent
|
||||
files = list(directory.glob('modules/*/data/etc/plinth/modules-enabled/*'))
|
||||
files = list(directory.glob(
|
||||
'modules/*/data/etc/plinth/modules-enabled/*'))
|
||||
|
||||
# Omit hidden files
|
||||
files = [
|
||||
|
||||
@ -28,7 +28,7 @@ def delete_tmp_backup_file(function):
|
||||
|
||||
def wrap(request, *args, **kwargs):
|
||||
path = request.session.get(SESSION_PATH_VARIABLE, None)
|
||||
if path:
|
||||
if path:
|
||||
if os.path.isfile(path):
|
||||
os.remove(path)
|
||||
del request.session[SESSION_PATH_VARIABLE]
|
||||
|
||||
@ -19,10 +19,8 @@ Forms for backups module.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
@ -204,9 +202,10 @@ class VerifySshHostkeyForm(forms.Form):
|
||||
stderr=subprocess.DEVNULL)
|
||||
keys = keyscan.stdout.decode().splitlines()
|
||||
# Generate user-friendly fingerprints of public keys
|
||||
keygen = subprocess.run(['ssh-keygen', '-l', '-f', '-'],
|
||||
input=keyscan.stdout,
|
||||
stdout=subprocess.PIPE)
|
||||
keygen = subprocess.run(
|
||||
['ssh-keygen', '-l', '-f', '-'],
|
||||
input=keyscan.stdout,
|
||||
stdout=subprocess.PIPE)
|
||||
fingerprints = keygen.stdout.decode().splitlines()
|
||||
|
||||
return zip(keys, fingerprints)
|
||||
|
||||
@ -23,8 +23,6 @@ from unittest.mock import MagicMock, call, patch
|
||||
import pytest
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
|
||||
from plinth import cfg, module_loader
|
||||
|
||||
from .. import ROOT_REPOSITORY, api, forms
|
||||
|
||||
# pylint: disable=protected-access
|
||||
|
||||
@ -21,18 +21,14 @@ Tests for SSH remotes for backups.
|
||||
import datetime
|
||||
import os
|
||||
import pwd
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from django.forms import ValidationError
|
||||
from django.urls import reverse
|
||||
|
||||
from plinth.modules.backups import network_storage
|
||||
from plinth.utils import generate_password, random_string
|
||||
|
||||
from .. import forms, views
|
||||
from .. import forms
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.usefixtures('needs_root', 'load_cfg', 'has_ssh_key'),
|
||||
|
||||
@ -57,7 +57,7 @@ class CoquelicotAppView(views.AppView):
|
||||
'coquelicot', ['set-upload-password'],
|
||||
input=form_data['upload_password'].encode())
|
||||
messages.success(self.request, _('Upload password updated'))
|
||||
except ActionError as e:
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Failed to update upload password'))
|
||||
|
||||
@ -68,7 +68,7 @@ class CoquelicotAppView(views.AppView):
|
||||
'coquelicot', ['set-max-file-size',
|
||||
str(max_file_size)])
|
||||
messages.success(self.request, _('Maximum file size updated'))
|
||||
except ActionError as e:
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Failed to update maximum file size'))
|
||||
|
||||
|
||||
@ -97,7 +97,7 @@ def setup(helper, old_version=None):
|
||||
|
||||
def get_enabled_services(domain_name):
|
||||
"""Get enabled services for the domain name."""
|
||||
if domain_name != None and domain_name != '':
|
||||
if domain_name is not None and domain_name != '':
|
||||
try:
|
||||
domainname_services = firewall.get_enabled_services(
|
||||
zone='external')
|
||||
|
||||
@ -38,7 +38,8 @@ urlpatterns = [
|
||||
url(r'^sys/networks/add/ethernet/$', views.add_ethernet,
|
||||
name='add_ethernet'),
|
||||
url(r'^sys/networks/add/pppoe/$', views.add_pppoe, name='add_pppoe'),
|
||||
url(r'^sys/networks/add/wifi/(?:(?P<ssid>[^/]+)/(?P<interface_name>[^/]+)/)?$',
|
||||
url(r'^sys/networks/add/wifi/(?:(?P<ssid>[^/]+)/'
|
||||
r'(?P<interface_name>[^/]+)/)?$',
|
||||
views.add_wifi, name='add_wifi'),
|
||||
url(r'^sys/networks/(?P<uuid>[\w.@+-]+)/delete/$', views.delete,
|
||||
name='delete'),
|
||||
|
||||
@ -25,7 +25,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from plinth import action_utils, actions
|
||||
from plinth import app as app_module
|
||||
from plinth import frontpage, menu
|
||||
from plinth.daemon import Daemon
|
||||
from plinth.modules.apache.components import Uwsgi, Webserver
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.users import register_group
|
||||
|
||||
@ -423,7 +423,8 @@ class ForceUpgrader():
|
||||
"""Raised when upgrade fails but can be tried again immediately."""
|
||||
|
||||
class PermanentFailure(Exception):
|
||||
"""Raised when upgrade fails and there is nothing more we wish to do."""
|
||||
"""Raised when upgrade fails and there is nothing more we wish to do.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the force upgrader."""
|
||||
|
||||
@ -28,6 +28,7 @@ from plinth import cfg
|
||||
from plinth import context_processors as cp
|
||||
from plinth import menu as menu_module
|
||||
|
||||
|
||||
@pytest.fixture(name='menu', autouse=True)
|
||||
def fixture_menu():
|
||||
"""Initialized menu module."""
|
||||
|
||||
@ -83,6 +83,7 @@ pppoe_settings = {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name='network')
|
||||
def fixture_network(needs_root):
|
||||
"""Return the network module. Load it conservatively."""
|
||||
@ -116,7 +117,6 @@ def fixture_pppoe_uuid(network):
|
||||
yield from _connection(network, pppoe_settings)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('ethernet_uuid', 'wifi_uuid', 'pppoe_uuid')
|
||||
def test_get_connection_list(network):
|
||||
"""Check that we can get a list of available connections."""
|
||||
@ -127,7 +127,6 @@ def test_get_connection_list(network):
|
||||
assert 'plinth_test_pppoe' in [x['name'] for x in connections]
|
||||
|
||||
|
||||
|
||||
def test_get_connection(network, ethernet_uuid, wifi_uuid):
|
||||
"""Check that we can get a connection by name."""
|
||||
connection = network.get_connection(ethernet_uuid)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user