comparison piecrust/commands/base.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 logging 1 import logging
2 from piecrust.pathutil import SiteNotFoundError
2 3
3 4
4 logger = logging.getLogger(__name__) 5 logger = logging.getLogger(__name__)
5 6
6 7
7 class CommandContext(object): 8 class CommandContext(object):
8 def __init__(self, args, app): 9 def __init__(self, app, args):
10 self.app = app
9 self.args = args 11 self.args = args
10 self.app = app
11 12
12 13
13 class ChefCommand(object): 14 class ChefCommand(object):
14 def __init__(self): 15 def __init__(self):
15 self.name = '__unknown__' 16 self.name = '__unknown__'
20 raise NotImplementedError() 21 raise NotImplementedError()
21 22
22 def run(self, ctx): 23 def run(self, ctx):
23 raise NotImplementedError() 24 raise NotImplementedError()
24 25
26 def _runFromChef(self, app, res):
27 if app.root is None and self.requires_website:
28 raise SiteNotFoundError()
29 self.run(CommandContext(app, res))
25 30
26 class RootCommand(ChefCommand):
27 def __init__(self):
28 super(RootCommand, self).__init__()
29 self.name = 'root'
30 self.description = "Gets the root directory of the current website."
31
32 def setupParser(self, parser):
33 pass
34
35 def run(self, ctx):
36 logger.info(ctx.app.root)
37