From a67b4055cdd85edb781b644c354d5bfbca9c2e98 Mon Sep 17 00:00:00 2001 From: acidburnmonkey Date: Sat, 23 Nov 2024 12:57:22 -0500 Subject: [PATCH] rewrite of data.config parser to add headers and flatpak --- README.md | 4 ++-- data.txt => data.config | 18 ++++++++------ rice-cook.py | 52 +++++++++++++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 16 deletions(-) rename data.txt => data.config (90%) diff --git a/README.md b/README.md index 87aab78..66f2d1e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This is a python script made to rice a blank fedora install into my custom hyprl * Hyrland * hyprcursor ,hypridle, hyprlang, hyprloc, hyprpaper, hyprpicker, hyprutils * Waybar -* Finally installs all programs given in data.txt +* Finally installs all programs given in data.config ________________________________________________________________________________ @@ -54,7 +54,7 @@ Should look like this . |---nvim |---ranger |---etc... -|---data.txt +|---data.config |---rice-cook.py ``` diff --git a/data.txt b/data.config similarity index 90% rename from data.txt rename to data.config index 6184e75..613fed1 100644 --- a/data.txt +++ b/data.config @@ -1,3 +1,4 @@ +[Main] hyprland hyprcursor hypridle @@ -15,19 +16,22 @@ flatpak neovim zsh pavucontrol -picom alsa-tools dunst feh +alsa-utils +rofi +mozilla-openh +pamixer +pavucontrol +network-manager-applet + +[other-programs] gnome-font-viewer gnome-software kitty ranger gnome-software -alsa-utils -rofi -mozilla-openh nemo -pamixer -pavucontrol -network-manager-applet + +[Flatpak] diff --git a/rice-cook.py b/rice-cook.py index c6e0bac..42b96e1 100755 --- a/rice-cook.py +++ b/rice-cook.py @@ -147,17 +147,48 @@ Type=Application ''') console.print('Created hyprland .desktop and wrappedhl :heavy_check_mark:', style='ok') -# install programs dnfmax list i can pass to dnf of programs to install +# install programs dnf def install_programs_dnf(): console.rule("Installing All Programs DNF ", style='checkt') programs =[] - with open("data.txt", 'r') as file: - for line in file: - programs.append(line.strip()) + others = [] + flatpaks= [] -#for some reason they have to be passed to dnf individually -# instead of unpacked list *programs + with open("data.config", 'r') as file: + lines = file.readlines() + + # Variables to store line numbers of headers + main_index = 0 + others_index = 0 + flatpak_index = 0 + + # Find the line numbers of headers + for index, line in enumerate(lines): + if '[Main]' in line: + main_index = index + elif '[other-programs]' in line: + others_index = index + elif '[Flatpak]' in line: + flatpak_index = index + + file.seek(0) + for index,line in enumerate(file): + #empty strings + if not line.strip(): + continue + elif index < others_index and ('[' not in line): + programs.append(line.strip()) + elif index > others_index and index < flatpak_index: + others.append(line.strip()) + elif index > flatpak_index: + flatpaks.append(line.strip()) + elif '[' in line.strip(): + continue + + #for some reason they have to be passed to dnf individually + # instead of unpacked list *programs + programs.extend(others) for program in programs: try: subprocess.run(f'dnf install -y {program} ', shell=True) @@ -165,7 +196,14 @@ def install_programs_dnf(): console.print(Exception(),":x:" , style='error') logging.critical(f"Error at Installing programs: {str(e)}") - logger.info('Installed programs in data.txt') + for fp in flatpaks: + try: + subprocess.run(f'flatpak install flathub -y {fp}', shell=True) + except Exception as e: + console.print(Exception(),":x:" , style='error') + logging.critical(f"Error at Installing flatpaks: {str(e)}") + + logger.info('Installed programs in data.config') ## checks for sudo