Mercurial > piecrust2
comparison piecrust/admin/siteinfo.py @ 886:dcdec4b951a1
admin: Get the admin panel working again.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Jun 2017 21:13:08 -0700 |
parents | |
children | 7ecb946bfafd |
comparison
equal
deleted
inserted
replaced
885:13e8b50a2113 | 886:dcdec4b951a1 |
---|---|
1 import os | |
2 import os.path | |
3 import sys | |
4 import copy | |
5 import logging | |
6 import threading | |
7 import subprocess | |
8 from piecrust.app import PieCrustFactory | |
9 | |
10 | |
11 logger = logging.getLogger(__name__) | |
12 | |
13 | |
14 class UnauthorizedSiteAccessError(Exception): | |
15 pass | |
16 | |
17 | |
18 class InvalidSiteError(Exception): | |
19 pass | |
20 | |
21 | |
22 class SiteInfo: | |
23 def __init__(self, root_dir, url_prefix, *, debug=False): | |
24 self.root_dir = root_dir | |
25 self.url_prefix = url_prefix | |
26 self.debug = debug | |
27 self._piecrust_factory = None | |
28 self._piecrust_app = None | |
29 self._scm = None | |
30 | |
31 @property | |
32 def piecrust_factory(self): | |
33 if self._piecrust_factory is None: | |
34 self._piecrust_factory = PieCrustFactory( | |
35 self.root_dir, | |
36 cache_key='admin', | |
37 debug=self.debug, | |
38 config_values=[ | |
39 ('site/root', '%s/preview/' % self.url_prefix), | |
40 ('site/asset_url_format', | |
41 self.url_prefix + '/preview/_asset/%path%') | |
42 ]) | |
43 return self._piecrust_factory | |
44 | |
45 @property | |
46 def piecrust_app(self): | |
47 if self._piecrust_app is None: | |
48 logger.debug("Creating PieCrust admin app: %s" % self.root_dir) | |
49 self._piecrust_app = self.piecrust_factory.create() | |
50 return self._piecrust_app | |
51 | |
52 @property | |
53 def scm(self): | |
54 if self._scm is None: | |
55 cfg = copy.deepcopy(self.piecrust_app.config.get('scm', {})) | |
56 | |
57 if os.path.isdir(os.path.join(self.root_dir, '.hg')): | |
58 from .scm.mercurial import MercurialSourceControl | |
59 self._scm = MercurialSourceControl(self.root_dir, cfg) | |
60 elif os.path.isdir(os.path.join(self.root_dir, '.git')): | |
61 from .scm.git import GitSourceControl | |
62 self._scm = GitSourceControl(self.root_dir, cfg) | |
63 else: | |
64 self._scm = False | |
65 | |
66 return self._scm | |
67 | |
68 @property | |
69 def publish_pid_file(self): | |
70 return os.path.join(self.piecrust_app.cache_dir, 'publish.pid') | |
71 | |
72 @property | |
73 def publish_log_file(self): | |
74 return os.path.join(self.piecrust_app.cache_dir, 'publish.log') | |
75 | |
76 def publish(self, target): | |
77 args = [ | |
78 sys.executable, sys.argv[0], | |
79 '--pid-file', self.publish_pid_file, | |
80 'publish', | |
81 '--log-publisher', self.publish_log_file, | |
82 target] | |
83 logger.debug("Running publishing command: %s" % args) | |
84 proc = subprocess.Popen(args, cwd=self.root_dir) | |
85 | |
86 def _comm(): | |
87 proc.communicate() | |
88 | |
89 t = threading.Thread(target=_comm, daemon=True) | |
90 t.start() | |
91 |