comparison piecrust/admin/siteinfo.py @ 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 94fd4f07da83
children 8101692fdc11
comparison
equal deleted inserted replaced
954:d709429f02eb 955:a4f1eafd1964
3 import sys 3 import sys
4 import copy 4 import copy
5 import logging 5 import logging
6 import threading 6 import threading
7 import subprocess 7 import subprocess
8 from flask import request 8 from flask import request, flash
9 from piecrust.app import PieCrustFactory 9 from piecrust.app import PieCrustFactory
10 10
11 11
12 logger = logging.getLogger(__name__) 12 logger = logging.getLogger(__name__)
13 13
78 78
79 @property 79 @property
80 def publish_log_file(self): 80 def publish_log_file(self):
81 return os.path.join(self.piecrust_app.cache_dir, 'publish.log') 81 return os.path.join(self.piecrust_app.cache_dir, 'publish.log')
82 82
83 def getPublishTargetLogFile(self, target):
84 target = target.replace(' ', '_').lower()
85 return os.path.join(self.piecrust_app.cache_dir,
86 'publish.%s.log' % target)
87
83 def publish(self, target): 88 def publish(self, target):
84 chef_path = os.path.realpath(os.path.join( 89 chef_path = os.path.realpath(os.path.join(
85 os.path.dirname(__file__), 90 os.path.dirname(__file__),
86 '../../chef.py')) 91 '../../chef.py'))
87 args = [ 92 args = [
88 sys.executable, chef_path, 93 sys.executable, chef_path,
94 '--no-color',
89 '--pid-file', self.publish_pid_file, 95 '--pid-file', self.publish_pid_file,
96 '--log', self.publish_log_file,
90 'publish', 97 'publish',
91 '--log-publisher', self.publish_log_file, 98 '--log-publisher', self.getPublishTargetLogFile(target),
99 '--log-debug-info',
92 target] 100 target]
93 env = {} 101 env = {}
94 for k, v in os.environ.items(): 102 for k, v in os.environ.items():
95 env[k] = v 103 env[k] = v
96 env['PYTHONHOME'] = sys.prefix 104 env['PYTHONHOME'] = sys.prefix
97 logger.info("Running publishing command: %s" % args) 105 logger.info("Running publishing command: %s" % args)
98 proc = subprocess.Popen(args, cwd=self.root_dir, env=env) 106 proc = subprocess.Popen(args, cwd=self.root_dir, env=env)
107 logger.info("Publishing process ID: %s" % proc.pid)
108 try:
109 proc.wait(timeout=2)
110 if proc.returncode == 0:
111 flash("Publish process ran successfully!")
112 else:
113 flash("Publish process returned '%s'... check the log." %
114 proc.returncode)
115 except subprocess.TimeoutExpired:
116 flash("Publish process is still running... check the log later.")
99 117
100 def _comm():
101 proc.communicate()
102
103 t = threading.Thread(target=_comm, daemon=True)
104 t.start()
105