comparison piecrust/commands/builtin/admin.py @ 852:4850f8c21b6e

core: Start of the big refactor for PieCrust 3.0. * Everything is a `ContentSource`, including assets directories. * Most content sources are subclasses of the base file-system source. * A source is processed by a "pipeline", and there are 2 built-in pipelines, one for assets and one for pages. The asset pipeline is vaguely functional, but the page pipeline is completely broken right now. * Rewrite the baking process as just running appropriate pipelines on each content item. This should allow for better parallelization.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 17 May 2017 00:11:48 -0700
parents a85d08ffe1f6
children dcdec4b951a1
comparison
equal deleted inserted replaced
851:2c7e57d80bba 852:4850f8c21b6e
18 18
19 def setupParser(self, parser, app): 19 def setupParser(self, parser, app):
20 subparsers = parser.add_subparsers() 20 subparsers = parser.add_subparsers()
21 21
22 p = subparsers.add_parser( 22 p = subparsers.add_parser(
23 'init', 23 'init',
24 help="Creates a new administration panel website.") 24 help="Creates a new administration panel website.")
25 p.set_defaults(sub_func=self._initFoodTruck) 25 p.set_defaults(sub_func=self._initFoodTruck)
26 26
27 p = subparsers.add_parser( 27 p = subparsers.add_parser(
28 'genpass', 28 'genpass',
29 help=("Generates the hashed password for use as an " 29 help=("Generates the hashed password for use as an "
30 "admin password")) 30 "admin password"))
31 p.add_argument('password', help="The password to hash.") 31 p.add_argument('password', help="The password to hash.")
32 p.set_defaults(sub_func=self._generatePassword) 32 p.set_defaults(sub_func=self._generatePassword)
33 33
34 p = subparsers.add_parser( 34 p = subparsers.add_parser(
35 'run', 35 'run',
36 help="Runs the administrative panel website.") 36 help="Runs the administrative panel website.")
37 p.add_argument( 37 p.add_argument(
38 '-p', '--port', 38 '-p', '--port',
39 help="The port for the administrative panel website.", 39 help="The port for the administrative panel website.",
40 default=8090) 40 default=8090)
41 p.add_argument( 41 p.add_argument(
42 '-a', '--address', 42 '-a', '--address',
43 help="The host for the administrative panel website.", 43 help="The host for the administrative panel website.",
44 default='localhost') 44 default='localhost')
45 p.add_argument( 45 p.add_argument(
46 '--no-assets', 46 '--no-assets',
47 help="Don't process and monitor the asset folder(s).", 47 help="Don't process and monitor the asset folder(s).",
48 dest='monitor_assets', 48 dest='monitor_assets',
49 action='store_false') 49 action='store_false')
50 p.set_defaults(sub_func=self._runFoodTruck) 50 p.set_defaults(sub_func=self._runFoodTruck)
51 51
52 def checkedRun(self, ctx): 52 def checkedRun(self, ctx):
53 if ctx.app.root_dir is None: 53 if ctx.app.root_dir is None:
54 raise SiteNotFoundError(theme=ctx.app.theme_site) 54 raise SiteNotFoundError(theme=ctx.app.theme_site)
57 ctx.parser.parse_args(['admin', '--help']) 57 ctx.parser.parse_args(['admin', '--help'])
58 return 58 return
59 return ctx.args.sub_func(ctx) 59 return ctx.args.sub_func(ctx)
60 60
61 def _runFoodTruck(self, ctx): 61 def _runFoodTruck(self, ctx):
62 # See `_run_sse_check` in `piecrust.serving.wrappers` for an explanation 62 # See `_run_sse_check` in `piecrust.serving.wrappers` for an
63 # of this check. 63 # explanation of this check.
64 if (ctx.args.monitor_assets and ( 64 if (ctx.args.monitor_assets and (
65 not ctx.args.debug or 65 not ctx.args.debug or
66 os.environ.get('WERKZEUG_RUN_MAIN') == 'true')): 66 os.environ.get('WERKZEUG_RUN_MAIN') == 'true')):
67 from piecrust.app import PieCrustFactory
68 from piecrust.serving.procloop import ProcessingLoop 67 from piecrust.serving.procloop import ProcessingLoop
69 appfactory = PieCrustFactory( 68 out_dir = os.path.join(
70 ctx.app.root_dir, 69 ctx.app.root_dir, CACHE_DIR, 'foodtruck', 'server')
71 cache=ctx.app.cache.enabled, 70 proc_loop = ProcessingLoop(ctx.appfactory, out_dir)
72 cache_key=ctx.app.cache_key,
73 config_variant=ctx.config_variant,
74 config_values=ctx.config_values,
75 debug=ctx.app.debug,
76 theme_site=ctx.app.theme_site)
77 out_dir = os.path.join(ctx.app.root_dir, CACHE_DIR, 'foodtruck', 'server')
78 proc_loop = ProcessingLoop(appfactory, out_dir)
79 proc_loop.start() 71 proc_loop.start()
80 72
81 es = { 73 es = {
82 'FOODTRUCK_CMDLINE_MODE': True, 74 'FOODTRUCK_CMDLINE_MODE': True,
83 'FOODTRUCK_ROOT': ctx.app.root_dir} 75 'FOODTRUCK_ROOT': ctx.app.root_dir}
84 from piecrust.admin.main import run_foodtruck 76 from piecrust.admin.main import run_foodtruck
85 run_foodtruck( 77 run_foodtruck(
86 host=ctx.args.address, 78 host=ctx.args.address,
87 port=ctx.args.port, 79 port=ctx.args.port,
88 debug=ctx.args.debug, 80 debug=ctx.args.debug,
89 extra_settings=es) 81 extra_settings=es)
90 82
91 def _initFoodTruck(self, ctx): 83 def _initFoodTruck(self, ctx):
92 import getpass 84 import getpass
93 from piecrust.admin import bcryptfallback as bcrypt 85 from piecrust.admin import bcryptfallback as bcrypt
94 86
111 username: %(username)s 103 username: %(username)s
112 # You can generate another hashed password with `chef admin genpass`. 104 # You can generate another hashed password with `chef admin genpass`.
113 password: %(password)s 105 password: %(password)s
114 """ 106 """
115 ft_config = ft_config % { 107 ft_config = ft_config % {
116 'username': admin_username, 108 'username': admin_username,
117 'password': admin_password 109 'password': admin_password
118 } 110 }
119 with open('foodtruck.yml', 'w', encoding='utf8') as fp: 111 with open('foodtruck.yml', 'w', encoding='utf8') as fp:
120 fp.write(ft_config) 112 fp.write(ft_config)
121 113
122 flask_config = """ 114 flask_config = """
123 SECRET_KEY = %(secret_key)s 115 SECRET_KEY = %(secret_key)s