ck3-save-updater

Tools

The tools command finds and runs two kinds of tool:

tools run runs a tool of either kind by name, and tools path prints where one is. Nothing extra needs installing.

The command never changes a tool, and writes nothing anywhere. Each tool runs exactly as it would if you ran it yourself: as its own process, from your current folder, with your terminal’s input and output and the arguments you give. tools run exits with the tool’s own exit code. A toolbox tool runs as python -m ck3_save_migrator.toolbox.<name>. A script runs as a file, python <script>, never as a module, whatever else its folder holds.

Using it

ck3update tools list
ck3update tools list --dev
ck3update tools run record --county c_vianden "Old.ck3" "New.ck3"
ck3update tools run diff_saves "Old.ck3" "New.ck3"
ck3update tools path diff_saves

Every *.py file directly in the scripts folder is a script tool, named by its file name without .py. Other files and subfolders are not tools. Every module in the package’s toolbox that defines main is a toolbox tool; its helper modules are not. An unknown name is refused, naming it, with exit code 2.

Scripts that act on the game

Some scripts start the game, send input to its window, pause a running game’s threads to read them, or write files in the game’s folder under Documents. tools list marks each of them with [acts on the game: run needs --acts-on-game], and tools run refuses one unless you ask for it:

ck3update tools run --acts-on-game launch_load_test my-run -debug_mode

The flag goes after run and before the script’s name. Without it the command says why it stopped and exits with code 2. Nothing is started. Without the flag, --help on such a script prints its docstring and never starts it, whether or not it has a help of its own.

A script is marked by one comment line in its own source, so the mark stays with the script wherever it is copied:

# ck3update-tools: acts-on-game

Add that line to a script of your own that acts on the game. A script without the line runs as before.

Where the scripts are found

The first of these that is set:

  1. --scripts-dir <folder>, written after tools and before list, run or path: ck3update tools --scripts-dir my_scripts list;
  2. the environment variable CK3SM_SCRIPTS_DIR;
  3. the tests/one-offs folder of the source checkout the tool is running from. An installed package has no such folder.

The toolbox needs no scripts folder, so tools list, and tools run of a toolbox tool, work in an installed package. When no scripts folder is found, tools list --dev and a script name given to tools run or tools path say so and exit with code 2.

A tool in a run patch

A run patch can name a script from the scripts folder instead of spelling out its command:

[run]
tool = "edit_save"
args = ["@@input@@", "@@output@@"]

This runs <scripts folder>/edit_save.py with the Python running the tool, followed by args, which take the same @@name@@ variables as command: the same command tools run builds. It is the same as command = ["@@python@@", "<scripts folder>/edit_save.py", "@@input@@", "@@output@@"]. The scripts folder is the variable scripts_dir when given (--var scripts_dir=<folder>), else found as above; when there is none, or the script is not in it, the patch is refused, naming the folder. Like any run patch in a pack folder, it needs --allow-run, or a trusted pack in your packs folder.

A script marked as acting on the game (the # ck3update-tools: acts-on-game line above) gets the same gate here as in tools run. The patch must say so in its [run] table:

[run]
tool = "launch_load_test"
args = ["@@input@@"]
acts_on_game = true

Without acts_on_game = true, a patch naming such a script is refused before anything is written or started, naming the script. A patch naming an unmarked script needs no such line. acts_on_game goes with tool only.