# HG changeset patch # User Ludovic Chabant # Date 1507188554 25200 # Node ID 94fd4f07da83a4f612d1a2ee8de4108a4aa401bc # Parent c50ff76e059667a9c8875b2a7c35bed7f02fa88b admin: Fix more URL prefix issues, improve publishing. diff -r c50ff76e0596 -r 94fd4f07da83 piecrust/admin/blueprint.py --- a/piecrust/admin/blueprint.py Thu Oct 05 00:28:34 2017 -0700 +++ b/piecrust/admin/blueprint.py Thu Oct 05 00:29:14 2017 -0700 @@ -94,7 +94,9 @@ def _setup_foodtruck_globals(): def _get_site(): root_dir = current_app.config['FOODTRUCK_ROOT_DIR'] - return SiteInfo(root_dir, debug=current_app.debug) + return SiteInfo(root_dir, + url_prefix=foodtruck_bp.url_prefix, + debug=current_app.debug) g.site = LazySomething(_get_site) diff -r c50ff76e0596 -r 94fd4f07da83 piecrust/admin/siteinfo.py --- a/piecrust/admin/siteinfo.py Thu Oct 05 00:28:34 2017 -0700 +++ b/piecrust/admin/siteinfo.py Thu Oct 05 00:29:14 2017 -0700 @@ -21,19 +21,19 @@ class SiteInfo: - def __init__(self, root_dir, *, debug=False): + def __init__(self, root_dir, *, url_prefix='', debug=False): self.root_dir = root_dir + self.url_prefix = url_prefix self.debug = debug self._piecrust_factory = None self._piecrust_app = None self._scm = None - @property - def url_prefix(self): - return request.script_root - def make_url(self, rel_url): - return self.url_prefix + rel_url + prefix = self.url_prefix + if not prefix: + return rel_url + return prefix + rel_url @property def piecrust_factory(self): @@ -81,14 +81,21 @@ return os.path.join(self.piecrust_app.cache_dir, 'publish.log') def publish(self, target): + chef_path = os.path.realpath(os.path.join( + os.path.dirname(__file__), + '../../chef.py')) args = [ - sys.executable, sys.argv[0], + sys.executable, chef_path, '--pid-file', self.publish_pid_file, 'publish', '--log-publisher', self.publish_log_file, target] - logger.debug("Running publishing command: %s" % args) - proc = subprocess.Popen(args, cwd=self.root_dir) + 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) def _comm(): proc.communicate() diff -r c50ff76e0596 -r 94fd4f07da83 piecrust/admin/templates/publish.html --- a/piecrust/admin/templates/publish.html Thu Oct 05 00:28:34 2017 -0700 +++ b/piecrust/admin/templates/publish.html Thu Oct 05 00:29:14 2017 -0700 @@ -14,5 +14,12 @@ {% endfor %} +{% if last_log %} +

Last Publish Log

+

+{{last_log}}
+
+{% endif %} + {% endblock %} diff -r c50ff76e0596 -r 94fd4f07da83 piecrust/admin/views/preview.py --- a/piecrust/admin/views/preview.py Thu Oct 05 00:28:34 2017 -0700 +++ b/piecrust/admin/views/preview.py Thu Oct 05 00:29:14 2017 -0700 @@ -13,7 +13,8 @@ @foodtruck_bp.route('/preview/') @login_required def preview_page(url): - pcappfac = g.site.piecrust_factory - server = PieCrustServer(pcappfac, root_url=g.site.make_url('/preview/')) + site = g.site + pcappfac = site.piecrust_factory + server = PieCrustServer(pcappfac, root_url=site.make_url('/preview/')) return make_response(server) diff -r c50ff76e0596 -r 94fd4f07da83 piecrust/admin/views/publish.py --- a/piecrust/admin/views/publish.py Thu Oct 05 00:28:34 2017 -0700 +++ b/piecrust/admin/views/publish.py Thu Oct 05 00:29:14 2017 -0700 @@ -28,6 +28,12 @@ with_base_data(data) return render_template('error.html', **data) + try: + with open(site.publish_log_file, 'r') as fp: + last_pub_log = fp.read() + except OSError: + last_pub_log = None + data = {} data['url_run'] = url_for('.publish') data['site_title'] = site.piecrust_app.config.get('site/title', @@ -43,6 +49,8 @@ 'description': desc }) + data['last_log'] = last_pub_log + with_menu_context(data) return render_template('publish.html', **data)