# HG changeset patch # User Ludovic Chabant # Date 1507264271 25200 # Node ID a4f1eafd1964f7118033608dac8b85369d425881 # Parent d709429f02eb310fcae19a049e4e48b83a8998e7 admin: Show more info from the publishing process. diff -r d709429f02eb -r a4f1eafd1964 piecrust/admin/siteinfo.py --- a/piecrust/admin/siteinfo.py Thu Oct 05 21:30:25 2017 -0700 +++ b/piecrust/admin/siteinfo.py Thu Oct 05 21:31:11 2017 -0700 @@ -5,7 +5,7 @@ import logging import threading import subprocess -from flask import request +from flask import request, flash from piecrust.app import PieCrustFactory @@ -80,15 +80,23 @@ def publish_log_file(self): return os.path.join(self.piecrust_app.cache_dir, 'publish.log') + 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, 'publish', - '--log-publisher', self.publish_log_file, + '--log-publisher', self.getPublishTargetLogFile(target), + '--log-debug-info', target] env = {} for k, v in os.environ.items(): @@ -96,10 +104,14 @@ env['PYTHONHOME'] = sys.prefix logger.info("Running publishing command: %s" % args) proc = subprocess.Popen(args, cwd=self.root_dir, env=env) - - def _comm(): - proc.communicate() + logger.info("Publishing process ID: %s" % proc.pid) + try: + proc.wait(timeout=2) + if proc.returncode == 0: + flash("Publish process ran successfully!") + else: + flash("Publish process returned '%s'... check the log." % + proc.returncode) + except subprocess.TimeoutExpired: + flash("Publish process is still running... check the log later.") - t = threading.Thread(target=_comm, daemon=True) - t.start() -