""" * 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 from pathlib import Path import argparse import collections import logging 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 BuildXfce: """ Determine what base to use and then build the ISO """ def __init__(self, sbase, sarch): """ init the build process""" self.sbase = sbase self.sarch = sarch self.change_to_fusato_root_and_build() def change_to_fusato_root_and_build(self): """ change to the correct folder for the build """ os.chdir(HOME_FOLDER + FUSATO_ROOT) self.build_system() def lb_helper(self): """ Helper for the lb setup this is shared for all builds """ lbsetup = None if self.sbase in ["deb", "dev"]: arch_suffix = self.sarch[1:] if arch_suffix in ["64", "32", "arm"]: lbsetup = getattr(conf, f"LBSET_{self.sbase.upper()}{arch_suffix}" ) os.system(lbsetup) return lbsetup def infra_helper(self): """ Helper for the infra classes this is shared for all builds """ infra_methods = [infra.ChrootFolders, infra.BinaryFolders, infra.ArchitectureFiles, infra.Archive ] for method in infra_methods: method(self.sbase, self.sarch) def xfce_helper(self): """ Helper for the xfce desktop shared for all builds """ arch_suffix = self.sarch[1:] cmd_list = None if arch_suffix in ["64", "32", "arm"]: cmd_list = getattr(conf, f"build{arch_suffix}_xfce_build", []) for command in cmd_list: execute = command + '()' exec(execute) return cmd_list def cleanup_helper(self): """ Clean up Helper to move the ISOs to the nightly location """ finish_cleanup.make_check_sum() finish_cleanup.check_build_type_xfce() finish_cleanup.kill_old_iso() def build_system(self): """ Builds the ISO XFCE Depedning on the Arch """ current_working_directory = os.getcwd() dir_current = WRKING_DIR + current_working_directory logger.info("Building a " + self.sbase + self.sarch[1:] + " bit ISO") logger.info(dir_current) # Set the config tree self.lb_helper() # Start with the XFCE stuff self.xfce_helper() # Run the specific classes self.infra_helper() # Run the Build logger.info(CFG_READY) logger.info(START_LIVEBUILD) logger.info(dir_current) self.lb_helper() run_cmd = 'sudo lb build' current_working_directory = os.getcwd() os.chdir(HOME_FOLDER + FUSATO_ROOT) # Set the build inidcator 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 BuildGflashback: """ Determine what base to use and then build the ISO """ def __init__(self, sbase, sarch): """ init the build process""" self.sbase = sbase self.sarch = sarch self.change_to_fusato_root_and_build() def change_to_fusato_root_and_build(self): """ change to the correct folder for the build """ os.chdir(HOME_FOLDER + FUSATO_ROOT) self.build_system() def lb_helper(self): """ Helper for the lb setup this is shared for all builds """ lbsetup = None if self.sbase in ["deb", "dev"]: arch_suffix = self.sarch[1:] if arch_suffix in ["64", "32", "arm"]: lbsetup = getattr(conf, f"LBSET_{self.sbase.upper()}{arch_suffix}" ) os.system(lbsetup) return lbsetup def infra_helper(self): """ Helper for the infra classes this is shared for all builds """ infra_methods = [infra.ChrootFolders, infra.BinaryFolders, infra.ArchitectureFiles, infra.Archive ] for method in infra_methods: method(self.sbase, self.sarch) def gfb_helper(self): """ Helper for the gfb desktop shared for all builds """ arch_suffix = self.sarch[1:] cmd_list = None if arch_suffix in ["64", "32", "arm"]: cmd_list = getattr(conf, f"build{arch_suffix}_gfb_build", []) for command in cmd_list: execute = command + '()' exec(execute) return cmd_list def cleanup_helper(self): """ Clean up Helper to move the ISOs to the nightly location """ finish_cleanup.make_check_sum() finish_cleanup.check_build_type_gfb() finish_cleanup.kill_old_iso() def build_system(self): """ Builds the ISO GFB Depedning on the Arch """ 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.gfb_helper() self.infra_helper() logger.info(CFG_READY) logger.info(START_LIVEBUILD) logger.info(dir_current) run_cmd = 'sudo lb build' os.chdir(HOME_FOLDER + FUSATO_ROOT) inflate_bubble.make_bld_gnomeflashback(self.sbase, self.sarch[1:]) os.system(run_cmd) logger.info(BUILD_COMPLETED) logger.info(dir_current) self.cleanup_helper() logger.info(BUILD_COMPLETED) 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'): os.system("sudo rm -r -f fusato") os.makedirs('fusato') class Decsions: """ Aguments used to tell the application what to build """ def __init__(self): """ init the Decsions """ # Set up the terminal arguments 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 for example" " e-xfce", type=str ) self.argument_parser.add_argument("b", help="identify the ISO to" "build for example" " b-deb64", type=str ) self.arguments = self.argument_parser.parse_args() # Then determine what desktop build to look for desktop_build_function = getattr(self, f'd{self.arguments.e[2:]}', None) if desktop_build_function: desktop_build_function() def dxfce(self): """ Arguments for the XFCE """ build_type_mapping = { 'b-deb64': ("deb", "_64"), 'b-deb32': ("deb", "_32"), 'b-dev64': ("dev", "_64"), 'b-dev32': ("dev", "_32"), 'b-debarm': ("deb", "_arm"), 'b-devarm': ("dev", "_arm"), } build_argument = self.arguments.b if build_argument in build_type_mapping: readybuild() BuildXfce(*build_type_mapping[build_argument]) else: logger.critical("You have not specified a build to process!") def dgnomefb(self): """ Arguments for the gnomefb """ build_type_mapping = { 'b-deb64': ("deb", "_64"), 'b-deb32': ("deb", "_32"), 'b-dev64': ("dev", "_64"), 'b-dev32': ("dev", "_32"), 'b-debarm': ("deb", "_arm"), 'b-devarm': ("dev", "_arm"), } build_argument = self.arguments.b if build_argument in build_type_mapping: readybuild() BuildGflashback(*build_type_mapping[build_argument]) else: logger.critical("You have not specified a build to process!") def dopenbox(self): """ Arguments for the openbox """ build_type_mapping = { 'b-deb64': ("deb", "_64"), 'b-deb32': ("deb", "_32"), 'b-dev64': ("dev", "_64"), 'b-dev32': ("dev", "_32"), 'b-debarm': ("deb", "_arm"), 'b-devarm': ("dev", "_arm"), } build_argument = self.arguments.b if build_argument in build_type_mapping: pass #readybuild() #BuildGflashback(*build_type_mapping[build_argument]) else: logger.critical("You have not specified a build to process!") Decsions()