Updated all Python code to be fully flake8 compliant
This commit is contained in:
2
dev.py
2
dev.py
@@ -13,7 +13,7 @@ from puppetboard.app import app
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Start CoffeeScript to automatically compile our coffee source.
|
# Start CoffeeScript to automatically compile our coffee source.
|
||||||
# We must be careful to only start this in the parent process as
|
# We must be careful to only start this in the parent process as
|
||||||
# WERKZEUG will create a secondary process when using the reloader.
|
# Werkzeug will create a secondary process when using the reloader.
|
||||||
if os.environ.get('WERKZEUG_RUN_MAIN') is None:
|
if os.environ.get('WERKZEUG_RUN_MAIN') is None:
|
||||||
try:
|
try:
|
||||||
subprocess.Popen([
|
subprocess.Popen([
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ try:
|
|||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, render_template, abort, url_for,
|
Flask, render_template, abort, url_for,
|
||||||
@@ -45,7 +45,7 @@ puppetdb = connect(
|
|||||||
|
|
||||||
numeric_level = getattr(logging, app.config['LOGLEVEL'].upper(), None)
|
numeric_level = getattr(logging, app.config['LOGLEVEL'].upper(), None)
|
||||||
if not isinstance(numeric_level, int):
|
if not isinstance(numeric_level, int):
|
||||||
raise ValueError('Invalid log level: %s' % loglevel)
|
raise ValueError('Invalid log level: %s' % app.config['LOGLEVEL'])
|
||||||
logging.basicConfig(level=numeric_level)
|
logging.basicConfig(level=numeric_level)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ def bad_request(e):
|
|||||||
|
|
||||||
|
|
||||||
@app.errorhandler(403)
|
@app.errorhandler(403)
|
||||||
def bad_request(e):
|
def forbidden(e):
|
||||||
return render_template('403.html'), 400
|
return render_template('403.html'), 400
|
||||||
|
|
||||||
|
|
||||||
@@ -203,15 +203,17 @@ def reports():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/reports/<node>')
|
@app.route('/reports/<node>')
|
||||||
def reports_node(node):
|
def reports_node(node_name):
|
||||||
"""Fetches all reports for a node and processes them eventually rendering
|
"""Fetches all reports for a node and processes them eventually rendering
|
||||||
a table displaying those reports."""
|
a table displaying those reports."""
|
||||||
reports = limit_reports(yield_or_stop(
|
reports = limit_reports(
|
||||||
puppetdb.reports('["=", "certname", "{0}"]'.format(node))), app.config['REPORTS_COUNT'])
|
yield_or_stop(
|
||||||
|
puppetdb.reports('["=", "certname", "{0}"]'.format(node_name))),
|
||||||
|
app.config['REPORTS_COUNT'])
|
||||||
return render_template(
|
return render_template(
|
||||||
'reports_node.html',
|
'reports_node.html',
|
||||||
reports=reports,
|
reports=reports,
|
||||||
nodename=node,
|
nodename=node_name,
|
||||||
reports_count=app.config['REPORTS_COUNT'])
|
reports_count=app.config['REPORTS_COUNT'])
|
||||||
|
|
||||||
|
|
||||||
@@ -221,7 +223,6 @@ def report_latest(node_name):
|
|||||||
as long as PuppetDB can't filter reports for latest-report? field. This
|
as long as PuppetDB can't filter reports for latest-report? field. This
|
||||||
feature has been requested: https://tickets.puppetlabs.com/browse/PDB-203
|
feature has been requested: https://tickets.puppetlabs.com/browse/PDB-203
|
||||||
"""
|
"""
|
||||||
node = get_or_abort(puppetdb.node, node_name)
|
|
||||||
reports = get_or_abort(puppetdb._query, 'reports',
|
reports = get_or_abort(puppetdb._query, 'reports',
|
||||||
query='["=","certname","{0}"]'.format(node_name),
|
query='["=","certname","{0}"]'.format(node_name),
|
||||||
limit=1)
|
limit=1)
|
||||||
@@ -232,8 +233,8 @@ def report_latest(node_name):
|
|||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/report/<node>/<report_id>')
|
@app.route('/report/<node_name>/<report_id>')
|
||||||
def report(node, report_id):
|
def report(node_name, report_id):
|
||||||
"""Displays a single report including all the events associated with that
|
"""Displays a single report including all the events associated with that
|
||||||
report and their status.
|
report and their status.
|
||||||
|
|
||||||
@@ -241,7 +242,7 @@ def report(node, report_id):
|
|||||||
configuration_version. This allows for better integration
|
configuration_version. This allows for better integration
|
||||||
into puppet-hipchat.
|
into puppet-hipchat.
|
||||||
"""
|
"""
|
||||||
reports = puppetdb.reports('["=", "certname", "{0}"]'.format(node))
|
reports = puppetdb.reports('["=", "certname", "{0}"]'.format(node_name))
|
||||||
|
|
||||||
for report in reports:
|
for report in reports:
|
||||||
if report.hash_ == report_id or report.version == report_id:
|
if report.hash_ == report_id or report.version == report_id:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from pypuppetdb.errors import EmptyResponseError
|
|||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
|
||||||
|
|
||||||
def jsonprint(value):
|
def jsonprint(value):
|
||||||
return json.dumps(value, indent=2, separators=(',', ': '))
|
return json.dumps(value, indent=2, separators=(',', ': '))
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ def limit_reports(reports, limit):
|
|||||||
raise StopIteration
|
raise StopIteration
|
||||||
yield report
|
yield report
|
||||||
|
|
||||||
|
|
||||||
def yield_or_stop(generator):
|
def yield_or_stop(generator):
|
||||||
"""Similar in intent to get_or_abort this helper will iterate over our
|
"""Similar in intent to get_or_abort this helper will iterate over our
|
||||||
generators and handle certain errors.
|
generators and handle certain errors.
|
||||||
|
|||||||
Reference in New Issue
Block a user