buildtest.utils.shell
Module Contents
Classes
The Shell initializer takes an input shell and shell options and split |
Functions
Return a list of shell returned from /etc/shells file. If file exist we return a list |
|
Return a list of all python shells by running |
|
Return a dictionary of shell types and list of all shell interpreter. If shell is not present the entry will be an empty list. |
|
|
Return |
|
Return |
|
Return |
|
Return |
Attributes
- buildtest.utils.shell.get_shells()[source]
Return a list of shell returned from /etc/shells file. If file exist we return a list The command we run is the following which will omit any lines that start with
#
which is for comments. If file doesn’t exist we return an empty list$ grep '^[^#]' /etc/shells /bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh /bin/zsh
- Returns:
Return a list of shells
- Return type:
- buildtest.utils.shell.get_python_shells()[source]
Return a list of all python shells by running
which -a python3 python
which will report full path to all python and python3 wrapper in current $PATH.Shown below is an expected output.
$ which -a python3 python /Users/siddiq90/.local/share/virtualenvs/buildtest-KLOcDrW0/bin/python3 /usr/local/bin/python3 /usr/bin/python3 /Users/siddiq90/.local/share/virtualenvs/buildtest-KLOcDrW0/bin/python /usr/bin/python
- Returns:
A list of full path to python shells
- Return type:
- buildtest.utils.shell.shell_lookup()[source]
Return a dictionary of shell types and list of all shell interpreter. If shell is not present the entry will be an empty list.
- buildtest.utils.shell.is_bash_shell(name)[source]
Return
True
if specified shell is valid bash shell>>> is_bash_shell("bash") True >>> is_bash_shell("/bin/bash") True
- buildtest.utils.shell.is_sh_shell(name)[source]
Return
True
if specified shell is valid sh shell>>> is_sh_shell("sh") True >>> is_sh_shell("/bin/sh") True
- buildtest.utils.shell.python_shells
- buildtest.utils.shell.system_shells
- buildtest.utils.shell.shell_dict
- class buildtest.utils.shell.Shell(shell='bash')[source]
The Shell initializer takes an input shell and shell options and split string by shell name and options.
- Parameters:
shell (str) – Specify shell program and any options passed to shell. Defaults to
bash
- property opts
retrieve the shell opts that are set on init, and updated with setter
- property path
This method returns the full path to shell program using
shutil.which()
If shell program is not found we raise an exception. The shebang is is updated assuming path is valid which is just adding character ‘#!’ in front of path. The return is full path to shell program. This method automatically updates the shell path when there is a change in attribute self.name>>> shell = Shell("bash") >>> shell.path '/usr/bin/bash' >>> shell.name="sh" >>> shell.path '/usr/bin/sh'