Skip to content

Commit 6b5d2ce

Browse files
committed
pep257: fix D401/D400
1 parent 4ffd04d commit 6b5d2ce

File tree

15 files changed

+94
-84
lines changed

15 files changed

+94
-84
lines changed

marmoset/pxe/client_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""file for dealing with PXE client configs"""
1+
"""file for dealing with PXE client configs."""
22
import base64
33
import crypt
44
import os
@@ -11,7 +11,7 @@
1111

1212

1313
class ClientConfig:
14-
"""Class to handle PXE configs for clients"""
14+
"""Class to handle PXE configs for clients."""
1515

1616
CFG_DIR = '/srv/tftp/pxelinux.cfg/'
1717

@@ -53,7 +53,7 @@ def __init__(self, ip_address, password=None, script=None, uuid=None,
5353
ipv6_address=None, ipv6_gateway=None, ipv6_prefix=None,
5454
persistent=False):
5555
"""
56-
Initialize a PXE config object with provided data
56+
Initialize a PXE config object with provided data.
5757
5858
We do a lot of data validation here. Besides that we do a lot of
5959
assumptions her. Example: IPv6 is a all-or-nothing setup. All IPv6

marmoset/pxe/exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
"""Module to deal with exceptions in the PXE part"""
1+
"""Module to deal with exceptions in the PXE part."""
22

33

44
class Error(Exception):
5-
"""Class to deal with it"""
5+
"""Class to deal with it."""
66

77
def __init__(self, message):
8-
"""Initialize the message attribute"""
8+
"""Initialize the message attribute."""
99
self.message = message
1010

1111

1212
class InputError(Error):
13-
"""Dummy class"""
13+
"""Dummy class."""
1414

1515
pass

marmoset/pxe/label.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""File for dealing with PXE lables"""
1+
"""File for dealing with PXE lables."""
22
from .client_config import ClientConfig
33
from .exceptions import InputError
44

55

66
class Label:
7-
"""class to handle PXE lables"""
7+
"""class to handle PXE lables."""
88

99
instances = []
1010

@@ -23,7 +23,7 @@ def names(cls):
2323

2424
def __init__(self, name, callback=None):
2525
"""
26-
Initialize attributes with defaults
26+
Initialize attributes with defaults.
2727
2828
This also checks if a configured callback method (from our config file)
2929
for a PXE label actually exists as a mehod.

marmoset/validation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""helper fill with several validation functions"""
1+
"""helper fill with several validation functions."""
22
import ipaddress
33
import re
44
from uuid import UUID
@@ -7,12 +7,12 @@
77

88

99
def is_mac(mac):
10-
"""Returns True if param is a valid MAC"""
10+
"""Return True if param is a valid MAC."""
1111
return True if re.match("^%s$" % MAC_REGEX, mac) else False
1212

1313

1414
def is_ipv4(ipaddr):
15-
"""Returns True if param is a valid IPv4 address"""
15+
"""Return True if param is a valid IPv4 address."""
1616
try:
1717
ipaddress.IPv4Address(ipaddr)
1818
except ipaddress.AddressValueError:
@@ -21,7 +21,7 @@ def is_ipv4(ipaddr):
2121

2222

2323
def is_ipv6(ipaddr):
24-
"""Returns True if param is a valid IPv6 address"""
24+
"""Return True if param is a valid IPv6 address."""
2525
try:
2626
ipaddress.IPv6Address(ipaddr)
2727
except ipaddress.AddressValueError:
@@ -30,7 +30,7 @@ def is_ipv6(ipaddr):
3030

3131

3232
def is_cidr(cidr):
33-
"""Returns True if param is a valid IPv4 CIDR"""
33+
"""Return True if param is a valid IPv4 CIDR."""
3434
try:
3535
if "/" not in cidr:
3636
return False
@@ -42,7 +42,7 @@ def is_cidr(cidr):
4242

4343

4444
def is_uuid(uuid):
45-
"""Returns True if param is a valid UUID"""
45+
"""Return True if param is a valid UUID."""
4646
try:
4747
UUID(uuid)
4848
except Exception:
@@ -51,7 +51,7 @@ def is_uuid(uuid):
5151

5252

5353
def get_cidr(cidr):
54-
"""Returns a hash with parsed CIDR, containing IP, Netmask, Gateway"""
54+
"""Return a hash with parsed CIDR, containing IP, Netmask, Gateway."""
5555
interface = ipaddress.IPv4Interface(cidr)
5656
gateway = list(interface.network.hosts())[0]
5757
return {'ip': str(interface.ip),
@@ -60,18 +60,18 @@ def get_cidr(cidr):
6060

6161

6262
def get_ip_from_cidr(cidr):
63-
"""Returns the IP from a CIDR"""
63+
"""Return the IP from a CIDR."""
6464
data = get_cidr(cidr)
6565
return data['ip']
6666

6767

6868
def get_nm_from_cidr(cidr):
69-
"""Returns the netmask from a CIDR"""
69+
"""Return the netmask from a CIDR."""
7070
data = get_cidr(cidr)
7171
return data['nm']
7272

7373

7474
def get_gw_from_cidr(cidr):
75-
"""Returns the gateway from a CIDR"""
75+
"""Return the gateway from a CIDR."""
7676
data = get_cidr(cidr)
7777
return data['gw']

marmoset/webserver/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""initial file for providing a Flask based API"""
1+
"""initial file for providing a Flask based API."""
22
from flask import Flask, jsonify
33
# https://flask-restful.readthedocs.io/en/latest/quickstart.html
44
from flask_restful import Api
@@ -11,14 +11,14 @@
1111

