# HG changeset patch # User Ludovic Chabant # Date 1507403637 25200 # Node ID 8101692fdc118ddb2726f7cae39e0bfc9c8444ad # Parent 4c69935ca4153faca48f393ff193ecfef46558b1 admin: Add a "rebake preview assets" button to the dashboard. Baking preview assets is needed for showing the site preview. Also, add flashed messages. diff -r 4c69935ca415 -r 8101692fdc11 piecrust/admin/siteinfo.py --- a/piecrust/admin/siteinfo.py Sat Oct 07 12:12:28 2017 -0700 +++ b/piecrust/admin/siteinfo.py Sat Oct 07 12:13:57 2017 -0700 @@ -6,6 +6,7 @@ import threading import subprocess from flask import request, flash +from piecrust import CACHE_DIR from piecrust.app import PieCrustFactory @@ -80,17 +81,35 @@ def publish_log_file(self): return os.path.join(self.piecrust_app.cache_dir, 'publish.log') + def rebakeAssets(self): + out_dir = os.path.join( + self.root_dir, + CACHE_DIR, + self.piecrust_factory.cache_key, + 'server') + args = [ + '--no-color', + 'bake', + '-o', out_dir, + '--assets-only'] + proc = self._runChef(args) + try: + proc.wait(timeout=2) + if proc.returncode == 0: + flash("Assets baked successfully!") + else: + flash("Asset baking process returned '%s'... check the log." % + proc.returncode) + except subprocess.TimeoutExpired: + flash("Asset baking process is still running... check the log later.") + def getPublishTargetLogFile(self, target): target = target.replace(' ', '_').lower() return os.path.join(self.piecrust_app.cache_dir, 'publish.%s.log' % target) def publish(self, target): - chef_path = os.path.realpath(os.path.join( - os.path.dirname(__file__), - '../../chef.py')) args = [ - sys.executable, chef_path, '--no-color', '--pid-file', self.publish_pid_file, '--log', self.publish_log_file, @@ -98,13 +117,7 @@ '--log-publisher', self.getPublishTargetLogFile(target), '--log-debug-info', target] - env = {} - for k, v in os.environ.items(): - env[k] = v - env['PYTHONHOME'] = sys.prefix - logger.info("Running publishing command: %s" % args) - proc = subprocess.Popen(args, cwd=self.root_dir, env=env) - logger.info("Publishing process ID: %s" % proc.pid) + proc = self._runChef(args) try: proc.wait(timeout=2) if proc.returncode == 0: @@ -115,3 +128,18 @@ except subprocess.TimeoutExpired: flash("Publish process is still running... check the log later.") + def _runChef(self, args): + chef_path = os.path.realpath(os.path.join( + os.path.dirname(__file__), + '../../chef.py')) + args = [sys.executable, chef_path] + args + + env = {} + for k, v in os.environ.items(): + env[k] = v + env['PYTHONHOME'] = sys.prefix + + logger.info("Running chef command: %s" % args) + proc = subprocess.Popen(args, cwd=self.root_dir, env=env) + logger.info("Chef process ID: %s" % proc.pid) + return proc diff -r 4c69935ca415 -r 8101692fdc11 piecrust/admin/templates/dashboard.html --- a/piecrust/admin/templates/dashboard.html Sat Oct 07 12:12:28 2017 -0700 +++ b/piecrust/admin/templates/dashboard.html Sat Oct 07 12:13:57 2017 -0700 @@ -6,6 +6,15 @@

{{site_title}}

+{% with messages = get_flashed_messages() %} +{% if messages %} +
+{% for message in messages %} +

{{message}}

+{% endfor %} +
+{% endif %} +{% endwith %}

Site Summary

@@ -14,6 +23,11 @@ {{s.page_count}} {{s.name}}
{% endfor %} + +

Site Management

+
+ +

Work in Progress

diff -r 4c69935ca415 -r 8101692fdc11 piecrust/admin/views/dashboard.py --- a/piecrust/admin/views/dashboard.py Sat Oct 07 12:12:28 2017 -0700 +++ b/piecrust/admin/views/dashboard.py Sat Oct 07 12:13:57 2017 -0700 @@ -63,6 +63,7 @@ data['site_title'] = pcapp.config.get('site/title', "Unnamed Website") data['url_publish'] = url_for('.publish') data['url_preview'] = url_for('.preview_root_page') + data['url_bake_assets'] = url_for('.rebake_assets') pub_tgts = pcapp.config.get('publish', {}) data['publish'] = {'targets': list(pub_tgts.keys())} @@ -109,6 +110,13 @@ } +@foodtruck_bp.route('/rebake_assets', methods=['POST']) +@login_required +def rebake_assets(): + g.site.rebakeAssets() + return redirect(url_for('.index')) + + @foodtruck_bp.route('/login', methods=['GET', 'POST']) def login(): data = {}