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: BData

Parser for command line options.

__init__()[source]

Initialise the parser state.

### Returns: None - Constructor.

Return type:

None

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.

Parameters:
Return type:

None

configure_argument(short_arg, long_arg, desc_arg=None, has_value=False, example_value=None)[source]

[Deprecated] Wrapper preserved for backwards compatibility.

Parameters:
Return type:

None

parse()[source]

Parse command-line arguments using configured option metadata.

### Returns: bool - True on successful parsing, False when getopt fails.

Return type:

bool

parse_arguments()[source]

[Deprecated] Wrapper around parse().

### Returns: bool - Result of parse().

Return type:

bool

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.

Parameters:

long_arg (str)

Return type:

bool

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.

Parameters:

long_arg (str)

Return type:

str | None

dump()[source]

Return configured options metadata as a dictionary.

### Returns: Dict[str, Any] - Mapping of long option names to description metadata.

Return type:

Dict[str, Any]

help()[source]

Print a human-readable help summary to stdout.

### Returns: None - Help information printed to standard output.

Return type:

None

property args: Dict[str, Any]

Return parsed argument key/value data.

### Returns: Dict[str, Any] - Parsed arguments dictionary.

__setattr__(name, value)

Prevent dynamic attribute assignment on instances.

### Raises: * AttributeError: Attribute not previously declared.

Parameters:
Return type:

None

class jsktoolbox.systemtool.Env[source]

Bases: BData

Environment class.

__init__()[source]

Initialise environment lookups.

Return type:

None

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:

str

property is_64bits: bool

Return True when the interpreter runs in 64-bit mode.

### Returns: bool - True if running in 64-bit mode, False otherwise.

__setattr__(name, value)

Prevent dynamic attribute assignment on instances.

### Raises: * AttributeError: Attribute not previously declared.

Parameters:
Return type:

None

class jsktoolbox.systemtool.PathChecker(pathname, check_deep=True)[source]

Bases: BData

PathChecker class for filesystem path.

Parameters:
__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.

Parameters:
Return type:

None

__run__()[source]

Analyse the path and populate cached metadata.

### Returns: None - Internal state updated in place.

Return type:

None

__str__()[source]

Returns class data as string.

Return type:

str

__repr__()[source]

Returns string representation.

Return type:

str

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_file: bool

Return True when the path represents a file.

### Returns: bool - File flag.

Return True when the path represents a symlink.

### Returns: bool - Symlink flag.

property path: str

Return the original input path string.

### Returns: str - Pathname.

property posixpath: str | None

Return the resolved POSIX path when the target exists.

### Returns: Optional[str] - Resolved path or None.

create()[source]

Create intermediate directories or touch file as required.

### Returns: bool - True when the path exists after creation.

Return type:

bool

__setattr__(name, value)

Prevent dynamic attribute assignment on instances.

### Raises: * AttributeError: Attribute not previously declared.

Parameters:
Return type:

None