changeset 952:94fd4f07da83

admin: Fix more URL prefix issues, improve publishing.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 05 Oct 2017 00:29:14 -0700
parents c50ff76e0596
children e04f2ad5f931
files piecrust/admin/blueprint.py piecrust/admin/siteinfo.py piecrust/admin/templates/publish.html piecrust/admin/views/preview.py piecrust/admin/views/publish.py
diffstat 5 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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)
 
--- 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()
--- 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 @@
 </div>
 {% endfor %}
 
+{% if last_log %}
+<h2>Last Publish Log</h2>
+<pre><code>
+{{last_log}}
+</code></pre>
+{% endif %}
+
 {% endblock %}
 
--- 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/<path:url>')
 @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)
 
--- 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)