1212

1313
def jsonify_nl(*args, **kwargs):
14-
"""Encode data to json"""
14+
"""Encode data to json."""
1515
resp = jsonify(*args, **kwargs)
1616
resp.set_data(resp.get_data() + b'\n')
1717
return resp
1818

1919

2020
def app(config):
21-
"""Setup the initial flask app"""
21+
"""Setup the initial flask app."""
2222
auth.Username = config['Webserver'].get('Username')
2323
auth.Password = config['Webserver'].get('Password')
2424

@@ -83,7 +83,7 @@ def app(config):
8383

8484
@app.errorhandler(404)
8585
def not_found(ex):
86-
"""Function to generate 404 handler"""
86+
"""Function to generate 404 handler."""
8787
# pylint: disable-msg=unused-argument
8888
# pylint: disable-msg=unused-variable
8989
resp = jsonify_nl(message="Route not found.", status=404)
@@ -92,7 +92,7 @@ def not_found(ex):
9292

9393
@app.errorhandler(401)
9494
def unauthorized(ex):
95-
"""Function to generate 401 handler"""
95+
"""Function to generate 401 handler."""
9696
# pylint: disable-msg=unused-argument
9797
# pylint: disable-msg=unused-variable
9898
resp = jsonify_nl(message="Unauthorized", status=401)
@@ -103,7 +103,7 @@ def unauthorized(ex):
103103

104104

105105
def run(args):
106-
"""Function to run the app"""
106+
"""Function to run the app."""
107107
# pylint: disable-msg=unused-argument
108108
webserver = app(config)
109109
print(webserver.url_map)

marmoset/webserver/dhcp.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""File to handle all web interaction with DHCP records"""
1+
"""File to handle all web interaction with DHCP records."""
22
from flask import request
33
from flask.ext.restful import Resource
44
from flask.ext.restful import abort
@@ -25,14 +25,14 @@
2525

2626

2727
class DhcpCollection(Resource):
28-
"""Collection class to dal with all DHCP records"""
28+
"""Collection class to dal with all DHCP records."""
2929

3030
def get(self):
31-
"""Returns all DHCP records"""
31+
"""Return all DHCP records."""
3232
return [vars(c) for c in dhcp.DhcpConfig.all()]
3333

3434
def post(self):
35-
"""Creates a new PXE record"""
35+
"""Create a new PXE record."""
3636
args = parser.parse_args()
3737

3838
if ((args.gateway is None and config['DHCPConfig'].getboolean(
@@ -78,10 +78,10 @@ def post(self):
7878

7979

8080
class DhcpIpv4Object(Resource):
81-
"""Class to handle a single DHCP record based on IPv4 address"""
81+
"""Class to handle a single DHCP record based on IPv4 address."""
8282

8383
def get(self, ipv4):
84-
"""Returns a single DHCP record based on the provided ipv4"""
84+
"""Return a single DHCP record based on the provided ipv4."""
8585
if not validation.is_ipv4(ipv4):
8686
return {'message': 'please provide a valid ipv4 address'}, 406
8787

@@ -93,7 +93,7 @@ def get(self, ipv4):
9393
return vars(dhcp_config)
9494

9595
def put(self, ipv4):
96-
"""Updates a DHCP recordd"""
96+
"""Update a DHCP recordd."""
9797
args = parser.parse_args(request)
9898

9999
if not validation.is_ipv4(ipv4):
@@ -142,10 +142,10 @@ def delete(self, ipv4):
142142

143143

144144
class DhcpMacObject(Resource):
145-
"""Class to handle a single DHCP record based on a MAC address"""
145+
"""Class to handle a single DHCP record based on a MAC address."""
146146

147147
def get(self, mac):
148-
"""Returns a single DHCP record based on the provided MAC"""
148+
"""Return a single DHCP record based on the provided MAC."""
149149
if not validation.is_mac(mac):
150150
return {'message': 'please provide a valid mac address'}, 406
151151

@@ -157,7 +157,7 @@ def get(self, mac):
157157
return vars(dhcp_config)
158158

159159
def put(self, mac):
160-
"""Updates a DHCP record"""
160+
"""Update a DHCP record."""
161161
args = parser.parse_args(request)
162162

163163
if not validation.is_mac(mac):
@@ -189,7 +189,7 @@ def put(self, mac):
189189
return vars(dhcp_config), 201, {'Location': location}
190190

191191
def delete(self, mac):
192-
"""Deletes a DHCP record"""
192+
"""Delete a DHCP record."""
193193
if not validation.is_mac(mac):
194194
return {'message': 'please provide a valid mac address'}, 406
195195

marmoset/webserver/flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""flask initial file"""
1+
"""flask initial file."""

