File: Executable.rst

package info (click to toggle)
python-pytooling 8.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,572 kB
  • sloc: python: 23,936; makefile: 13
file content (53 lines) | stat: -rw-r--r-- 1,354 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
.. _CLIABS/Executable:

Executable
##########

The :class:`~pyTooling.CLIAbstraction.Executable` is derived from :class:`~pyTooling.CLIAbstraction.Program`, which
represents an executable command line program. In addition, it offers an API to :class:`subprocess.Popen`, so an
abstracted command line program can be launched.

**Features:**

* Launch an abstracted CLI program using :class:`subproess.Popen`.
* Setup and modify the environment for the launched program.
* Provide a line-based STDOUT reader as generator.


Simple Example
**************

The following example implements a portion of the ``git`` program and its ``--version`` argument.

.. rubric:: Program Definition

.. code-block:: Python
   :name: EXEC:Example:Definition
   :caption: Git program defining --version argument.

   class Git(Executable):
     _executableNames: ClassVar[Dict[str, str]] = {
       "Darwin":  "git",
       "FreeBSD": "git",
       "Linux":   "git",
       "Windows": "git.exe"
     }

     @CLIArgument()
     class FlagVersion(LongFlag, name="version"):
       """Print the version information."""


.. rubric:: Program Usage

.. code-block:: Python
   :name: EXEC:Example:Usage
   :caption: Usage of the abstracted Git program.

   git = Git()
   git[git.FlagVersion] = True

   git.StartProcess()
   for line in git.GetLineReader():
     print(line)