confattr.types module
- class confattr.types.Path(value: str)
Bases:
object
This is the path as it is stored in the config file. It needs to be processed before usage. In the easiest case that is as easy as calling os.path.expanduser but you may want to do more like checking that the path exists or mounting an external drive.
- help = 'The path to a file or directory'
- type_name = 'path'
- class confattr.types.Regex
Bases:
str
- help = 'https://docs.python.org/3/library/re.html#regular-expression-syntax'
- type_name = 'regular expression'
- class confattr.types.SubprocessCommand(arg: confattr.types.SubprocessCommand | collections.abc.Sequence[str] | str, *, env: Optional[Mapping[str, str]] = None)
Bases:
object
- help = '\tA command to be executed as a subprocess.\n\tThe command is executed without a shell so redirection or wildcard expansion is not possible.\n\tSetting environment variables and piping like in a POSIX shell, however, are implemented in python and should work platform independently.\n\tIf you need a shell write the command to a file, insert an appropriate shebang line, make the file executable and set this value to the file.\n\t'
- parse_str(arg: str) None
Parses a string as returned by
__str__()
and initializes this objcet accordingly- Parameters
arg¶ – The string to be parsed
- Raises
ValueError – if arg is invalid
- Example:
If the input is
arg = 'ENVVAR1=val ENVVAR2= cmd --arg1 --arg2'
this function sets .. code-block:self.env = {'ENVVAR1' : 'val', 'ENVVAR2' : ''} self.cmd = ['cmd', '--arg1', '--arg2']
- python_callbacks: MutableMapping[str, Callable[[SubprocessCommand, Callable[[SubprocessCommand], ContextManager[SubprocessCommand]] | None], None]] = {}
- classmethod register_python_callback(name: str, func: Callable[[SubprocessCommand, Callable[[SubprocessCommand], ContextManager[SubprocessCommand]] | None], None]) None
- replace(wildcard: str, replacement: str) SubprocessCommand
- run(*, context: TYPE_CONTEXT | None) CompletedProcess[bytes] | None
Runs this command and returns when the command is finished.
- Parameters
context¶ – returns a context manager which can be used to stop and start an urwid screen.
It takes the command to be executed so that it can log the command and it returns the command to be executed so that it can modify the command, e.g. processing and intercepting some environment variables.
- Returns
The completed process
- Raises
OSError – e.g. if the program was not found
CalledProcessError – if the called program failed
- type_name = 'command'
- class confattr.types.SubprocessCommandWithAlternatives(commands: collections.abc.Sequence[confattr.types.SubprocessCommand | collections.abc.Sequence[str] | str] | str)
Bases:
object
- SEP = '||'
- get_preferred_command() SubprocessCommand
- help = '\n\tOne or more commands separated by ||.\n\tThe first command where the program is installed is executed. The other commands are ignored.\n\n\tThe command is executed without a shell so redirection or wildcard expansion is not possible.\n\tSetting environment variables and piping like in a POSIX shell, however, are implemented in python and should work platform independently.\n\tIf you need a shell write the command to a file, insert an appropriate shebang line, make the file executable and set this value to the file.\n\t'
- replace(wildcard: str, replacement: str) SubprocessCommand
- type_name = 'command with alternatives'