Utilities API¶
OS Utilities¶
PGMob will try to abstract OS commands using classes that provide support for a specific OS.
- class pgmob.os.OSCommandResult(command: str)¶
Results of the OS command execution
- exit_code¶
command exit code
- Type:
int
- text¶
stdout and stderr together
- Type:
str
- raise_for_error()¶
Raises an exception when exist code is not 0.
- Raises:
PostgresShellCommandError – when exit code is not 0
- class pgmob.os.ShellEnv¶
Shell-like command line operations (/bin/sh)
- static get_os_command_wrapper() str ¶
Returns a wrapper for an OS command used by run_os_command method
- Returns:
wrapper for an OS command
- Return type:
str
- static join_path(*args) str ¶
Joins path according to the local OS rules. Deals with URLs and Posix paths
- Parameters:
*args – paths that need to be joined
- Returns:
Joined path string
- Return type:
str
- static quote(cmd: str) str ¶
Quotes command line argument for a shell function
- Parameters:
cmd (str) – command line argument to escape
- Returns:
quoted command line argument
- Return type:
str
General Utilities¶
Internal module utilities.
- class pgmob.util.Version(version)¶
Version object. Allows to track major, minor, build and revision versions, left to right.
- property base_version: str¶
The “base version” of the version.
>>> Version("1.2.3").base_version '1.2.3' >>> Version("1.2.3+abc").base_version '1.2.3' >>> Version("1!1.2.3+abc.dev1").base_version '1!1.2.3'
The “base version” is the public version of the project without any pre or post release markers.
- property dev: int | None¶
The development number of the version.
>>> print(Version("1.2.3").dev) None >>> Version("1.2.3.dev1").dev 1
- property epoch: int¶
The epoch of the version.
>>> Version("2.0.0").epoch 0 >>> Version("1!2.0.0").epoch 1
- property is_devrelease: bool¶
Whether this version is a development release.
>>> Version("1.2.3").is_devrelease False >>> Version("1.2.3.dev1").is_devrelease True
- property is_postrelease: bool¶
Whether this version is a post-release.
>>> Version("1.2.3").is_postrelease False >>> Version("1.2.3.post1").is_postrelease True
- property is_prerelease: bool¶
Whether this version is a pre-release.
>>> Version("1.2.3").is_prerelease False >>> Version("1.2.3a1").is_prerelease True >>> Version("1.2.3b1").is_prerelease True >>> Version("1.2.3rc1").is_prerelease True >>> Version("1.2.3dev1").is_prerelease True
- property local: str | None¶
The local version segment of the version.
>>> print(Version("1.2.3").local) None >>> Version("1.2.3+abc").local 'abc'
- property micro: int¶
The third item of
release
or0
if unavailable.>>> Version("1.2.3").micro 3 >>> Version("1").micro 0
- property minor: int¶
The second item of
release
or0
if unavailable.>>> Version("1.2.3").minor 2 >>> Version("1").minor 0
- property post: int | None¶
The post-release number of the version.
>>> print(Version("1.2.3").post) None >>> Version("1.2.3.post1").post 1
- property pre: Tuple[str, int] | None¶
The pre-release segment of the version.
>>> print(Version("1.2.3").pre) None >>> Version("1.2.3a1").pre ('a', 1) >>> Version("1.2.3b1").pre ('b', 1) >>> Version("1.2.3rc1").pre ('rc', 1)
- property public: str¶
The public portion of the version.
>>> Version("1.2.3").public '1.2.3' >>> Version("1.2.3+abc").public '1.2.3' >>> Version("1.2.3+abc.dev1").public '1.2.3'
- property release: Tuple[int, ...]¶
The components of the “release” segment of the version.
>>> Version("1.2.3").release (1, 2, 3) >>> Version("2.0.0").release (2, 0, 0) >>> Version("1!2.0.0.post0").release (2, 0, 0)
Includes trailing zeroes but not the epoch or any pre-release / development / post-release suffixes.
- pgmob.util.get_shell(name: str) str ¶
Retrieves shell code from a file in a ‘shell’ folder
- Parameters:
name (str) – file name w/o extension
- Returns:
file contents
- Return type:
str
- pgmob.util.get_sql(name: str, version: Version | None = None) SQL ¶
Retrieves SQL code from a file in a ‘sql’ folder
- pgmob.util.group_by(key: Callable[[...], str], seq: Sequence[_T]) Dict[str, List[_T]] ¶
Groups a list by key
- Parameters:
key – lambda function to extract the key from a value
seq – input items
- Returns:
a dictionary grouped by keys
- Return type:
dict