bubbles/python_modules/build_iso.py

415 lines
14 KiB
Python
Raw Normal View History

"""
* Author: "PeppermintOS Team(peppermintosteam@proton.me)
*
* License: SPDX-License-Identifier: GPL-3.0-or-later
*
* Build the ISOs for the the system
"""
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
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):
self.sbase = sbase
self.sarch = sarch
# Change to the root of Fusato
# then run the buils
os.chdir(HOME_FOLDER + FUSATO_ROOT)
self.build_system()
def lb_helper(self):
"""
Helper for the lb setup this is shared for all builds
"""
if self.sbase == "deb":
if self.sarch[1:] == "64":
lbsetup = conf.LBSET_DEB64
os.system(lbsetup)
elif self.sarch[1:] == "32":
lbsetup = conf.LBSET_DEB32
os.system(lbsetup)
elif self.sarch[1:] == "arm":
lbsetup = conf.LBSET_DEBARM
os.system(lbsetup)
else:
lbsetup = None
elif self.sbase == "dev":
if self.sarch[1:] == "64":
lbsetup = conf.LBSET_DEV64
os.system(lbsetup)
elif self.sarch[1:] == "32":
lbsetup = conf.LBSET_DEV32
os.system(lbsetup)
elif self.sarch[1:] == "arm":
lbsetup = conf.LBSET_DEVARM
os.system(lbsetup)
else:
lbsetup = None
def infra_helper(self):
"""
Helper for the infra classes this is shared for all builds
"""
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 xfce_helper(self):
"""
Helper for the xfce desktop shared for all builds
"""
if self.sarch[1:] == "64":
cmd_list = collections.deque(conf.build64_xfce_build)
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(conf.build32_xfce_build)
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(conf.buildarm_xfce_build)
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):
if self.sbase == "deb":
finish_cleanup.make_check_sum()
finish_cleanup.copy_debian_xfce_based()
finish_cleanup.kill_old_iso()
else:
finish_cleanup.make_check_sum()
finish_cleanup.copy_devuan_xfce_based()
finish_cleanup.kill_old_iso()
def build_system(self):
""" Builds the ISO XFCE Depedning on the Arch """
current_working_directory = os.getcwd()
dir_current = "Current working directory" + 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):
self.sbase = sbase
self.sarch = sarch
# Change to the root of Fusato
# then run the buils
os.chdir(HOME_FOLDER + FUSATO_ROOT)
self.build_system()
def lb_helper(self):
"""
Helper for the lb setup this is shared for all builds
"""
if self.sbase == "deb":
if self.sarch[1:] == "64":
lbsetup = conf.LBSET_DEB64
os.system(lbsetup)
elif self.sarch[1:] == "32":
lbsetup = conf.LBSET_DEB32
os.system(lbsetup)
elif self.sarch[1:] == "arm":
lbsetup = conf.LBSET_DEBARM
os.system(lbsetup)
else:
lbsetup = None
elif self.sbase == "dev":
if self.sarch[1:] == "64":
lbsetup = conf.LBSET_DEV64
os.system(lbsetup)
elif self.sarch[1:] == "32":
lbsetup = conf.LBSET_DEV32
os.system(lbsetup)
elif self.sarch[1:] == "arm":
lbsetup = conf.LBSET_DEVARM
os.system(lbsetup)
else:
lbsetup = None
def infra_helper(self):
"""
Helper for the infra classes this is shared for all builds
"""
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 gfb_helper(self):
"""
Helper for the gfb desktop shared for all builds
"""
if self.sarch[1:] == "64":
cmd_list = collections.deque(conf.build64_gfb_build)
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(conf.build32_gfb_build)
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(conf.buildarm_gfb_build)
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):
if self.sbase == "deb":
finish_cleanup.make_check_sum()
finish_cleanup.copy_debian_gfb_based()
finish_cleanup.kill_old_iso()
else:
finish_cleanup.make_check_sum()
finish_cleanup.copy_devuan_gfb_based()
finish_cleanup.kill_old_iso()
def build_system(self):
""" Builds the ISO GFB Depedning on the Arch """
current_working_directory = os.getcwd()
dir_current = "Current working directory" + 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 GFB stuff
self.gfb_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_gnomeflashback(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)
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 Decsions:
"""
Aguments used to tell the application what to build
"""
def __init__(self):
# 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
if self.arguments.e == 'e-gnomefb':
self.dgnomefb()
elif self.arguments.e == 'e-xfce':
self.dxfce()
elif self.arguments.e == 'e-openbox':
self.dopenbox()
def dxfce(self):
""" Arguments for the XFCE """
if self.arguments.e == 'e-xfce':
if self.arguments.b == 'b-deb64':
readybuild()
BuildXfce("deb", "_64")
elif self.arguments.b == 'b-deb32':
readybuild()
BuildXfce("deb", "_32")
elif self.arguments.b == 'b-dev64':
readybuild()
BuildXfce("dev", "_64")
elif self.arguments.b == 'b-dev32':
readybuild()
BuildXfce("dev", "_32")
elif self.arguments.b == 'b-debarm':
readybuild()
BuildXfce("deb", "_arm")
elif self.arguments.b == 'b-devarm':
readybuild()
BuildXfce("dev", "_arm")
else:
logger.critical("You have not specified a build to process!")
def dgnomefb(self):
""" Arguments for the gnomefb """
if self.arguments.e == 'e-gnomefb':
if self.arguments.b == 'b-deb64':
readybuild()
BuildGflashback("deb", "_64")
elif self.arguments.b == 'b-deb32':
readybuild()
BuildGflashback("deb", "_32")
elif self.arguments.b == 'b-debarm':
readybuild()
BuildGflashback("deb", "_arm")
elif self.arguments.b == 'b-dev32':
readybuild()
BuildGflashback("dev", "_32")
elif self.arguments.b == 'b-dev64':
readybuild()
BuildGflashback("dev", "_64")
elif self.arguments.b == 'b-devarm':
readybuild()
BuildGflashback("dev", "_arm")
else:
logger.critical("You have not specified a build to process!")
def dopenbox(self):
""" Arguments for the openbox """
if self.arguments.e == 'e-openbox':
if self.arguments.b == 'b-deb64':
readybuild()
print('run openbox builds deb64')
elif self.arguments.b == 'b-deb32':
readybuild()
print('run openbox builds deb32')
elif self.arguments.b == 'b-dev64':
readybuild()
print('run openbox builds dev64')
elif self.arguments.b == 'b-dev32':
readybuild()
print('run openbox builds dev32')
elif self.arguments.b == 'b-debarm':
readybuild()
print('run openbox builds debarm')
elif self.arguments.b == 'b-devarm':
readybuild()
print('run openbox builds devarm')
else:
print('You have not specified a valid '
'build architecture!!')
else:
logger.critical("You have not specified a valid "
"desktop environment!!")
Decsions()