wuttjamaican.upgrades

Upgrade Handler

class wuttjamaican.upgrades.UpgradeHandler(config)[source]

Base class and default implementation for the upgrade handler.

See also get_upgrade_handler().

capture_pip_freeze_output(upgrade, occurrence)[source]

Run the pip freeze command and capture its output to file, in the given upgrade’s data folder.

This is called from do_execute() but only for the default upgrade target.

See also get_pip_path().

Parameters:
  • upgrade – Reference to the Upgrade record being executed.

  • occurrence – String identifier, should be "before" or "after" only.

Returns:

Output file path as string.

delete_files(upgrade)[source]

Delete all data files for the given upgrade.

Caller must use this method (first!) for full cleanup when deleting an upgrade record from the database.

Parameters:

upgrade – Reference to the Upgrade record.

do_execute(upgrade, user, **kwargs)[source]

Perform all steps required to fully execute an upgrade.

This first calls execute() and then will update the given upgrade record to reflect the result.

For the default upgrade target only, this will also call capture_pip_freeze_output() before and after the upgrade runs. This allows viewing the diff between them e.g. in web app.

Parameters:
  • upgrade – Reference to the Upgrade record to be executed.

  • user – Reference to the in-app User responsible for executing the upgrade.

  • **kwargs – Any additional kwargs are passed along to execute().

Returns:

Boolean indicating success of the upgrade.

execute(upgrade, user, **kwargs)[source]

Execute the given upgrade as the given user.

This will run the upgrade target command “as-is” via subprocess.call() with shell=True, and capture the STDOUT/STDERR streams to file.

Callers should generally avoid using this method directly and instead use do_execute().

Parameters:
  • upgrade – Reference to the Upgrade record to be executed.

  • user – Reference to the in-app User responsible for executing the upgrade.

  • **kwargs – Any additional kwargs are ignored by default; subclass may override if needed.

Returns:

Boolean indicating success of the command (i.e. if exit code was 0).

get_all_target_keys()[source]

Retrieve a list of keys for all configured upgrade targets.

Note that a default target will always be included, first in the list.

Returns:

List of string keys

get_all_targets()[source]

Retrieve an ordered dict of all configured upgrade targets.

The result would be something like:

OrderedDict([
    ("default", {
        "key": "default",
        "label": "Poser",
        "command": "/srv/envs/poser/app/upgrade.sh"
    }),
    ("another", {
        "key": "another",
        "label": "My Other App",
        "command": "/srv/envs/poser/app/upgrade-another.sh"
    }),
])

Note that a default target will always be included, first in the ordering.

Returns:

OrderedDict with all upgrade targets.

get_pip_path()[source]

Retrieve the path to pip executable.

This is called from capture_pip_freeze_output().

Returns:

File path as string

get_target(key)[source]

Retrieve the configured upgrade target for the given key.

The target is represented as a simple dict, e.g.:

{
    "key": "default",
    "label": "Poser",
    "command": "/srv/envs/poser/app/upgrade.sh",
}
Parameters:

key – Config key for the desired target.

Returns:

Target as dict.

get_upgrade_filepath(upgrade, filename=None, create=False)[source]

Get the path to upgrade’s data folder, or a file within it.

Parameters:
  • upgrade – Reference to the Upgrade record.

  • filename – Optional filename to append as suffix to the data folder path.

  • create – Pass True here if you want to ensure the data folder exists, creating it if necessary. This does not auto-create any files.

Returns:

Folder/file path as string.