comparison piecrust/commands/builtin/util.py @ 1:aaa8fb7c8918

Re-arranged modules to reduce dependencies to builtin stuff. Added `init` command.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 22 Dec 2013 08:00:24 -0800
parents
children f485ba500df3
comparison
equal deleted inserted replaced
0:a212a3f2e3ee 1:aaa8fb7c8918
1 import os
2 import os.path
3 import codecs
4 import logging
5 import yaml
6 from piecrust.app import CONFIG_PATH
7 from piecrust.commands.base import ChefCommand
8
9
10 logger = logging.getLogger(__name__)
11
12
13 class InitCommand(ChefCommand):
14 def __init__(self):
15 super(InitCommand, self).__init__()
16 self.name = 'init'
17 self.description = "Creates a new empty PieCrust website."
18 self.requires_website = False
19
20 def setupParser(self, parser):
21 parser.add_argument('destination',
22 help="The destination directory in which to create the website.")
23
24 def run(self, ctx):
25 destination = ctx.args.destination
26 if destination is None:
27 destination = os.getcwd()
28
29 if not os.path.isdir(destination):
30 os.makedirs(destination, 0755)
31
32 config_path = os.path.join(destination, CONFIG_PATH)
33 if not os.path.isdir(os.path.dirname(config_path)):
34 os.makedirs(os.path.dirname(config_path))
35
36 config_text = yaml.dump({
37 'site': {
38 'title': "My New Website",
39 'description': "A website recently generated with PieCrust",
40 'pretty_urls': True
41 },
42 'smartypants': {
43 'enable': True
44 }
45 },
46 default_flow_style=False)
47 with codecs.open(config_path, 'w', 'utf-8') as fp:
48 fp.write(config_text)
49