:py:mod:`buildtest.utils.shell` =============================== .. py:module:: buildtest.utils.shell Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: buildtest.utils.shell.Shell Functions ~~~~~~~~~ .. autoapisummary:: buildtest.utils.shell.get_shells buildtest.utils.shell.get_python_shells buildtest.utils.shell.shell_lookup buildtest.utils.shell.is_bash_shell buildtest.utils.shell.is_sh_shell buildtest.utils.shell.is_csh_shell buildtest.utils.shell.is_zsh_shell Attributes ~~~~~~~~~~ .. autoapisummary:: buildtest.utils.shell.python_shells buildtest.utils.shell.system_shells buildtest.utils.shell.shell_dict .. py:function:: get_shells() 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 .. code-block:: console $ grep '^[^#]' /etc/shells /bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh /bin/zsh :returns: Return a list of shells :rtype: list .. py:function:: get_python_shells() 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. .. code-block:: console $ 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 :rtype: list .. py:function:: shell_lookup() Return a dictionary of shell types and list of all shell interpreter. If shell is not present the entry will be an empty list. .. py:function:: is_bash_shell(name) Return ``True`` if specified shell is valid bash shell >>> is_bash_shell("bash") True >>> is_bash_shell("/bin/bash") True .. py:function:: is_sh_shell(name) Return ``True`` if specified shell is valid sh shell >>> is_sh_shell("sh") True >>> is_sh_shell("/bin/sh") True .. py:function:: is_csh_shell(name) Return ``True`` if specified shell is valid csh shell .. py:function:: is_zsh_shell(name) Return ``True`` if specified shell is valid zsh shell .. py:data:: python_shells .. py:data:: system_shells .. py:data:: shell_dict .. py:class:: Shell(shell='bash') The Shell initializer takes an input shell and shell options and split string by shell name and options. :param shell: Specify shell program and any options passed to shell. Defaults to ``bash`` :type shell: str .. py:property:: opts retrieve the shell opts that are set on init, and updated with setter .. py: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' .. py:method:: __str__() Return str(self). .. py:method:: __repr__() Return repr(self). .. py:method:: get() Return shell attributes as a dictionary