changeset 955:a4f1eafd1964

admin: Show more info from the publishing process.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 05 Oct 2017 21:31:11 -0700
parents d709429f02eb
children 4f136b746081
files piecrust/admin/siteinfo.py
diffstat 1 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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()
-