srctools.cmdseq

CmdSeq.wc is Hammer’s configuration format for “expert” compiles, storing the various sequences of executables to compile maps with. This module allows for reading and writing this file format. Valve’s is a binary format, while both Strata Source and Hammer++ have alternate keyvalue formats which are human-readable.

Classes

class srctools.cmdseq.SpecialCommand

Bases: Enum

Special commands to run instead of an executable.

Depending on the command, these either take a single filename or a source destination pair.

CHANGE_DIR = 256

Change the working directory to the specified folder.

COPY_FILE = 257

Copies the source file to the destination filename.

DELETE_FILE = 258

Deletes the specified filename.

RENAME_FILE = 259

Renames the source file to the destination filename.

STRATA_COPY_FILE_IF_EXISTS = 261

Strata Source addition. If source exists, copies it to the destination filename.

class srctools.cmdseq.Command(
exe: str | SpecialCommand,
args: str,
*,
enabled: bool = True,
ensure_file: str | None = None,
use_proc_win: bool = True,
no_wait: bool = False,
)

A command to run.

exe: str | SpecialCommand

Either the path to the executable, or one of several special commands. A few presets are also available like $vis_exe.

enabled: bool

Whether this command is checked and should run.

ensure_file: str | None

If non-None, the command should fail if this file doesn’t exist after it runs.

use_proc_win: bool

Determines if the command should be executed directly, or captured in the ‘run process’ window. Obsolete for Hammer versions which use hammer_run_map_launcher.exe.

no_wait: bool

Indicates whether Hammer should wait for the command to finish before proceeding. Seems nonfunctional. This is normally set to non-wait for $game_exe commands.

Binary Format

Valve uses a binary file format, which can be read and written by these two functions.

srctools.cmdseq.parse(file: IO[bytes]) dict[str, list[Command]]

Read a list of sequences from a file.

This returns a dict mapping names to a list of sequences. The file may either be in the Valve binary format, or Strata/Hammer++’s keyvalues format.

srctools.cmdseq.write(
sequences: Mapping[str, Sequence[Command]],
file: FileWBinary,
) None

Write commands back to the standard binary file format.

Keyvalues Format

Strata Source and Hammer++ both independently switched over to using a keyvalues-based format instead, which is human-editable. The parse function detects and reads this automatically, but these functions are available to directly parse from keyvalues, and produce the tree to resave:

srctools.cmdseq.parse_keyvalues(
kv: Keyvalues,
) dict[str, list[Command]]

Parse Strata Source’s or Hammer++’s alternate Keyvalues file format.

This is automatically called by the standard parse function if the signature is detected.

srctools.cmdseq.build_keyvalues(
file_format: Literal['strata', 'hammer++'],
sequences: Mapping[str, Sequence[Command]],
) Keyvalues

Build Strata Source’s or Hammer++’s keyvalues file format, for export.

Parameters:
  • file_format – The file format to produce, "strata" or "hammer++". Hammer++ does not support the ensure_file, use_proc_win or no_wait attributes.

  • sequences – The sequences to build. The keys are the name of the commands.