Mercurial > piecrust2
changeset 812:82509bce94ca
internal: PEP8 fixup for admin panel code.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Dec 2016 22:20:18 -0800 |
parents | c7393ce2dde7 |
children | c3cb2f9df882 133580265c57 e01473c3ea7e 7f235e65ef5d 10c482d57c79 |
files | piecrust/admin/blueprint.py piecrust/admin/configuration.py piecrust/admin/pubutil.py piecrust/admin/scm/git.py piecrust/admin/sites.py piecrust/admin/views/create.py piecrust/admin/views/dashboard.py piecrust/admin/views/edit.py piecrust/admin/views/menu.py piecrust/admin/views/preview.py piecrust/admin/views/publish.py piecrust/admin/views/sources.py piecrust/admin/web.py |
diffstat | 13 files changed, 101 insertions(+), 109 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/admin/blueprint.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/blueprint.py Tue Dec 20 22:20:18 2016 -0800 @@ -1,10 +1,8 @@ -import os -import os.path import time import logging -from flask import Blueprint, current_app, g, request, render_template +from flask import Blueprint, current_app, g, request from .configuration import ( - FoodTruckConfigNotFoundError, get_foodtruck_config) + FoodTruckConfigNotFoundError, get_foodtruck_config) from .sites import FoodTruckSites, InvalidSiteError @@ -12,7 +10,7 @@ # Prepare the Login extension. -from flask.ext.login import LoginManager, UserMixin +from flask.ext.login import LoginManager, UserMixin # NOQA class User(UserMixin): @@ -47,7 +45,7 @@ # Setup Bcrypt. -from .bcryptfallback import Bcrypt +from .bcryptfallback import Bcrypt # NOQA bcrypt_ext = Bcrypt() @@ -55,8 +53,8 @@ if (getattr(Bcrypt, 'is_fallback_bcrypt', None) is True and not state.app.config.get('FOODTRUCK_CMDLINE_MODE', False)): raise Exception( - "You're running FoodTruck outside of `chef`, and will need to " - "install Flask-Bcrypt to get more proper security.") + "You're running FoodTruck outside of `chef`, and will need to " + "install Flask-Bcrypt to get more proper security.") bcrypt_ext.init_app(state.app) state.app.bcrypt = bcrypt_ext @@ -64,9 +62,9 @@ # Create the FoodTruck blueprint. foodtruck_bp = Blueprint( - 'FoodTruck', __name__, - template_folder='templates', - static_folder='static') + 'FoodTruck', __name__, + template_folder='templates', + static_folder='static') foodtruck_bp.record(record_login_manager) foodtruck_bp.record(record_bcrypt) @@ -103,7 +101,7 @@ names = g.config.get('sites') if not names or not isinstance(names, dict): raise InvalidSiteError( - "No sites are defined in the configuration file.") + "No sites are defined in the configuration file.") current = request.cookies.get('foodtruck_site_name') if current is not None and current not in names:
--- a/piecrust/admin/configuration.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/configuration.py Tue Dec 20 22:20:18 2016 -0800 @@ -3,8 +3,8 @@ import logging import yaml from piecrust.configuration import ( - Configuration, ConfigurationError, ConfigurationLoader, - merge_dicts) + Configuration, ConfigurationError, ConfigurationLoader, + merge_dicts) logger = logging.getLogger(__name__) @@ -30,8 +30,8 @@ try: with open(self.cfg_path, 'r', encoding='utf-8') as fp: values = yaml.load( - fp.read(), - Loader=ConfigurationLoader) + fp.read(), + Loader=ConfigurationLoader) self._values = self._validateAll(values) except OSError: @@ -43,8 +43,8 @@ self._values = copy.deepcopy(self.fallback_config) except Exception as ex: raise ConfigurationError( - "Error loading configuration from: %s" % - self.cfg_path) from ex + "Error loading configuration from: %s" % + self.cfg_path) from ex def _validateAll(self, values): if values is None: @@ -60,15 +60,15 @@ default_configuration = { - 'triggers': { - 'bake': 'chef bake' - }, - 'scm': { - 'type': 'hg' - }, - 'security': { - 'username': '', - 'password': '' - } - } + 'triggers': { + 'bake': 'chef bake' + }, + 'scm': { + 'type': 'hg' + }, + 'security': { + 'username': '', + 'password': '' + } +}
--- a/piecrust/admin/pubutil.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/pubutil.py Tue Dec 20 22:20:18 2016 -0800 @@ -30,9 +30,9 @@ # Make sure CTRL+C works correctly. logger.debug("Adding SIGINT callback for pipeline thread.") signal.signal( - signal.SIGINT, - lambda *args: _shutdown_server_and_raise_sigint( - state.app.debug)) + signal.SIGINT, + lambda *args: _shutdown_server_and_raise_sigint( + state.app.debug)) foodtruck_bp.record(record_pipeline) @@ -117,8 +117,8 @@ if pid: is_running = _pid_exists(pid) logger.debug( - "Process %d is %s" % - (pid, 'running' if is_running else 'not running')) + "Process %d is %s" % + (pid, 'running' if is_running else 'not running')) if not is_running: # Let's forget this PID file until it changes. pid = None @@ -135,8 +135,8 @@ # This means we saw the PID file get changed. if not is_pid_file_prehistoric: outstr = ( - 'event: message\n' - 'data: Publish started.\n\n') + 'event: message\n' + 'data: Publish started.\n\n') yield bytes(outstr, 'utf8') last_seek = 0
--- a/piecrust/admin/scm/git.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/scm/git.py Tue Dec 20 22:20:18 2016 -0800 @@ -24,8 +24,8 @@ if path[-1] == '/': import glob res.new_files += [ - f for f in glob.glob(path + '**', recursive=True) - if f[-1] != '/'] + f for f in glob.glob(path + '**', recursive=True) + if f[-1] != '/'] else: res.new_files.append(path) elif line.startswith(' M '): @@ -56,7 +56,7 @@ logger.debug("Running Git: " + str(exe)) proc = subprocess.Popen( - exe, stdout=subprocess.PIPE, cwd=self.root_dir) + exe, stdout=subprocess.PIPE, cwd=self.root_dir) out, _ = proc.communicate() encoded_out = _s(out)
--- a/piecrust/admin/sites.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/sites.py Tue Dec 20 22:20:18 2016 -0800 @@ -63,10 +63,10 @@ def publish(self, target): args = [ - 'chef', - '--pid-file', self.publish_pid_file, - 'publish', target, - '--log-publisher', self.publish_log_file] + 'chef', + '--pid-file', self.publish_pid_file, + 'publish', target, + '--log-publisher', self.publish_log_file] proc = subprocess.Popen(args, cwd=self.root_dir) def _comm():
--- a/piecrust/admin/views/create.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/create.py Tue Dec 20 22:20:18 2016 -0800 @@ -2,7 +2,7 @@ import os.path import logging from flask import ( - g, request, abort, render_template, url_for, redirect, flash) + g, request, abort, render_template, url_for, redirect, flash) from flask.ext.login import login_required from piecrust.sources.interfaces import IInteractiveSource from piecrust.sources.base import MODE_CREATING
--- a/piecrust/admin/views/dashboard.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/dashboard.py Tue Dec 20 22:20:18 2016 -0800 @@ -2,8 +2,8 @@ import os.path import logging from flask import ( - current_app, g, request, - render_template, url_for, redirect) + current_app, g, request, + render_template, url_for, redirect) from flask.ext.login import login_user, logout_user, login_required from piecrust.configuration import parse_config_header from piecrust.rendering import QualifiedPage @@ -28,9 +28,9 @@ continue facs = source.getPageFactories() src_data = { - 'name': source.name, - 'list_url': url_for('.list_source', source_name=source.name), - 'page_count': len(facs)} + 'name': source.name, + 'list_url': url_for('.list_source', source_name=source.name), + 'page_count': len(facs)} data['sources'].append(src_data) fe = getattr(source, 'fs_endpoint', None) @@ -66,7 +66,7 @@ 'name': s.name, 'display_name': s.piecrust_app.config.get('site/title'), 'url': url_for('.index', site_name=s.name) - }) + }) data['needs_switch'] = len(g.config.get('sites')) > 1 data['url_switch'] = url_for('.switch_site') @@ -103,11 +103,11 @@ header, offset = parse_config_header(raw_text) extract = text_preview(raw_text, offset=offset) return { - 'title': qp.config.get('title'), - 'slug': slug, - 'url': url_for('.edit_page', slug=slug), - 'text': extract - } + 'title': qp.config.get('title'), + 'slug': slug, + 'url': url_for('.edit_page', slug=slug), + 'text': extract + } @login_required @@ -139,8 +139,8 @@ login_user(user, remember=bool(remember)) return redirect(url_for('.index')) data['message'] = ( - "User '%s' doesn't exist or password is incorrect." % - username) + "User '%s' doesn't exist or password is incorrect." % + username) return render_template('login.html', **data)
--- a/piecrust/admin/views/edit.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/edit.py Tue Dec 20 22:20:18 2016 -0800 @@ -2,11 +2,9 @@ import logging from werkzeug.utils import secure_filename from flask import ( - g, request, abort, render_template, url_for, redirect, flash) + g, request, abort, render_template, url_for, redirect, flash) from flask.ext.login import login_required from piecrust.data.assetor import Assetor -from piecrust.rendering import ( - PageRenderingContext, render_page) from piecrust.serving.util import get_requested_page from ..blueprint import foodtruck_bp from ..views import with_menu_context @@ -37,7 +35,7 @@ with open(page.path, 'w', encoding='utf8', newline='') as fp: fp.write(page_text) flash("%s was saved." % os.path.relpath( - page.path, site_app.root_dir)) + page.path, site_app.root_dir)) if 'do_save_and_commit' in request.form: message = request.form.get('commit_msg')
--- a/piecrust/admin/views/menu.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/menu.py Tue Dec 20 22:20:18 2016 -0800 @@ -24,19 +24,19 @@ url_listall = url_for('.list_source', source_name=s.name) ctx = { - 'url': url_listall, - 'title': s.name, - 'icon': source_icon, - 'quicklink': { - 'icon': 'edit', - 'url': url_write, - 'title': "Write New" - }, - 'entries': [ - {'url': url_listall, 'title': "List All"}, - {'url': url_write, 'title': "Write New"} - ] - } + 'url': url_listall, + 'title': s.name, + 'icon': source_icon, + 'quicklink': { + 'icon': 'plus-round', + 'url': url_write, + 'title': "Write New" + }, + 'entries': [ + {'url': url_listall, 'title': "List All"}, + {'url': url_write, 'title': "Write New"} + ] + } entries.append(ctx) entries.append({
--- a/piecrust/admin/views/preview.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/preview.py Tue Dec 20 22:20:18 2016 -0800 @@ -1,7 +1,5 @@ -import os.path from flask import current_app, g, make_response from flask.ext.login import login_required -from piecrust import CACHE_DIR from piecrust.app import PieCrustFactory from piecrust.serving.server import Server from ..blueprint import foodtruck_bp @@ -18,9 +16,9 @@ def preview_site(sitename, url): root_dir = g.sites.get_root_dir(sitename) appfactory = PieCrustFactory( - root_dir, - cache_key='foodtruck', - debug=current_app.debug) + root_dir, + cache_key='foodtruck', + debug=current_app.debug) server = Server(appfactory, root_url='/site/%s/' % sitename) return make_response(server._run_request)
--- a/piecrust/admin/views/publish.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/publish.py Tue Dec 20 22:20:18 2016 -0800 @@ -39,7 +39,7 @@ data['targets'].append({ 'name': tn, 'description': desc - }) + }) with_menu_context(data)
--- a/piecrust/admin/views/sources.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/views/sources.py Tue Dec 20 22:20:18 2016 -0800 @@ -2,7 +2,6 @@ from flask.ext.login import login_required from piecrust.data.paginator import Paginator from ..blueprint import foodtruck_bp -from ..textutil import text_preview, html_to_text from ..views import with_menu_context @@ -22,27 +21,27 @@ pgn = Paginator(None, source, page_num=page_num, items_per_page=20) for p in pgn.items: page_data = { - 'title': p['title'], - 'author': p.get('author', default_author), - 'slug': p['slug'], - 'timestamp': p['timestamp'], - 'tags': p.get('tags', []), - 'category': p.get('category'), - 'source': source_name, - 'url': url_for('.edit_page', slug=p['slug']) - } + 'title': p['title'], + 'author': p.get('author', default_author), + 'slug': p['slug'], + 'timestamp': p['timestamp'], + 'tags': p.get('tags', []), + 'category': p.get('category'), + 'source': source_name, + 'url': url_for('.edit_page', slug=p['slug']) + } data['pages'].append(page_data) prev_page_url = None if pgn.prev_page_number: prev_page_url = url_for( - '.list_source', source_name=source_name, - page_num=pgn.prev_page_number) + '.list_source', source_name=source_name, + page_num=pgn.prev_page_number) next_page_url = None if pgn.next_page_number: next_page_url = url_for( - '.list_source', source_name=source_name, - page_num=pgn.next_page_number) + '.list_source', source_name=source_name, + page_num=pgn.next_page_number) page_urls = [] for i in pgn.all_page_numbers(7): @@ -52,10 +51,10 @@ page_urls.append({'num': i, 'url': url}) data['pagination'] = { - 'prev_page': prev_page_url, - 'next_page': next_page_url, - 'nums': page_urls - } + 'prev_page': prev_page_url, + 'next_page': next_page_url, + 'nums': page_urls + } with_menu_context(data) return render_template('list_source.html', **data)
--- a/piecrust/admin/web.py Mon Dec 19 22:31:30 2016 -0800 +++ b/piecrust/admin/web.py Tue Dec 20 22:20:18 2016 -0800 @@ -1,6 +1,6 @@ import os.path import logging -from flask import Flask +from flask import Flask, render_template from werkzeug import SharedDataMiddleware from .blueprint import foodtruck_bp from .configuration import FoodTruckConfigNotFoundError @@ -20,22 +20,22 @@ admin_root = app.config.setdefault('FOODTRUCK_ROOT', os.getcwd()) config_path = os.path.join(admin_root, 'app.cfg') - # If we're being run as the `chef admin run` command, from inside a PieCrust - # website, do a few things differently. + # If we're being run as the `chef admin run` command, from inside a + # PieCrust website, do a few things differently. app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = None if (app.config.get('FOODTRUCK_CMDLINE_MODE', False) and os.path.isfile(os.path.join(admin_root, 'config.yml'))): app.secret_key = os.urandom(22) app.config['LOGIN_DISABLED'] = True app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = { - 'sites': { - 'local': admin_root} - } + 'sites': { + 'local': admin_root} + } # Add a special route for the `.well-known` directory. app.wsgi_app = SharedDataMiddleware( - app.wsgi_app, - {'/.well-known': os.path.join(admin_root, '.well-known')}) + app.wsgi_app, + {'/.well-known': os.path.join(admin_root, '.well-known')}) if os.path.isfile(config_path): app.config.from_pyfile(config_path) @@ -50,16 +50,15 @@ @app.errorhandler(InvalidSiteError) def _on_invalid_site(ex): - data = {'error': "The was an error with your configuration file: %s" % + data = {'error': + "The was an error with your configuration file: %s" % str(ex)} return render_template('error.html', **data) - _missing_secret_key = False if not app.secret_key: # If there's no secret key, create a temp one but mark the app as not # correctly installed so it shows the installation information page. app.secret_key = 'temp-key' - _missing_secret_key = True # Register extensions and blueprints. app.register_blueprint(foodtruck_bp)