""" * Author: "PeppermintOS Team(peppermintosteam@proton.me) * * License: SPDX-License-Identifier: GPL-3.0-or-later * * Build the ISOs for the system to be deployed """ import os import logging from pathlib import Path import argparse import collections import conf import infra import inflate_bubble import finish_cleanup # Set the home path used regardless the user logged in BSTRING_ISO_CONFIGS = '~/bubbles/iso_configs' HOME_FOLDER = str(Path(BSTRING_ISO_CONFIGS).expanduser()) FUSATO_ROOT = '/fusato' WPCHROOT = '/fusato/config/includes.chroot' # Set up the logging format logger = logging.getLogger() handler = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) # Common Logging Messages WRKING_DIR = "Current working directory" CFG_TREE_READY = "Config tree ready!" CFG_READY = "Configs in place start the ISO build process" START_LIVEBUILD = "Start Live-Build Process" BUILD_COMPLETED = "ISO build has completed successfully" BUILD_COMPLETED = "ISO is ready for usage." class BaseBuilder: def __init__(self, sbase, sarch, desktop_helper, build_list): self.sbase = sbase self.sarch = sarch self.desktop_helper = desktop_helper self.build_list = build_list # Change to the root of Fusato # then run the build os.chdir(HOME_FOLDER + FUSATO_ROOT) self.build_system() def lb_helper(self): if self.sbase == "deb": lbsetup = getattr(conf, f'LBSET_DEB{self.sarch[1:]}', None) elif self.sbase == "dev": lbsetup = getattr(conf, f'LBSET_DEV{self.sarch[1:]}', None) else: lbsetup = None if lbsetup: os.system(lbsetup) else: raise ValueError(f"Unsupported combination: sbase={self.sbase}, sarch={self.sarch[1:]}") def infra_helper(self): infra.ChrootFolders(self.sbase, self.sarch) infra.BinaryFolders(self.sbase, self.sarch) infra.ArchitectureFiles(self.sbase, self.sarch) infra.Archive(self.sbase, self.sarch) def desktop_helper(self): if self.sarch[1:] == "64": cmd_list = collections.deque(self.build_list) list_size = len(cmd_list) for _ in range(list_size): i = cmd_list.popleft() execute = i + '()' exec(execute) elif self.sarch[1:] == "32": cmd_list = collections.deque(self.build_list) list_size = len(cmd_list) for _ in range(list_size): i = cmd_list.popleft() execute = i + '()' exec(execute) elif self.sarch[1:] == "arm": cmd_list = collections.deque(self.build_list) list_size = len(cmd_list) for _ in range(list_size): i = cmd_list.popleft() execute = i + '()' exec(execute) else: cmd_list = None def cleanup_helper(self): finish_cleanup.make_check_sum() finish_cleanup.check_build_type_xfce() finish_cleanup.kill_old_iso() def build_system(self): current_working_directory = os.getcwd() dir_current = WRKING_DIR + current_working_directory logger.info(f"Building a {self.sbase}{self.sarch[1:]} bit ISO") logger.info(dir_current) self.lb_helper() self.desktop_helper() self.infra_helper() logger.info(CFG_READY) logger.info(START_LIVEBUILD) logger.info(dir_current) self.lb_helper() run_cmd = 'sudo lb build' os.chdir(HOME_FOLDER + FUSATO_ROOT) inflate_bubble.make_bld_xfce(self.sbase, self.sarch[1:]) logger.info(dir_current) os.system(run_cmd) logger.info(BUILD_COMPLETED) logger.info(dir_current) self.cleanup_helper() logger.info(BUILD_COMPLETED) class BuildXfce(BaseBuilder): def __init__(self, sbase, sarch): build_list = conf.build64_xfce_build if sarch[1:] == "64" else ( conf.build32_xfce_build if sarch[1:] == "32" else conf.buildarm_xfce_build ) super().__init__(sbase, sarch, self.xfce_helper, build_list) class BuildGflashback(BaseBuilder): def __init__(self, sbase, sarch): build_list = conf.build64_gfb_build if sarch[1:] == "64" else ( conf.build32_gfb_build if sarch[1:] == "32" else conf.buildarm_gfb_build ) super().__init__(sbase, sarch, self.gfb_helper, build_list) def readybuild(): """" Make Ready the bld structure If fusato exists remove it. and recreate it, otherwise just make a new folder named fusato. """ logger.info("Making ready the fusato build directory") os.chdir(HOME_FOLDER) if os.path.exists('fusato'): rm_cmd = "sudo rm -r -f fusato" os.system(rm_cmd) os.makedirs('fusato') else: os.makedirs('fusato') class Decisions: """ Arguments used to tell the application what to build """ def __init__(self, logger): """ Initialize the building """ self.argument_parser = argparse.ArgumentParser() self.argument_parser.add_argument("set", help="set what build to start", type=str ) self.argument_parser.add_argument("e", help="identify the desktop environment, e.g., e-xfce", type=str ) self.argument_parser.add_argument("b", help="identify the ISO to build, e.g., b-deb64", type=str ) self.arguments = self.argument_parser.parse_args() self.logger = logger self.make_build_decision() def make_build_decision(self): """ Make a decision on what to build """ desktop_methods = { 'e-gnomefb': self.dgnomefb, 'e-xfce': self.dxfce, 'e-openbox': self.dopenbox, } desktop_method = desktop_methods.get(self.arguments.e) if desktop_method: desktop_method() else: self.logger.critical("Unsupported desktop environment!") def build_iso(self, builder_class): """ Common method for building ISOs """ iso_builders = { 'b-deb64': builder_class("deb", "_64", self.logger), 'b-deb32': builder_class("deb", "_32", self.logger), 'b-dev64': builder_class("dev", "_64", self.logger), 'b-dev32': builder_class("dev", "_32", self.logger), 'b-debarm': builder_class("deb", "_arm", self.logger), 'b-devarm': builder_class("dev", "_arm", self.logger), } iso_builder = iso_builders.get(self.arguments.b) if iso_builder: readybuild() iso_builder.initialize() iso_builder.run_build() else: self.logger.critical("Unsupported ISO build!") def dxfce(self): """ Arguments for the XFCE """ self.build_iso(BuildXfce) def dgnomefb(self): """ Arguments for the gnomefb """ self.build_iso(BuildGflashback) def dopenbox(self): """ Arguments for Openbox """ # Add logic for Openbox Decisions()