utils
Classes:
| Name | Description |
|---|---|
CloneProgress |
Handler providing an interface to parse progress information emitted by git. |
KeyRequest |
Map LCD button or G-Key with an abstract request model. |
Functions:
| Name | Description |
|---|---|
check_bios_ver |
Check the DSC-BIOS release version. |
check_dcs_bios_entry |
Check DCS-BIOS entry in Export.lua file. |
check_dcs_ver |
Check DCS version and release type. |
check_github_repo |
Update git repository. |
check_ver_at_github |
Check a version of |
collect_debug_data |
Collect and zip all data for troubleshooting. |
count_files |
Count files with extension in a directory. |
detect_system_color_mode |
Detect the color mode of the system. |
download_file |
Download a file from URL and save to save_path. |
generate_bios_jsons_with_lupa |
Regenerate DCS-BIOS JSON files. |
get_all_git_refs |
Get a list of branches and tags for repo. |
get_config_yaml_location |
Get a location of YAML configuration files. |
get_default_yaml |
Return a full path to the default configuration file. |
get_depiction_of_ctrls |
Get the depiction of controls. |
get_full_bios_for_plane |
Collect full BIOS for plane with name. |
get_inputs_for_plane |
Get dict with all not empty inputs for plane. |
get_key_instance |
Resolve the provided key string into an instance of a valid key class based on a predefined set of classes and their respective resolution methods. |
get_list_of_ctrls |
Get a list of all controllers from dict with sections and inputs. |
get_plane_aliases |
Get a list of all YAML files for plane with name. |
get_planes_list |
Get a list of all DCS-BIOS supported planes with clickable cockpit. |
get_version_string |
Generate formatted string with version number. |
is_git_exec_present |
Check if the git executable is present in a system. |
is_git_object |
Check if git_obj is a valid Git reference. |
is_git_repo |
Check if dir_path ios Git repository. |
is_git_sha |
Check if a ref is a git commit SHA. |
load_json |
Load JSON from a file into a dictionary. |
load_yaml |
Load YAML from a file into a dictionary. |
replace_symbols |
Replace symbols in a string with specified replacements. |
rgb |
Convert a Color instance to its RGB components as a tuple of integers. |
rgba |
Convert a color to a single integer or tuple of integers. |
run_command |
Run command in shell as a subprocess. |
save_yaml |
Save disc as YAML file. |
substitute_symbols |
Substitute symbols in a string with specified replacements. |
verify_hashes |
Check hashes for a file. |
CloneProgress
Bases: RemoteProgress
Handler providing an interface to parse progress information emitted by git.
Initialize the progress handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Progress Qt6 signal |
required | |
|
Report stage Qt6 signal |
required |
Methods:
| Name | Description |
|---|---|
get_curr_op |
Get a stage name from OP code. |
update |
Call whenever the progress changes. |
Source code in src/dcspy/utils.py
411 412 413 414 415 416 417 418 419 420 | |
get_curr_op
Get a stage name from OP code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
OP code |
required |
Returns:
| Type | Description |
|---|---|
str
|
stage name |
Source code in src/dcspy/utils.py
422 423 424 425 426 427 428 429 430 | |
update
Call whenever the progress changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Integer allowing to be compared against Operation IDs and stage IDs. |
required |
|
A count of current absolute items |
required | |
|
The maximum count of items we expect. It may be None in case there is no maximum number of items or if it is (yet) unknown. |
None
|
|
|
str
|
It contains the number of bytes transferred. It may be used for other purposes as well. |
''
|
Source code in src/dcspy/utils.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
KeyRequest
KeyRequest(
yaml_path: Path, get_bios_fn: Callable[[str], BiosValue]
)
Map LCD button or G-Key with an abstract request model.
Load YAML with BIOS request for G-Keys and LCD buttons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to the airplane YAML file. |
required |
|
Callable[[str], BiosValue]
|
Function used to get a current BIOS value. |
required |
Methods:
| Name | Description |
|---|---|
get_request |
Get abstract representation for request ti be sent for requested button. |
set_request |
Update the internal string request for the specified button. |
Attributes:
| Name | Type | Description |
|---|---|---|
cycle_button_ctrl_name |
dict[str, int]
|
Return a dictionary with BIOS selectors to track changes of values for a cycle button to get current values. |
Source code in src/dcspy/utils.py
780 781 782 783 784 785 786 787 788 789 790 791 792 | |
cycle_button_ctrl_name
property
Return a dictionary with BIOS selectors to track changes of values for a cycle button to get current values.
get_request
get_request(button: AnyButton) -> RequestModel
Get abstract representation for request ti be sent for requested button.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AnyButton
|
LcdButton, Gkey or MouseButton |
required |
Returns:
| Type | Description |
|---|---|
RequestModel
|
RequestModel object |
Source code in src/dcspy/utils.py
799 800 801 802 803 804 805 806 | |
set_request
Update the internal string request for the specified button.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AnyButton
|
LcdButton, Gkey or MouseButton |
required |
|
str
|
The raw request to set. |
required |
Source code in src/dcspy/utils.py
808 809 810 811 812 813 814 815 | |
check_bios_ver
Check the DSC-BIOS release version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path | str
|
Path to DCS-BIOS directory in the SavedGames folder |
required |
Returns:
| Type | Description |
|---|---|
Version
|
Version object |
Source code in src/dcspy/utils.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
check_dcs_bios_entry
check_dcs_bios_entry(
lua_dst_data: str, lua_dst_path: Path, temp_dir: Path
) -> str
Check DCS-BIOS entry in Export.lua file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Content of Export.lua |
required |
|
Path
|
Export.lua path |
required |
|
Path
|
Directory with DCS-BIOS archive |
required |
Returns:
| Type | Description |
|---|---|
str
|
Result of checks |
Source code in src/dcspy/utils.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
check_dcs_ver
Check DCS version and release type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to DCS installation directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
DCS version as strings |
Source code in src/dcspy/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
check_github_repo
check_github_repo(
git_ref: str,
repo_dir: Path,
repo: str,
update: bool = True,
progress: RemoteProgress | None = None,
) -> str
Update git repository.
Return SHA of the latest commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Any Git reference as a string |
required |
|
Path
|
Local directory for a repository |
required |
|
str
|
GitHub repository address |
required |
|
bool
|
Perform update process |
True
|
|
RemoteProgress | None
|
Progress callback |
None
|
Source code in src/dcspy/utils.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
check_ver_at_github
Check a version of
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Format ' |
required |
Returns:
| Type | Description |
|---|---|
Release
|
Release object with data |
Source code in src/dcspy/utils.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
collect_debug_data
collect_debug_data() -> Path
Collect and zip all data for troubleshooting.
Returns:
| Type | Description |
|---|---|
Path
|
Path object to ZIP file |
Source code in src/dcspy/utils.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
count_files
Count files with extension in a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
As Path object |
required |
|
str
|
File extension |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of files |
Source code in src/dcspy/utils.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
detect_system_color_mode
detect_system_color_mode() -> str
Detect the color mode of the system.
Registry will return 0 if Windows is in Dark Mode and 1 if Windows is in Light Mode. In case of error, it will return 'light' as default.
Returns:
| Type | Description |
|---|---|
str
|
Dark or light as string |
Source code in src/dcspy/utils.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | |
download_file
download_file(
url: str,
save_path: Path,
progress_fn: Callable[[int], None] | None = None,
) -> bool
Download a file from URL and save to save_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
URL address |
required |
|
Path
|
full path to save |
required |
|
Callable[[int], None] | None
|
a callable object to report download progress |
None
|
Source code in src/dcspy/utils.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
generate_bios_jsons_with_lupa
generate_bios_jsons_with_lupa(
dcs_save_games: Path,
local_compile="./Scripts/DCS-BIOS/test/compile/LocalCompile.lua",
) -> None
Regenerate DCS-BIOS JSON files.
Using the Lupa library, first it will try to use LuaJIT 2.1 if not, it will fall back to Lua 5.1
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Full path to the Saved Games\DCS directory. |
required |
|
Relative path to the LocalCompile.lua file. |
'./Scripts/DCS-BIOS/test/compile/LocalCompile.lua'
|
Source code in src/dcspy/utils.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
get_all_git_refs
Get a list of branches and tags for repo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Directory with a repository |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of git references as strings |
Source code in src/dcspy/utils.py
392 393 394 395 396 397 398 399 400 401 402 403 | |
get_config_yaml_location
get_config_yaml_location() -> Path
Get a location of YAML configuration files.
Source code in src/dcspy/utils.py
583 584 585 586 587 588 589 590 591 | |
get_default_yaml
get_default_yaml(local_appdata: bool = False) -> Path
Return a full path to the default configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
If True value C:/Users/ |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
Path like an object |
Source code in src/dcspy/utils.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
get_depiction_of_ctrls
get_depiction_of_ctrls(
inputs: dict[str, dict[str, ControlKeyData]],
) -> dict[str, ControlDepiction]
Get the depiction of controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, dict[str, ControlKeyData]]
|
Dictionary with ControlKeyData |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ControlDepiction]
|
A dictionary containing the depiction of controls. |
Source code in src/dcspy/utils.py
697 698 699 700 701 702 703 704 705 706 707 708 | |
get_full_bios_for_plane
cached
get_full_bios_for_plane(
plane: str, bios_dir: Path
) -> DcsBiosPlaneData
Collect full BIOS for plane with name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
BIOS plane name |
required |
|
Path
|
path to DCS-BIOS directory |
required |
Returns:
| Type | Description |
|---|---|
DcsBiosPlaneData
|
dict |
Source code in src/dcspy/utils.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |
get_inputs_for_plane
cached
Get dict with all not empty inputs for plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
BIOS plane name |
required |
|
Path
|
path to DCS-BIOS |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, ControlKeyData]]
|
dict. |
Source code in src/dcspy/utils.py
640 641 642 643 644 645 646 647 648 649 650 651 | |
get_key_instance
Resolve the provided key string into an instance of a valid key class based on a predefined set of classes and their respective resolution methods.
If the key string matches a class method's criteria, it returns the resolved key instance. If no match is found, an exception is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
A string representing the name or identifier of the key to be resolved into a key instance (e.g., Gkey, LcdButton, or MouseButton). |
required |
Returns:
| Type | Description |
|---|---|
AnyButton
|
An instance of a class (AnyButton) that corresponds to the provided key string, if successfully resolved. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the provided key string cannot be resolved into a valid key instance using the predefined classes and methods. |
Source code in src/dcspy/utils.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
get_list_of_ctrls
Get a list of all controllers from dict with sections and inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, dict[str, ControlKeyData]]
|
Dictionary with ControlKeyData |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of string |
Source code in src/dcspy/utils.py
654 655 656 657 658 659 660 661 662 663 664 665 666 | |
get_plane_aliases
cached
Get a list of all YAML files for plane with name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
BIOS plane name |
None
|
|
Path
|
path to DCS-BIOS |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
list of all YAML files for plane definition |
Source code in src/dcspy/utils.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
get_planes_list
cached
Get a list of all DCS-BIOS supported planes with clickable cockpit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to DCS-BIOS |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of all supported planes |
Source code in src/dcspy/utils.py
669 670 671 672 673 674 675 676 677 678 | |
get_version_string
Generate formatted string with version number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Format ' |
required |
|
str | Version
|
String or Version object. |
required |
|
bool
|
Version online. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted version as a string. |
Source code in src/dcspy/utils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
is_git_exec_present
is_git_exec_present() -> bool
Check if the git executable is present in a system.
Returns:
| Type | Description |
|---|---|
bool
|
True if git.exe is available |
Source code in src/dcspy/utils.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
is_git_object
Check if git_obj is a valid Git reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Directory with repository |
required |
|
str
|
Git reference to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if git_obj is git reference, False otherwise |
Source code in src/dcspy/utils.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
is_git_repo
Check if dir_path ios Git repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path as string |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if dir is a git repo |
Source code in src/dcspy/utils.py
210 211 212 213 214 215 216 217 218 219 220 221 222 | |
is_git_sha
Check if a ref is a git commit SHA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
Git Repository object |
required |
|
str
|
Git commit SHA as string |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if ref is SHA of git commit, False otherwise |
Source code in src/dcspy/utils.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
load_json
Load JSON from a file into a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Full path |
required |
Returns:
| Type | Description |
|---|---|
dict[Any, Any]
|
Python representation of JSON |
Source code in src/dcspy/utils.py
610 611 612 613 614 615 616 617 618 619 | |
load_yaml
Load YAML from a file into a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Full path to YAML file |
required |
Returns:
| Type | Description |
|---|---|
DcspyConfigYaml
|
Dictionary with data |
Source code in src/dcspy/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
replace_symbols
Replace symbols in a string with specified replacements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The string in which symbols will be replaced. |
required |
|
Sequence[Sequence[str]]
|
A sequence of sequences containing the original symbols and their replacement strings. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string with symbols to replace. |
Source code in src/dcspy/utils.py
724 725 726 727 728 729 730 731 732 733 734 | |
rgb
Convert a Color instance to its RGB components as a tuple of integers.
The function extracts the red, green, and blue components from the color's value, which is expected to be a single integer representing a 24-bit RGB color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Color
|
An instance of Color, whose value is a 24-bit RGB integer. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
A tuple containing the red, green, and blue components. |
Source code in src/dcspy/utils.py
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | |
rgba
Convert a color to a single integer or tuple of integers.
This depends on a given mode/alpha channel: * If a mode is an integer, then return a tuple of RGBA channels. * If a mode is a LcdMode.TRUE_COLOR, then return a tuple of RGBA channels. * If a mode is a LcdMode.BLACK_WHITE, then return a single integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Color
|
Color name to convert |
required |
|
LcdMode | int
|
Mode of the LCD or alpha channel as an integer |
TRUE_COLOR
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...] | int
|
tuple with RGBA channels or single integer |
Source code in src/dcspy/utils.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | |
run_command
Run command in shell as a subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sequence[str]
|
The command to be executed as a sequence of strings |
required |
|
Path | None
|
current working directory |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The return code of command |
Source code in src/dcspy/utils.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
save_yaml
Save disc as YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DcspyConfigYaml
|
Dictionary with data |
required |
|
Path
|
Full a path to YAML file |
required |
Source code in src/dcspy/utils.py
78 79 80 81 82 83 84 85 86 | |
substitute_symbols
Substitute symbols in a string with specified replacements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The input string to be processed |
required |
|
Sequence[Sequence[str]]
|
A list of symbol patterns and their corresponding replacements. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The processed string with symbols is replaced according to the provided symbol_replacement list. |
Source code in src/dcspy/utils.py
711 712 713 714 715 716 717 718 719 720 721 | |
verify_hashes
Check hashes for a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to the file |
required |
|
Path
|
Path to the digests file |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, dict[str, bool]]
|
Overall verdict and detailed results |
Source code in src/dcspy/utils.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | |