""" * Author: "PeppermintOS Team(peppermintosteam@proton.me) * * License: SPDX-License-Identifier: GPL-3.0-or-later * * Clean up the working folder and move ISO and other files """ import os import shutil from pathlib import Path from datetime import date import time # 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' # Set the base destination location for the final ISO # Default base is /var/www/html/nightly/ BASE_DESTINATION = '/var/www/html/nightly' # Set the base ISO Name BASE_NAME = 'PeppermintOS' import paths import time # Set the home path used regardless the user logged in bstring = '~/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) def make_check_sum(): """ Generate the check sum files """ os.chdir(HOME_FOLDER + FUSATO_ROOT) current_working_directory = os.getcwd().replace('/', '/') for _, _, files in os.walk(current_working_directory): current_dir = os.getcwd().replace('/', '/') for root, dirs, files in os.walk(current_dir): for fiso in files: if fiso.endswith('.iso'): sha = "sha512sum " ext = "-sha512.checksum" gen_sum = sha + fiso + ' >' + fiso + ext os.system(gen_sum) def process_iso(base, arch, desktop): """ Process the ISO for a given base, architecture, and desktop. """ current_working_directory = os.listdir(".") today = str(date.today()) for files in current_working_directory: if files.endswith('.iso'): src_iso = files rdes = f"{BASE_NAME}-{base}_{arch}_{desktop.lower()}{today}.iso" des_iso =f"{BASE_DESTINATION}/{base.lower()}{arch}/{desktop.lower()}" os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) elif files.endswith('.checksum'): src_sum = files rdes_sum = f"{BASE_NAME}{base.capitalize()}_{arch}_{desktop.lower()}-sha512.checksum" des_sum = f"{BASE_DESTINATION}/{base.lower()}{arch}/{desktop.lower()}" os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def check_build_type(): """ Decided which ISO needs to be moved for nightly """ # Make sure you are in fustao os.chdir(HOME_FOLDER + FUSATO_ROOT) directory_path = HOME_FOLDER + FUSATO_ROOT file_function_mapping = { 'DEB.64xfc': ('deb', '64', 'XFCE'), 'DEB.32xfc': ('deb', '32', 'XFCE'), 'DEB.armxfc': ('deb', 'arm', 'XFCE'), 'DEV.64xfc': ('dev', '64', 'XFCE'), 'DEV.32xfc': ('dev', '32', 'XFCE'), 'DEV.armxfc': ('dev', 'arm', 'XFCE'), 'DEB.64gfb': ('deb', '64', 'GFB'), 'DEB.32gfb': ('deb', '32', 'GFB'), 'DEV.64gfb': ('dev', '64', 'GFB'), 'DEV.32gfb': ('dev', '32', 'GFB'), 'DEB.64opb': ('deb', '64', 'OPB'), 'DEB.32opb': ('deb', '32', 'OPB'), 'DEV.64opb': ('dev', '64', 'OPB'), 'DEV.32opb': ('dev', '32', 'OPB'), 'DEB.64kde': ('deb', '64', 'KDE'), 'DEB.32kde': ('deb', '32', 'KDE'), 'DEV.64kde': ('dev', '64', 'KDE'), 'DEV.32kde': ('dev', '32', 'KDE'), 'DEBLD.64loaded': ('deb', '64', 'LOADED'), 'DEVLD.64loaded': ('dev', '64', 'LOADED'), 'DEBLD.32loaded': ('deb', '32', 'LOADED'), 'DEVLD.32loaded': ('dev', '32', 'LOADED'), 'DEBSRV.64server': ('deb', '64', 'SERVER'), 'DEVSRV.64server': ('dev', '64', 'SERVER'), 'DEBMIN.64mini': ('deb', '64', 'MINI'), 'DEVMIN.64mini': ('dev', '64', 'MINI'), 'DEBMIN.32mini': ('deb', '32', 'MINI'), 'DEVMIN.32mini': ('dev', '32', 'MINI'), } def check_build(): """ Check what build is there and call the correct process function """ for file_name, params in file_function_mapping.items(): file_path = os.path.join(directory_path, file_name) if os.path.exists(file_path): print(f"You are building a {params[0]} {params[1]} {params[2]} ISO type") process_iso(*params) else: print(f"File {file_name} you're not building this ISO type!") check_build() def copy_iso_file_nightly_deb32(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Debian_32_' + today + '.iso' des_iso = '/var/www/html/nightly/deb32' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Debian_32-sha512.checksum' des_sum = '/var/www/html/nightly/deb32' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def copy_iso_file_nightly_deb64(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Debian_64_' + today + '.iso' des_iso = '/var/www/html/nightly/deb64' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Debian_64-sha512.checksum' des_sum = '/var/www/html/nightly/deb64' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def copy_iso_file_nightly_dev32(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Devuan_32_' + today + '.iso' des_iso = '/var/www/html/nightly/dev32' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Devuan_32-sha512.checksum' des_sum = '/var/www/html/nightly/dev32' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def copy_iso_file_nightly_dev64(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Devuan_64_' + today + '.iso' des_iso = '/var/www/html/nightly/dev64' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Devuan_64-sha512.checksum' des_sum = '/var/www/html/nightly/dev64' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def copy_iso_file_prod_deb64(): """ Copy the pro nightly and prep it for production push""" today = str(date.today()) nstring = '/var/www/html/nightly/deb64' nightly_folder = Path( nstring ).expanduser() string_nightly = str(nightly_folder) pstring= '/var/www/html/prod' production_folder = Path( pstring ).expanduser() string_production = str(production_folder) src_iso = string_nightly + '/PeppermintOS-Debian_64_' + today + '.iso' src_checksum = string_nightly + '/PeppermintOS-Debian_64-sha512.checksum' rdes = string_nightly + '/PeppermintOS-Debian-64.iso' des_iso = pstring os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) shutil.copy(src_checksum, des_iso) os.remove(rdes) os.remove(src_checksum) def copy_iso_file_nightly_debarm(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Debian_arm_' + today + '.iso' des_iso = '/var/www/html/nightly/debarm' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Debian_arm-sha512.checksum' des_sum = '/var/www/html/nightly/debarm' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def copy_iso_file_nightly_devarm(): """ Copy the new ISO to the Nightly folder""" # Set the home path used regardless the user logged in bstring = '/home/pepadmin/bubbles/iso_configs/fusato' home_folder = Path( bstring ).expanduser() string_home = str(home_folder) today = str(date.today()) os.chdir(home_folder) for root, dirs, files in os.walk(home_folder): for fiso in files: if fiso.endswith('.iso'): src_iso = string_home + '/' + fiso rdes = string_home + '/PeppermintOS-Devuan_arm_' + today + '.iso' des_iso = '/var/www/html/nightly/devarm' os.rename(src_iso, rdes) shutil.copy(rdes, des_iso) for fsum in files: if fsum.endswith('.checksum'): src_sum = string_home + '/' + fsum rdes_sum = string_home + '/PeppermintOS-Devuan_arm-sha512.checksum' des_sum = '/var/www/html/nightly/devarm' os.rename(src_sum, rdes_sum) shutil.copy(rdes_sum, des_sum) def kill_fusato(): """ Delete the fusato folder as it is no longer needed""" icstring ='~/bubbles/iso_configs/' ic_root = Path( icstring ).expanduser() os.chdir(ic_root) current_dir = os.getcwd().replace('/', '/') del_fldr = "fusato" del_path = os.path.join(current_dir, del_fldr) os.rmdir(del_path) def kill_old_iso(): """ Delete older ISOs""" base_path = BASE_DESTINATION arch_list = ['/deb32/', '/deb64/', '/debarm/', '/dev32/', '/dev64/', '/devarm/'] de_list = ['gfb', 'opb', 'xfce', 'loaded', 'server', 'mini', 'kde'] for archs in arch_list: for desktops in de_list: full_path = [] full_path.append(base_path + archs + desktops) for working_paths in full_path: N = 1 os.chdir(os.path.join(os.getcwd(), working_paths)) list_of_files = os.listdir() current_time = time.time() day = 86400 for fls in list_of_files: file_location = os.path.join(os.getcwd(), fls) file_time = os.stat(file_location).st_mtime if file_time < current_time - day*N: print(f" Delete : {fls}") os.remove(file_location) for p in paths.nightly_paths: N = 1 os.chdir(os.path.join(os.getcwd(), p)) list_of_files = os.listdir() current_time = time.time() day = 86400 for fls in list_of_files: file_location = os.path.join(os.getcwd(), fls) file_time = os.stat(file_location).st_mtime if file_time < current_time - day*N: print(f" Delete : {fls}") os.remove(file_location)