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 freezecommand and capture its output to file, in the given upgrade’s data folder.This is called from
do_execute()but only for thedefaultupgrade target.See also
get_pip_path().- Parameters:
upgrade – Reference to the
Upgraderecord 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
Upgraderecord.
- 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
defaultupgrade target only, this will also callcapture_pip_freeze_output()before and after the upgrade runs. This allows viewing the diff between them e.g. in web app.
- 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()withshell=True, and capture the STDOUT/STDERR streams to file.Callers should generally avoid using this method directly and instead use
do_execute().- Parameters:
- 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
defaulttarget 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
defaulttarget will always be included, first in the ordering.- Returns:
OrderedDictwith all upgrade targets.
- get_pip_path()[source]¶
Retrieve the path to
pipexecutable.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
Upgraderecord.filename – Optional filename to append as suffix to the data folder path.
create – Pass
Truehere 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.