From 97bbe96465b7e33f1e358535052f4b8d8c4ac705 Mon Sep 17 00:00:00 2001 From: Fotis Gimian Date: Sun, 10 May 2015 20:08:09 +1000 Subject: [PATCH] Updated all Python code to be fully flake8 compliant --- dev.py | 2 +- puppetboard/app.py | 23 ++++++++++++----------- puppetboard/forms.py | 2 +- puppetboard/utils.py | 4 +++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dev.py b/dev.py index fb9b184..7576fa1 100644 --- a/dev.py +++ b/dev.py @@ -13,7 +13,7 @@ from puppetboard.app import app if __name__ == '__main__': # Start CoffeeScript to automatically compile our coffee source. # 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: try: subprocess.Popen([ diff --git a/puppetboard/app.py b/puppetboard/app.py index 09e816f..ddf073d 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -8,7 +8,7 @@ try: from urllib import unquote except ImportError: from urllib.parse import unquote -from datetime import datetime, timedelta +from datetime import datetime from flask import ( Flask, render_template, abort, url_for, @@ -45,7 +45,7 @@ puppetdb = connect( numeric_level = getattr(logging, app.config['LOGLEVEL'].upper(), None) 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) log = logging.getLogger(__name__) @@ -72,7 +72,7 @@ def bad_request(e): @app.errorhandler(403) -def bad_request(e): +def forbidden(e): return render_template('403.html'), 400 @@ -203,15 +203,17 @@ def reports(): @app.route('/reports/') -def reports_node(node): +def reports_node(node_name): """Fetches all reports for a node and processes them eventually rendering a table displaying those reports.""" - reports = limit_reports(yield_or_stop( - puppetdb.reports('["=", "certname", "{0}"]'.format(node))), app.config['REPORTS_COUNT']) + reports = limit_reports( + yield_or_stop( + puppetdb.reports('["=", "certname", "{0}"]'.format(node_name))), + app.config['REPORTS_COUNT']) return render_template( 'reports_node.html', reports=reports, - nodename=node, + nodename=node_name, 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 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', query='["=","certname","{0}"]'.format(node_name), limit=1) @@ -232,8 +233,8 @@ def report_latest(node_name): abort(404) -@app.route('/report//') -def report(node, report_id): +@app.route('/report//') +def report(node_name, report_id): """Displays a single report including all the events associated with that report and their status. @@ -241,7 +242,7 @@ def report(node, report_id): configuration_version. This allows for better integration into puppet-hipchat. """ - reports = puppetdb.reports('["=", "certname", "{0}"]'.format(node)) + reports = puppetdb.reports('["=", "certname", "{0}"]'.format(node_name)) for report in reports: if report.hash_ == report_id or report.version == report_id: diff --git a/puppetboard/forms.py b/puppetboard/forms.py index 45dbfb8..f4667c3 100644 --- a/puppetboard/forms.py +++ b/puppetboard/forms.py @@ -10,7 +10,7 @@ class QueryForm(Form): PuppetDB.""" query = TextAreaField('Query', [validators.Required( message='A query is required.')]) - endpoints = RadioField('API endpoint', choices = [ + endpoints = RadioField('API endpoint', choices=[ ('nodes', 'Nodes'), ('resources', 'Resources'), ('facts', 'Facts'), diff --git a/puppetboard/utils.py b/puppetboard/utils.py index 0699345..6f30b88 100644 --- a/puppetboard/utils.py +++ b/puppetboard/utils.py @@ -8,8 +8,9 @@ from pypuppetdb.errors import EmptyResponseError from flask import abort + def jsonprint(value): - return json.dumps(value, indent=2, separators=(',', ': ') ) + return json.dumps(value, indent=2, separators=(',', ': ')) def get_or_abort(func, *args, **kwargs): @@ -38,6 +39,7 @@ def limit_reports(reports, limit): raise StopIteration yield report + def yield_or_stop(generator): """Similar in intent to get_or_abort this helper will iterate over our generators and handle certain errors.