systemtool¶
Author: Jacek ‘Szumak’ Kotlarski –<szumak@virthost.pl> Created: 2024-09-06
Purpose: Provide helpers for command-line parsing, environment inspection, and filesystem path validation used across the toolkit.
- class jsktoolbox.systemtool.CommandLineParser[source]¶
Bases:
BDataParser for command line options.
- configure_option(short_arg, long_arg, desc_arg=None, has_value=False, example_value=None)[source]¶
Register a command-line option and associated metadata.
### Arguments: * short_arg: Optional[str] - Optional one-character short form (None → placeholder). * long_arg: str - Long option name without leading dashes. * desc_arg: Optional[Union[str, List, Tuple]] - Optional description or sequence of lines. * has_value: bool - When True the option expects a value. * example_value: Optional[str] - Sample value appended to help text.
### Returns: None - Parser configuration is updated.
### Raises: * AttributeError: Raised when long_arg is empty.
- configure_argument(short_arg, long_arg, desc_arg=None, has_value=False, example_value=None)[source]¶
[Deprecated] Wrapper preserved for backwards compatibility.
- parse()[source]¶
Parse command-line arguments using configured option metadata.
### Returns: bool - True on successful parsing, False when getopt fails.
- Return type:
- parse_arguments()[source]¶
[Deprecated] Wrapper around
parse().### Returns: bool - Result of
parse().- Return type:
- has_option(long_arg)[source]¶
Check whether the provided long option was parsed.
### Arguments: * long_arg: str - Long option name without dashes.
### Returns: bool - True when the option exists in the parsed arguments.
- get_option(long_arg)[source]¶
Retrieve the option value converted to string.
### Arguments: * long_arg: str - Long option name without dashes.
### Returns: Optional[str] - Option value string or None when missing.
- dump()[source]¶
Return configured options metadata as a dictionary.
### Returns: Dict[str, Any] - Mapping of long option names to description metadata.
- help()[source]¶
Print a human-readable help summary to stdout.
### Returns: None - Help information printed to standard output.
- Return type:
None
- class jsktoolbox.systemtool.Env[source]¶
Bases:
BDataEnvironment class.
- property home: str¶
Return the detected home directory path.
### Returns: str - The path to the detected home directory.
- property tmpdir: str¶
Return the detected temporary directory path.
### Returns: str - The path to the detected temporary directory.
- property username: str¶
Return the effective login name if available.
### Returns: str - The effective login name, or empty string if not available.
- os_arch()[source]¶
Return the operating system architecture description.
### Returns: str - Human-readable architecture string (e.g. 64-bit).
- Return type:
- class jsktoolbox.systemtool.PathChecker(pathname, check_deep=True)[source]¶
Bases:
BDataPathChecker class for filesystem path.
- __init__(pathname, check_deep=True)[source]¶
Initialise path metadata for the provided pathname.
### Arguments: * pathname: str - Path string to inspect. * check_deep: bool - When True analyse path components recursively.
### Returns: None - Constructor.
### Raises: * TypeError: When pathname is missing or not a string. * ValueError: When pathname is an empty string.
- __run__()[source]¶
Analyse the path and populate cached metadata.
### Returns: None - Internal state updated in place.
- Return type:
None
- property dirname: str | None¶
Return the directory component when the path exists.
### Returns: Optional[str] - Directory path or None when unavailable.
- property filename: str | None¶
Return the filename component when the path points to a file.
### Returns: Optional[str] - Filename string or None.
- property exists: bool¶
Return True when the path exists on the filesystem.
### Returns: bool - Existence flag.
- property is_dir: bool¶
Return True when the path represents a directory.
### Returns: bool - Directory flag.
- property is_symlink: bool¶
Return True when the path represents a symlink.
### Returns: bool - Symlink flag.
- property posixpath: str | None¶
Return the resolved POSIX path when the target exists.
### Returns: Optional[str] - Resolved path or None.