comparison piecrust/commands/builtin/info.py @ 879:58ae026b4c31

chef: Optimize startup time.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 15 Jun 2017 22:38:05 -0700
parents 4850f8c21b6e
children 07c23be08029
comparison
equal deleted inserted replaced
878:313db67cfc35 879:58ae026b4c31
1 import os.path 1 import os.path
2 import logging 2 import logging
3 import fnmatch
4 from piecrust.commands.base import ChefCommand 3 from piecrust.commands.base import ChefCommand
5 from piecrust.configuration import ConfigurationDumper
6 from piecrust.sources.fs import FSContentSourceBase
7 4
8 5
9 logger = logging.getLogger(__name__) 6 logger = logging.getLogger(__name__)
10 7
11 8
33 'path', 30 'path',
34 help="The path to a config section or value", 31 help="The path to a config section or value",
35 nargs='?') 32 nargs='?')
36 33
37 def run(self, ctx): 34 def run(self, ctx):
35 import yaml
36 from piecrust.configuration import ConfigurationDumper
37
38 if ctx.args.path: 38 if ctx.args.path:
39 show = ctx.app.config.get(ctx.args.path) 39 show = ctx.app.config.get(ctx.args.path)
40 else: 40 else:
41 show = ctx.app.config.getAll() 41 show = ctx.app.config.getAll()
42 42
43 if show is not None: 43 if show is not None:
44 if isinstance(show, (dict, list)): 44 if isinstance(show, (dict, list)):
45 import yaml
46 out = yaml.dump(show, default_flow_style=False, 45 out = yaml.dump(show, default_flow_style=False,
47 Dumper=ConfigurationDumper) 46 Dumper=ConfigurationDumper)
48 logger.info(out) 47 logger.info(out)
49 else: 48 else:
50 logger.info(show) 49 logger.info(show)
145 help=("Match the exact given pattern, instead of any page " 144 help=("Match the exact given pattern, instead of any page "
146 "containing the pattern"), 145 "containing the pattern"),
147 action='store_true') 146 action='store_true')
148 147
149 def run(self, ctx): 148 def run(self, ctx):
149 import fnmatch
150 from piecrust.sources.fs import FSContentSourceBase
151
150 pattern = ctx.args.pattern 152 pattern = ctx.args.pattern
151 sources = list(ctx.app.sources) 153 sources = list(ctx.app.sources)
152 if not ctx.args.exact and pattern is not None: 154 if not ctx.args.exact and pattern is not None:
153 pattern = '*%s*' % pattern 155 pattern = '*%s*' % pattern
154 156