Mercurial > piecrust2
comparison piecrust/admin/siteinfo.py @ 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 | 7ecb946bfafd |
children | a4f1eafd1964 |
comparison
equal
deleted
inserted
replaced
951:c50ff76e0596 | 952:94fd4f07da83 |
---|---|
19 class InvalidSiteError(Exception): | 19 class InvalidSiteError(Exception): |
20 pass | 20 pass |
21 | 21 |
22 | 22 |
23 class SiteInfo: | 23 class SiteInfo: |
24 def __init__(self, root_dir, *, debug=False): | 24 def __init__(self, root_dir, *, url_prefix='', debug=False): |
25 self.root_dir = root_dir | 25 self.root_dir = root_dir |
26 self.url_prefix = url_prefix | |
26 self.debug = debug | 27 self.debug = debug |
27 self._piecrust_factory = None | 28 self._piecrust_factory = None |
28 self._piecrust_app = None | 29 self._piecrust_app = None |
29 self._scm = None | 30 self._scm = None |
30 | 31 |
31 @property | |
32 def url_prefix(self): | |
33 return request.script_root | |
34 | |
35 def make_url(self, rel_url): | 32 def make_url(self, rel_url): |
36 return self.url_prefix + rel_url | 33 prefix = self.url_prefix |
34 if not prefix: | |
35 return rel_url | |
36 return prefix + rel_url | |
37 | 37 |
38 @property | 38 @property |
39 def piecrust_factory(self): | 39 def piecrust_factory(self): |
40 if self._piecrust_factory is None: | 40 if self._piecrust_factory is None: |
41 self._piecrust_factory = PieCrustFactory( | 41 self._piecrust_factory = PieCrustFactory( |
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 publish(self, target): | 83 def publish(self, target): |
84 chef_path = os.path.realpath(os.path.join( | |
85 os.path.dirname(__file__), | |
86 '../../chef.py')) | |
84 args = [ | 87 args = [ |
85 sys.executable, sys.argv[0], | 88 sys.executable, chef_path, |
86 '--pid-file', self.publish_pid_file, | 89 '--pid-file', self.publish_pid_file, |
87 'publish', | 90 'publish', |
88 '--log-publisher', self.publish_log_file, | 91 '--log-publisher', self.publish_log_file, |
89 target] | 92 target] |
90 logger.debug("Running publishing command: %s" % args) | 93 env = {} |
91 proc = subprocess.Popen(args, cwd=self.root_dir) | 94 for k, v in os.environ.items(): |
95 env[k] = v | |
96 env['PYTHONHOME'] = sys.prefix | |
97 logger.info("Running publishing command: %s" % args) | |
98 proc = subprocess.Popen(args, cwd=self.root_dir, env=env) | |
92 | 99 |
93 def _comm(): | 100 def _comm(): |
94 proc.communicate() | 101 proc.communicate() |
95 | 102 |
96 t = threading.Thread(target=_comm, daemon=True) | 103 t = threading.Thread(target=_comm, daemon=True) |