Mercurial > piecrust2
comparison piecrust/commands/builtin/plugins.py @ 879:58ae026b4c31
chef: Optimize startup time.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Jun 2017 22:38:05 -0700 |
parents | 3900169ac81b |
children | 2394fd689590 |
comparison
equal
deleted
inserted
replaced
878:313db67cfc35 | 879:58ae026b4c31 |
---|---|
1 import logging | 1 import logging |
2 from piecrust.commands.base import ChefCommand | 2 from piecrust.commands.base import ChefCommand |
3 from piecrust.pathutil import SiteNotFoundError | |
4 | 3 |
5 | 4 |
6 logger = logging.getLogger(__name__) | 5 logger = logging.getLogger(__name__) |
7 | 6 |
8 | 7 |
18 if app.root_dir is None: | 17 if app.root_dir is None: |
19 return | 18 return |
20 | 19 |
21 subparsers = parser.add_subparsers() | 20 subparsers = parser.add_subparsers() |
22 p = subparsers.add_parser( | 21 p = subparsers.add_parser( |
23 'list', | 22 'list', |
24 help="Lists the plugins installed in the current website.") | 23 help="Lists the plugins installed in the current website.") |
25 p.add_argument( | 24 p.add_argument( |
26 '-a', '--all', | 25 '-a', '--all', |
27 action='store_true', | 26 action='store_true', |
28 help=("Also list all the available plugins for the " | 27 help=("Also list all the available plugins for the " |
29 "current environment. The installed one will have an " | 28 "current environment. The installed one will have an " |
30 "asterix (*).")) | 29 "asterix (*).")) |
31 p.set_defaults(sub_func=self._listPlugins) | 30 p.set_defaults(sub_func=self._listPlugins) |
32 | 31 |
33 def checkedRun(self, ctx): | 32 def checkedRun(self, ctx): |
33 from piecrust.pathutil import SiteNotFoundError | |
34 | |
34 if ctx.app.root_dir is None: | 35 if ctx.app.root_dir is None: |
35 raise SiteNotFoundError(theme=ctx.app.theme_site) | 36 raise SiteNotFoundError(theme=ctx.app.theme_site) |
36 | 37 |
37 if not hasattr(ctx.args, 'sub_func'): | 38 if not hasattr(ctx.args, 'sub_func'): |
38 ctx.parser.parse_args(['plugins', '--help']) | 39 ctx.parser.parse_args(['plugins', '--help']) |
39 return | 40 return |
40 ctx.args.sub_func(ctx) | 41 ctx.args.sub_func(ctx) |
41 | 42 |
42 def _listPlugins(self, ctx): | 43 def _listPlugins(self, ctx): |
44 import pip | |
45 | |
43 names = {} | 46 names = {} |
44 installed_suffix = '' | 47 installed_suffix = '' |
45 if ctx.args.all: | 48 if ctx.args.all: |
46 import pip | |
47 prefix = 'PieCrust-' | 49 prefix = 'PieCrust-' |
48 installed_packages = pip.get_installed_distributions() | 50 installed_packages = pip.get_installed_distributions() |
49 for plugin in installed_packages: | 51 for plugin in installed_packages: |
50 if not plugin.project_name.startswith(prefix): | 52 if not plugin.project_name.startswith(prefix): |
51 continue | 53 continue |