hpcflow.sdk.submission.shells.powershell.WindowsPowerShell#
- class hpcflow.sdk.submission.shells.powershell.WindowsPowerShell(executable=None, os_args=None)#
Bases:
Shell
Class to represent using PowerShell on Windows to generate and submit a jobscript.
Methods
Produce code to check the looping status of part of a workflow.
Produce code to save a parameter's value into the workflow persistent store.
Produce code to assign the output of the command to a shell variable.
Get the command for submitting a non-scheduled jobscript.
Get powershell version information.
Get the command to wait for a workflow.
Prepare the jobscript path for use.
Prepare the element run directory names for use.
Process the application invocation key in the jobscript header arguments.
Perform any post-processing of an application invocation command name.
Format commands to run within a child scope.
Attributes
Arguments to pass to the shell.
Default for executable name.
Template for the jobscript header when directly executed.
Template for the element processing loop in a jobscript.
Indent for environment setup.
File extension for jobscripts.
Template for the common part of the jobscript header.
Basic indent.
Template for the jobscript body.
Template for the jobscript shebang line.
The executable to use plus any mandatory arguments.
The executable to use in a shebang line.
Template for the jobscript header when scheduled.
Template for the array handling code in a jobscript.
- JS_DIRECT_HEADER: ClassVar[str] = '{shebang}\n\n{header}\n{wait_command}\n'#
Template for the jobscript header when directly executed.
- JS_ELEMENT_LOOP: ClassVar[str] = 'for ($JS_elem_idx = 0; $JS_elem_idx -lt {num_elements}; $JS_elem_idx += 1) {{\n{main}\n}}\nSet-Location $WK_PATH\n'#
Template for the element processing loop in a jobscript.
- JS_HEADER: ClassVar[str] = 'function {workflow_app_alias} {{\n & {{\n{env_setup}{app_invoc} `\n --with-config log_file_path "$pwd/{run_log_file}" `\n --config-dir "{config_dir}" `\n --config-key "{config_invoc_key}" `\n $args\n }} @args\n}}\n\nfunction get_nth_line($file, $line) {{\n Get-Content $file | Select-Object -Skip $line -First 1\n}}\n\nfunction JoinMultiPath {{\n $numArgs = $args.Length\n $path = $args[0]\n for ($i = 1; $i -lt $numArgs; $i++) {{\n $path = Join-Path $path $args[$i]\n }}\n return $path\n}}\n\nfunction StartJobHere($block) {{\n $jobInitBlock = [scriptblock]::Create(@"\n Function wkflow_app {{ $function:wkflow_app }}\n Function get_nth_line {{ $function:get_nth_line }}\n Function JoinMultiPath {{ $function:JoinMultiPath }}\n Set-Location \'$pwd\'\n"@)\n Start-Job -InitializationScript $jobInitBlock -Script $block\n}}\n\n$WK_PATH = $(Get-Location)\n$WK_PATH_ARG = $WK_PATH\n$SUB_IDX = {sub_idx}\n$JS_IDX = {js_idx}\n$EAR_ID_FILE = JoinMultiPath $WK_PATH artifacts submissions $SUB_IDX {EAR_file_name}\n$ELEM_RUN_DIR_FILE = JoinMultiPath $WK_PATH artifacts submissions $SUB_IDX {element_run_dirs_file_path}\n'#
Template for the common part of the jobscript header.
- JS_MAIN: ClassVar[str] = '$elem_EAR_IDs = get_nth_line $EAR_ID_FILE $JS_elem_idx\n$elem_run_dirs = get_nth_line $ELEM_RUN_DIR_FILE $JS_elem_idx\n\nfor ($JS_act_idx = 0; $JS_act_idx -lt {num_actions}; $JS_act_idx += 1) {{\n\n $EAR_ID = ($elem_EAR_IDs -split "{EAR_files_delimiter}")[$JS_act_idx]\n if ($EAR_ID -eq -1) {{\n continue\n }}\n\n $run_dir = ($elem_run_dirs -split "{EAR_files_delimiter}")[$JS_act_idx]\n $run_dir_abs = "$WK_PATH\\$run_dir"\n Set-Location $run_dir_abs\n $app_stream_file = "$pwd/{run_stream_file}"\n\n $skip = {workflow_app_alias} internal workflow $WK_PATH get-ear-skipped $EAR_ID 2>> $app_stream_file\n $exc_sk = $LASTEXITCODE\n\n if ($exc_sk -eq 0) {{\n if ($skip -eq "1") {{\n continue\n }}\n\n {workflow_app_alias} internal workflow $WK_PATH write-commands $SUB_IDX $JS_IDX $JS_act_idx $EAR_ID 2>&1 >> $app_stream_file\n $exc_wc = $LASTEXITCODE\n\n {workflow_app_alias} internal workflow $WK_PATH set-ear-start $EAR_ID 2>&1 >> $app_stream_file\n $exc_se = $LASTEXITCODE\n\n if (($exc_wc -eq 0) -and ($exc_se -eq 0)) {{\n . (Join-Path $run_dir_abs "{commands_file_name}")\n $exit_code = $LASTEXITCODE\n }}\n else {{\n $exit_code = If ($exc_wc -ne 0) {{$exc_wc}} Else {{$exc_se}}\n }}\n }}\n else {{\n $exit_code = $exc_sk\n }}\n $global:LASTEXITCODE = $null\n {workflow_app_alias} internal workflow $WK_PATH set-ear-end $JS_IDX $JS_act_idx $EAR_ID "--" "$exit_code" 2>&1 >> $app_stream_file\n\n}}\n'#
Template for the jobscript body.
- format_loop_check(workflow_app_alias, loop_name, run_ID)#
Produce code to check the looping status of part of a workflow.
- format_save_parameter(workflow_app_alias, param_name, shell_var_name, EAR_ID, cmd_idx, stderr)#
Produce code to save a parameter’s value into the workflow persistent store.
- format_stream_assignment(shell_var_name, command)#
Produce code to assign the output of the command to a shell variable.
- get_direct_submit_command(js_path)#
Get the command for submitting a non-scheduled jobscript.
- get_version_info(exclude_os=False)#
Get powershell version information.
- Parameters:
exclude_os (bool) – If True, exclude operating system information.
- Return type:
VersionInfo
- get_wait_command(workflow_app_alias, sub_idx, deps)#
Get the command to wait for a workflow.
- os_args#
Arguments to pass to the shell.
- prepare_JS_path(js_path)#
Prepare the jobscript path for use.
- Parameters:
js_path (Path) –
- Return type:
- prepare_element_run_dirs(run_dirs)#
Prepare the element run directory names for use.
- process_JS_header_args(header_args)#
Process the application invocation key in the jobscript header arguments.
- Parameters:
header_args (JobscriptHeaderArgs) –
- Return type:
- static process_app_invoc_executable(app_invoc_exe)#
Perform any post-processing of an application invocation command name.