3
0
Fork 0

fix: refactor InstallHandler slightly, for easier customization

This commit is contained in:
Lance Edgar 2026-01-03 20:45:07 -06:00
parent 3b096061e3
commit d6eca8db50

View file

@ -161,6 +161,17 @@ class InstallHandler(GenericHandler):
any problem is found the installer should exit with code 2. any problem is found the installer should exit with code 2.
This is normally called by :meth:`run()`. This is normally called by :meth:`run()`.
The default logic here just calls :meth:`check_appdir()`.
"""
self.check_appdir()
def check_appdir(self):
"""
Check if the :term:`app dir` already exists; exit with code 2
if so.
This is normally called from :meth:`sanity_check()`.
""" """
# appdir must not yet exist # appdir must not yet exist
appdir = os.path.join(sys.prefix, "app") appdir = os.path.join(sys.prefix, "app")
@ -340,19 +351,48 @@ class InstallHandler(GenericHandler):
File templates for this come from File templates for this come from
``wuttjamaican:templates/install`` by default. ``wuttjamaican:templates/install`` by default.
This method calls
:meth:`~wuttjamaican.app.AppHandler.make_appdir()` for the
basic structure and then :meth:`write_all_config_files()` for
the gory details.
""" """
# app handler makes appdir proper # app handler makes appdir proper
appdir = appdir or self.app.get_appdir() appdir = appdir or self.app.get_appdir()
self.app.make_appdir(appdir) self.app.make_appdir(appdir)
# but then we also generate some files... # but then we also generate some files...
self.write_all_config_files(appdir, context)
# wutta.conf self.rprint(f"\n\tappdir created at: [bold green]{appdir}[/bold green]")
def write_all_config_files(self, appdir, context):
"""
This method should write all config files within the app dir.
It's called from :meth:`make_appdir()`.
Subclass can override this for specialized installers.
Note that the app dir may or may not be newly-created, when
this method is called. Some installers may support a
"refresh" of the existing app dir.
Default logic (over)writes 3 files:
* ``wutta.conf``
* ``web.cof``
* ``upgrade.sh``
"""
self.write_wutta_conf(appdir, context)
self.write_web_conf(appdir, context)
self.write_upgrade_sh(appdir, context)
def write_wutta_conf(self, appdir, context):
self.make_config_file( self.make_config_file(
"wutta.conf.mako", os.path.join(appdir, "wutta.conf"), **context "wutta.conf.mako", os.path.join(appdir, "wutta.conf"), **context
) )
# web.conf def write_web_conf(self, appdir, context):
web_context = dict(context) web_context = dict(context)
web_context.setdefault("beaker_key", context.get("pkg_name", "poser")) web_context.setdefault("beaker_key", context.get("pkg_name", "poser"))
web_context.setdefault("beaker_secret", "TODO_YOU_SHOULD_CHANGE_THIS") web_context.setdefault("beaker_secret", "TODO_YOU_SHOULD_CHANGE_THIS")
@ -362,7 +402,7 @@ class InstallHandler(GenericHandler):
"web.conf.mako", os.path.join(appdir, "web.conf"), **web_context "web.conf.mako", os.path.join(appdir, "web.conf"), **web_context
) )
# upgrade.sh def write_upgrade_sh(self, appdir, context):
template = self.templates.get_template("upgrade.sh.mako") template = self.templates.get_template("upgrade.sh.mako")
output_path = os.path.join(appdir, "upgrade.sh") output_path = os.path.join(appdir, "upgrade.sh")
self.render_mako_template(template, context, output_path=output_path) self.render_mako_template(template, context, output_path=output_path)
@ -371,8 +411,6 @@ class InstallHandler(GenericHandler):
stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH,
) )
self.rprint(f"\n\tappdir created at: [bold green]{appdir}[/bold green]")
def render_mako_template( def render_mako_template(
self, self,
template, template,