comparison chef.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 a212a3f2e3ee
children f485ba500df3
comparison
equal deleted inserted replaced
0:a212a3f2e3ee 1:aaa8fb7c8918
1 import sys 1 import sys
2 import os.path 2 import os.path
3 import logging 3 import logging
4 import argparse 4 import argparse
5 from piecrust.app import PieCrust, PieCrustConfiguration, APP_VERSION 5 from piecrust.app import PieCrust, PieCrustConfiguration, APP_VERSION
6 from piecrust.commands.base import CommandContext
7 from piecrust.environment import StandardEnvironment 6 from piecrust.environment import StandardEnvironment
8 from piecrust.pathutil import SiteNotFoundError, find_app_root 7 from piecrust.pathutil import SiteNotFoundError, find_app_root
8 from piecrust.plugins.base import PluginLoader
9 9
10 10
11 logger = logging.getLogger(__name__) 11 logger = logging.getLogger(__name__)
12 logging.basicConfig(level=logging.INFO, 12 logging.basicConfig(level=logging.INFO,
13 format="%(message)s") 13 format="%(message)s")
23 self.posts_dir = [] 23 self.posts_dir = []
24 self.plugins_dirs = [] 24 self.plugins_dirs = []
25 self.theme_dir = None 25 self.theme_dir = None
26 self.cache_dir = None 26 self.cache_dir = None
27 self.config = PieCrustConfiguration() 27 self.config = PieCrustConfiguration()
28 self.env = StandardEnvironment(self) 28 self.plugin_loader = PluginLoader(self)
29 self.env = StandardEnvironment()
30 self.env.initialize(self)
29 31
30 32
31 def main(): 33 def main():
32 root = None 34 root = None
33 cache = True 35 cache = True
84 86
85 commands = sorted(app.plugin_loader.getCommands(), 87 commands = sorted(app.plugin_loader.getCommands(),
86 lambda a, b: cmp(a.name, b.name)) 88 lambda a, b: cmp(a.name, b.name))
87 subparsers = parser.add_subparsers() 89 subparsers = parser.add_subparsers()
88 for c in commands: 90 for c in commands:
89 def command_runner(r):
90 if root is None and c.requires_website:
91 raise SiteNotFoundError()
92 c.run(CommandContext(r, app))
93
94 p = subparsers.add_parser(c.name, help=c.description) 91 p = subparsers.add_parser(c.name, help=c.description)
95 c.setupParser(p) 92 c.setupParser(p)
96 p.set_defaults(func=command_runner) 93 p.set_defaults(func=c._runFromChef)
97 94
98 # Parse the command line. 95 # Parse the command line.
99 result = parser.parse_args() 96 result = parser.parse_args()
100 97
101 # Setup the logger. 98 # Setup the logger.
108 if result.log: 105 if result.log:
109 from logging.handlers import FileHandler 106 from logging.handlers import FileHandler
110 logger.addHandler(FileHandler(result.log)) 107 logger.addHandler(FileHandler(result.log))
111 108
112 # Run the command! 109 # Run the command!
113 result.func(result) 110 result.func(app, result)
114 111
115 112
116 if __name__ == '__main__': 113 if __name__ == '__main__':
117 main() 114 main()
118 115