Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/docs/examples/python.rst
blob: 342ec5c7e86dc8dc1e8620dca14baf599a02f071 (plain)
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
54
55
56
57
58
59
.. _examples.python:

Python module
=============

Archinstall supports running in `module mode <https://docs.python.org/3/library/__main__.html>`_.
The way the library is invoked in module mode is limited to executing scripts under the **example** folder.

It's there for important to place any script or profile you wish to invoke in the examples folder prior to building and installing.

Pre-requisites
--------------

We'll assume you've followed the :ref:`installing.python.manual` method.
Before actually installing the library, you will need to place your custom installer-scripts under `./archinstall/examples/` as a python file.

More on how you create these in the next section.

.. warning::

    This is subject to change in the future as this method is currently a bit stiff. The script path will become a parameter. But for now, this is by design.

Creating a script
-----------------

Lets create a `test_installer` - installer as an example. This is assuming that the folder `./archinstall` is a git-clone of the main repo.
We begin by creating `./archinstall/examples/test_installer.py`. The placement here is important later.

This script can now already be called using `python -m archinstall test_installer` after a successful installation of the library itself.
But the script won't do much. So we'll do something simple like list all the hard drives as an example.

To do this, we'll begin by importing `archinstall` in our `./archinstall/examples/test_installer.py` and call some functions.

.. code-block:: python

    import archinstall
    
    all_drives = archinstall.list_drives()
    print(all_drives)

This should print out a list of drives and some meta-information about them.
As an example, this will do just fine.

Now, go ahead and install the library either as a user-module or system-wide.

Calling a module
----------------

Assuming you've followed the example in `Creating a script`_, you can now safely call it with:

.. code-block:: console

    python -m archinstall test_installer

This should now print all available drives on your system.

.. note::

    This should work on any system, not just Arch Linux based ones. But note that other functions in the library relies heavily on Arch Linux based commands to execute the installation steps. Such as `arch-chroot`.