diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2023-02-07 11:46:38 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2023-02-09 13:26:06 +0100 |
commit | 782f46a1991ba6661c6b1e99a7fc4ca850a1e32e (patch) | |
tree | 4a919265dbe68453a1b3c8b6747965c78784f1de | |
parent | 7801d483d453dcc47b36429cc763fb5908c7a21b (diff) |
live: rewrite setup operationv1.2.5
Rewrites the setup operation using python-libfdisk module instead of an
external bash script. Consolidating the operation into Python's code,
limiting external subprocesses to well known programs and small
concrete tasks that are difficult to fully integrate into Python.
Use parttypes.py to fetch partition types from python-libfdisk module.
Use fs.py to create any specified supported filesystem.
OpenGnsys cache partitions are created labelling the partition as
"CACHE". Stops setting non-standard MBR hexcode (0xca) to the cache
partition in addition to the filesystem label.
Any partition specified as type EMPTY will be ignored.
-rw-r--r-- | src/live/ogOperations.py | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 943c0cc..6f52a5a 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -20,6 +20,7 @@ import fdisk from src.ogClient import ogClient from src.ogRest import ThreadState from src.live.partcodes import GUID_MAP +from src.live.parttypes import get_parttype from src.utils.legacy import * from src.utils.net import ethtool @@ -27,7 +28,7 @@ from src.utils.menu import generate_menu from src.utils.fs import * from src.utils.probe import os_probe, cache_probe from src.utils.disk import * -from src.utils.cache import generate_cache_txt +from src.utils.cache import generate_cache_txt, umount_cache, init_cache from src.utils.tiptorrent import * @@ -301,30 +302,57 @@ class OgLiveOperations: cache = request.getCache() cache_size = request.getCacheSize() partlist = request.getPartitionSetup() - cfg = f'dis={disk}*che={cache}*tch={cache_size}!' - for part in partlist: - cfg += f'par={part["partition"]}*cpt={part["code"]}*' \ - f'sfi={part["filesystem"]}*tam={part["size"]}*' \ - f'ope={part["format"]}%' + self._ogbrowser_clear_logs() + self._restartBrowser(self._url_log) + + diskname = get_disks()[int(disk)-1] + cxt = fdisk.Context(f'/dev/{diskname}', + details=True) + + if table_type == 'MSDOS': + cxt.create_disklabel('dos') + elif table_type == 'GPT': + cxt.create_disklabel('gpt') + for part in partlist: + logging.debug(f'Adding partition: {part}') + if part["code"] == 'EMPTY': + continue if ogRest.terminated: break + if part["code"] == 'CACHE': + umount_cache() + + pa = fdisk.Partition(start_follow_default=True, + end_follow_default=False, + partno_follow_default=False) + parttype = get_parttype(cxt, part["code"]) + size = int(part["size"]) + pa.size = (size * (1 << 10)) // cxt.sector_size + pa.partno = int(part["partition"]) - 1 + pa.type = parttype + cxt.add_partition(pa) + + cxt.write_disklabel() + subprocess.run('partprobe') - cmd = f'{ogClient.OG_PATH}interfaceAdm/Configurar {table_type} {cfg}' - try: - ogRest.proc = subprocess.Popen([cmd], - stdout=subprocess.PIPE, - shell=True, - executable=OG_SHELL) - (output, error) = ogRest.proc.communicate() - except: - logging.error('Exception when running setup subprocess') - raise ValueError('Error: Incorrect command value') + for part in partlist: + if part["filesystem"] == 'EMPTY': + continue + partition = int(part["partition"]) + fs = part["filesystem"].lower() + if fs == 'cache': + mkfs('ext4', int(disk), partition, label='CACHE') + init_cache() + else: + mkfs(fs, int(disk), partition) logging.info('Setup command OK') result = self.refresh(ogRest) + self._restartBrowser(self._url) + return result def image_restore(self, request, ogRest): |