marmoset/webserver/flask/auth.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ def for_all_routes(app):
2222
return app
2323

2424

25-
# we've to disable pep8 here because it detects uppercase chars in the method name
25+
# we've to disable pep8 here because
26+
# it detects uppercase chars in the method name
2627
# pep8 compliance requires lowercase only function names, but thats the case
2728
def __check_auth(username, password): # nopep8
2829
"""
29-
Check username/password combination
30+
Check username/password combination.
3031
3132
This function is called to check if a username /
3233
password combination is valid.
3334
"""
3435
return username == Username and password == Password
3536

3637

37-
# we've to disable pep8 here because it detects uppercase chars in the method name
38+
# we've to disable pep8 here because
39+
# it detects uppercase chars in the method name
3840
# pep8 compliance requires lowercase only function names, but thats the case
3941
def __is_whitelist_endpoint(endpoint): # nopep8
40-
"""Check if a given endpoint is whitelisted in our configuration file"""
42+
"""Check if a given endpoint is whitelisted in our configuration file."""
4143
whitelist_conf = current_app.config['AUTH_WHITELIST_ENDPOINT']
4244
if whitelist_conf is not None:
4345
whitelist = whitelist_conf.split(',')
@@ -46,7 +48,8 @@ def __is_whitelist_endpoint(endpoint): # nopep8
4648
return False
4749

4850

49-
# we've to disable pep8 here because it detects uppercase chars in the method name
51+
# we've to disable pep8 here because
52+
# it detects uppercase chars in the method name
5053
# pep8 compliance requires lowercase only function names, but thats the case
5154
def __authenticate(): # nopep8
5255
auth = request.authorization

marmoset/webserver/flask/json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
"""Flask extension module which holds a few helper functions"""
1+
"""Flask extension module which holds a few helper functions."""
22
from flask import Flask, jsonify
33
from werkzeug.exceptions import default_exceptions, HTTPException
44

55

66
# pylint: disable-msg=keyword-arg-before-vararg
77
def response(code=200, headers={}, *args, **kwargs):
8-
"""Creates a json encoded response"""
8+
"""Create a json encoded response."""
99
# pylint: disable-msg=dangerous-default-value
1010
# pylint: disable-msg=redefined-outer-name
1111
response = jsonify(*args, **kwargs)
@@ -16,15 +16,15 @@ def response(code=200, headers={}, *args, **kwargs):
1616

1717

1818
def error(ex=None, code=500, headers={}):
19-
"""Creates a proper HTTP error"""
19+
"""Create a proper HTTP error."""
2020
# pylint: disable-msg=dangerous-default-value
2121
code = ex.code if isinstance(ex, HTTPException) else code
2222
return response(code, headers, message=str(ex))
2323

2424

2525
def app(import_name, **kwargs):
2626
"""
27-
Creates a JSON-oriented Flask app.
27+
Create a JSON-oriented Flask app.
2828
2929
All error responses that you don't specifically
3030
manage yourself will have application/json content

marmoset/webserver/imagecatalog.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
"""Class for hanlding image metadata."""
12
from flask.ext.restful import Resource, abort
23
from ..imagecatalog.catalog import ImageCatalog
34

45

56
class ImageMetadataCollection(Resource):
7+
"""Collection class to deal with metadata for images."""
68

79
def get(self):
8-
"""List all images' metadata"""
10+
"""List all images' metadata."""
911
catalog = ImageCatalog()
1012
metadata_list = catalog.list_all_metadata()
1113
return metadata_list
1214

1315

1416
class ImageMetadata(Resource):
17+
"""Class to get metadata for a single image."""
18+
1519
def get(self, image_file):
16-
"""Get image's metadata"""
20+
"""Get image's metadata."""
1721
catalog = ImageCatalog()
1822
image = catalog.get_image(image_file)
1923
if image is not None:
@@ -22,7 +26,10 @@ def get(self, image_file):
2226

2327

2428
class ImageSignature(Resource):
29+
"""Class to get signatures for a single image."""
30+
2531
def get(self, image_file):
32+
"""Return the signature as JSON, if available."""
2633
catalog = ImageCatalog()
2734
image = catalog.get_image(image_file)
2835
if image is not None:

0 commit comments

Comments
 (0)