Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/docs/examples/python.rst
blob: 7226c8250518f91477b435cd3fd87f37ae2bfbf6 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
.. _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 `scripts`_ folder.

It's therefore 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 `scripts`_ 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 "`scripts`_:code:`/test_installer.py`". The placement here is important later.

This script can now already be called using :code:`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 :code:`archinstall` in our "`scripts`_:code:`/test_installer.py`" and call a function whtin ``archinstall``.

.. code-block:: python

    import archinstall

    print(archinstall.disk.device_handler.devices)

Now, go ahead and reference the :ref:`installing.python.manual` installation method.
After running ``python -m archinstall test_installer`` it should print something that looks like:

.. code-block:: text

   [
       BDevice(
           disk=<parted.disk.Disk object at 0x7fbe17156050>,
           device_info=_DeviceInfo(
               model='PC801 NVMe SK hynix 512GB',
               path=PosixPath('/dev/nvme0n1'),
               type='nvme',
               total_size=Size(value=512110190592, unit=<Unit.B: 1>,
               sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
               free_space_regions=[
                   <archinstall.lib.disk.device_model.DeviceGeometry object at 0x7fbe166c4250>,
                   <archinstall.lib.disk.device_model.DeviceGeometry object at 0x7fbe166c4c50>,
                   <archinstall.lib.disk.device_model.DeviceGeometry object at 0x7fbe166c4a10>],
               sector_size=SectorSize(value=512, unit=<Unit.B: 1>),
               read_only=False,
               dirty=False
           ),
           partition_infos=[
               _PartitionInfo(
                   partition=<parted.partition.Partition object at 0x7fbe166c4a90>,
                   name='primary',
                   type=<PartitionType.Primary: 'primary'>,
                   fs_type=<FilesystemType.Fat32: 'fat32'>,
                   path='/dev/nvme0n1p1',
                   start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
                   length=Size(value=535822336, unit=<Unit.B: 1>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
                   flags=[
                       <PartitionFlag.Boot: 1>,
                       <PartitionFlag.ESP: 18>
                   ],
                   partn=1,
                   partuuid='a26be943-c193-41f4-9930-9341cf5f6b19',
                   uuid='6EE9-2C00',
                   disk=<parted.disk.Disk object at 0x7fbe17156050>,
                   mountpoints=[
                       PosixPath('/boot')
                   ],
                   btrfs_subvol_infos=[]
               ),
               _PartitionInfo(...)
           ]
       )
   ]

That means your script is in the right place, and ``archinstall`` is working as intended.

.. note::

   Most calls, including the one above requires `root <https://en.wikipedia.org/wiki/Superuser>`_ privileges.


.. _scripts: https://github.com/archlinux/archinstall/tree/master/archinstall/scripts