bubbles/python_modules/build_iso.py

299 lines
10 KiB
Python

"""
* Author: "PeppermintOS Team(peppermintosteam@proton.me)
*
* License: SPDX-License-Identifier: GPL-3.0-or-later
*
* Move and copy files as needed
"""
import os
import subprocess
import shutil
from pathlib import Path
import argparse
import collections
import conf
import paths
import inflate_bubble
import finish_cleanup
import infra
# 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'
class BuildXfce:
"""
Determine what base to use and then build the ISO
"""
def __init__(self, sbase, sarch):
self.sbase = sbase
self.sarch = sarch
os.chdir(HOME_FOLDER + FUSATO_ROOT)
# Determine what base to build
if sbase == "deb":
self.debian_build()
elif sbase == "dev":
self.devuan_build()
else:
print("No base has been found")
def run_build(self):
""" Run and start the build process"""
# run_cmd = 'sudo lb build'
current_working_directory = os.getcwd()
os.chdir(HOME_FOLDER + FUSATO_ROOT)
print("CurrenD -" + current_working_directory)
# os.system(run_cmd)
def debian_build(self):
"""
Used to build the Debian base XFCE ISO
"""
if self.sarch == '_64':
# livebuild init
print("Begin Live Build init")
lbsetup = conf.lbset_deb64
os.system(lbsetup)
# Loop though commands
print("Run the 64 bit Debian commands")
cmd_list_64 = collections.deque(conf.build64_xfce_build)
list_size_64 = len(cmd_list_64)
for _ in range(list_size_64):
i = cmd_list_64.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
print("Run the CHROOT, Binary and Arch Classes")
infra.ChrootFolders("deb", "_64")
infra.BinaryFolders("deb", "_64")
infra.ArchitectureFiles("deb", "_64")
# Run the Build
print("Run the build commands for the ISO")
self.run_build()
# bld_list = collections.deque(conf.shared_run_build)
# list_size = len(bld_list)
# for _ in range(list_size):
# i = bld_list.popleft()
# execute = i + '()'
# exec(execute)
elif self.sarch == '_32':
lbsetup = conf.lbset_deb32
os.system(lbsetup)
cmd_list_32 = collections.deque(conf.build32_xfce_build)
list_size_32 = len(cmd_list_32)
for _ in range(list_size_32):
i = cmd_list_32.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
infra.ChrootFolders("deb", "_32")
infra.BinaryFolders("deb", "_32")
infra.ArchitectureFiles("deb", "_31")
# Run the Build
self.run_build()
elif self.sarch == '_arm':
lbsetup = conf.lbset_debarm
os.system(lbsetup)
cmd_list_arm = collections.deque(conf.buildarm_xfce_build)
list_size_arm = len(cmd_list_arm)
for _ in range(list_size_arm):
i = cmd_list_arm.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
infra.ChrootFolders("deb", "_arm")
infra.BinaryFolders("deb", "_arm")
infra.ArchitectureFiles("deb", "_arm")
# Run the Build
self.run_build()
else:
print("No active build specified")
def devuan_build(self):
"""
Used to build the Devuan base xfce ISO
"""
if self.sarch == '_64':
lbsetup = conf.lbset_dev64
os.system(lbsetup)
# Loop though commands
cmd_list_64 = collections.deque(conf.build64_xfce_build)
list_size_64 = len(cmd_list_64)
for _ in range(list_size_64):
i = cmd_list_64.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
infra.ChrootFolders("dev", "_64")
infra.BinaryFolders("dev", "_64")
infra.ArchitectureFiles("dev", "_64")
# Run the Build
self.run_build()
elif self.sarch == '_32':
lbsetup = conf.lbset_dev32
os.system(lbsetup)
cmd_list_32 = collections.deque(conf.build32_xfce_build)
list_size_32 = len(cmd_list_32)
for _ in range(list_size_32):
i = cmd_list_32.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
infra.ChrootFolders("dev", "_32")
infra.BinaryFolders("dev", "_32")
infra.ArchitectureFiles("dev", "_31")
# Run the build
self.run_build()
else:
lbsetup = conf.lbset_devarm
os.system(lbsetup)
cmd_list_arm = collections.deque(conf.buildarm_xfce_build)
list_size_arm = len(cmd_list_arm)
for list_size in range(list_size_arm):
i = cmd_list_arm.popleft()
execute = i + '()'
exec(execute)
# Run the specific classes
infra.ChrootFolders("dev", "_arm")
infra.BinaryFolders("dev", "_arm")
infra.ArchitectureFiles("dev", "_arm")
# Run the Build
self.run_build()
def readybuild():
"""" Make Ready the bld structure If fusato exists remove it.
and recreate it, otherwise just make a new folder named
fusato.
"""
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:
print('You have not specified a valid '
'build architecture!!'
)
def dgnomefb(self):
""" Arguments for the gnomefb """
if self.arguments.e == 'e-gnomefb':
if self.arguments.b == 'b-deb64':
readybuild()
print('run gnomefb builds deb64')
elif self.arguments.b == 'b-deb32':
readybuild()
print('run gnomefb builds deb32')
elif self.arguments.b == 'b-dev64':
readybuild()
print('run gnomefb builds dev64')
elif self.arguments.b == 'b-dev32':
readybuild()
print('run gnomefb builds dev32')
elif self.arguments.b == 'b-debarm':
readybuild()
print('run gnomefb builds debarm')
elif self.arguments.b == 'b-devarm':
readybuild()
print('run gnomefb builds devarm')
else:
print('You have not specified a valid '
'build architecture!!')
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:
print('You have not specified a valid '
'desktop environment!!')
Decsions()