Proc Module

This module handles communication with the operating system. Namely launching commands.

git_sh_sync.proc.CODE_SUCCESS = 0

Returncode of a successful command

git_sh_sync.proc.CHAR_NEWLINE = '\n'

Newline character used for detailed log output

class git_sh_sync.proc.Command(cmd, *, cwd=None, cin=None)

This is a class-based command runner using subprocess

__init__(cmd, *, cwd=None, cin=None)

Initialize a new command

Parameters:
  • cmd – Commandline of command to launch
  • cwd – Launch cmd inside some other current working directory
  • cin – Send data via stdin into cmd
cmd
Returns:Splitted output of original cmd
cwd
Returns:Current working directory or None
cin
Returns:Stdin data or None
exc
Returns:If launching the command raised some exception it is available here, otherwise None
code
Returns:The shell returncode after launching. Will be None on exception or before launch
stdout
Returns:Unmodified output of command stdout or empty string
Return type:str
stderr
Returns:Unmodified output of command stderr or empty string
Return type:str
command
Returns:Joined and quoted output of internal cmd
launched
Returns:True if command was launched, otherwise False

A command is considered launched if any of the exception or the returncode are not set to None

success
Returns:True if command launch was successful, otherwise False

A command is considered successful if no exception was thrown and the returncode equals CODE_SUCCESS

out
Returns:Splitted list output of stdout
Return type:list
err
Returns:Splitted list output of stderr
Return type:list
fields
Returns:Some information about the current command as dictionary
Return type:dict

Before the command was launched only cmd, cwd and cin are included. After launch the result is extended by stdout, stderr, exc and code.

__repr__()

String representation of current command. Utilizes fields() and pprint.pformat() for that.

repr

Expand __repr__() with triple-quotes and CHAR_NEWLINE.

__call__()

Launches the command.

Returns:Output of success

To avoid confusion a previously launched command will not run again, returning always False.