Mercurial > piecrust2
comparison piecrust/commands/builtin/util.py @ 879:58ae026b4c31
chef: Optimize startup time.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Jun 2017 22:38:05 -0700 |
parents | 6db54bed2417 |
children |
comparison
equal
deleted
inserted
replaced
878:313db67cfc35 | 879:58ae026b4c31 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import shutil | |
4 import codecs | |
5 import logging | 3 import logging |
6 import yaml | |
7 from piecrust import CACHE_DIR, RESOURCES_DIR | 4 from piecrust import CACHE_DIR, RESOURCES_DIR |
8 from piecrust.app import CONFIG_PATH, THEME_CONFIG_PATH | 5 from piecrust.app import CONFIG_PATH, THEME_CONFIG_PATH |
9 from piecrust.commands.base import ChefCommand | 6 from piecrust.commands.base import ChefCommand |
10 | 7 |
11 | 8 |
19 self.description = "Creates a new empty PieCrust website." | 16 self.description = "Creates a new empty PieCrust website." |
20 self.requires_website = False | 17 self.requires_website = False |
21 | 18 |
22 def setupParser(self, parser, app): | 19 def setupParser(self, parser, app): |
23 parser.add_argument( | 20 parser.add_argument( |
24 'destination', | 21 'destination', |
25 help="The destination directory in which to create the website.") | 22 help="The destination directory in which to create the website.") |
26 | 23 |
27 def run(self, ctx): | 24 def run(self, ctx): |
28 destination = ctx.args.destination | 25 destination = ctx.args.destination |
29 if destination is None: | 26 if destination is None: |
30 destination = os.getcwd() | 27 destination = os.getcwd() |
39 if not os.path.isdir(os.path.dirname(config_path)): | 36 if not os.path.isdir(os.path.dirname(config_path)): |
40 os.makedirs(os.path.dirname(config_path), 0o755) | 37 os.makedirs(os.path.dirname(config_path), 0o755) |
41 | 38 |
42 tpl_path = os.path.join(RESOURCES_DIR, 'webinit', CONFIG_PATH) | 39 tpl_path = os.path.join(RESOURCES_DIR, 'webinit', CONFIG_PATH) |
43 if ctx.args.theme: | 40 if ctx.args.theme: |
44 tpl_path = os.path.join(RESOURCES_DIR, 'webinit', THEME_CONFIG_PATH) | 41 tpl_path = os.path.join(RESOURCES_DIR, 'webinit', |
42 THEME_CONFIG_PATH) | |
45 with open(tpl_path, 'r', encoding='utf-8') as fp: | 43 with open(tpl_path, 'r', encoding='utf-8') as fp: |
46 config_text = fp.read() | 44 config_text = fp.read() |
47 | 45 |
48 with open(config_path, 'w', encoding='utf-8') as fp: | 46 with open(config_path, 'w', encoding='utf-8') as fp: |
49 fp.write(config_text) | 47 fp.write(config_text) |
57 | 55 |
58 def setupParser(self, parser, app): | 56 def setupParser(self, parser, app): |
59 pass | 57 pass |
60 | 58 |
61 def run(self, ctx): | 59 def run(self, ctx): |
60 import shutil | |
61 | |
62 cache_dir = os.path.join(ctx.app.root_dir, CACHE_DIR) | 62 cache_dir = os.path.join(ctx.app.root_dir, CACHE_DIR) |
63 if cache_dir and os.path.isdir(cache_dir): | 63 if cache_dir and os.path.isdir(cache_dir): |
64 logger.info("Purging cache: %s" % cache_dir) | 64 logger.info("Purging cache: %s" % cache_dir) |
65 shutil.rmtree(cache_dir) | 65 shutil.rmtree(cache_dir) |
66 | 66 |