added slimParser
This commit is contained in:
@@ -29,7 +29,7 @@ xdg-desktop-portal-wlr
|
|||||||
qt5-qtwayland
|
qt5-qtwayland
|
||||||
qt6-qtwayland
|
qt6-qtwayland
|
||||||
|
|
||||||
[other-programs]
|
[Programs]
|
||||||
gnome-font-viewer
|
gnome-font-viewer
|
||||||
gnome-software
|
gnome-software
|
||||||
kitty
|
kitty
|
||||||
@@ -38,3 +38,7 @@ gnome-software
|
|||||||
nemo
|
nemo
|
||||||
|
|
||||||
[Flatpak]
|
[Flatpak]
|
||||||
|
|
||||||
|
[Repolist]
|
||||||
|
|
||||||
|
[Copr]
|
||||||
+19
-33
@@ -14,6 +14,8 @@ import gdown
|
|||||||
from git import Repo
|
from git import Repo
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.theme import Theme
|
from rich.theme import Theme
|
||||||
|
from slimParser import SlimParser
|
||||||
|
import slimParser
|
||||||
|
|
||||||
# pylint: disable=subprocess-run-check
|
# pylint: disable=subprocess-run-check
|
||||||
# pylint: disable=broad-exception-caught
|
# pylint: disable=broad-exception-caught
|
||||||
@@ -151,45 +153,29 @@ Type=Application ''')
|
|||||||
def install_programs_dnf():
|
def install_programs_dnf():
|
||||||
console.rule("Installing All Programs DNF ", style='checkt')
|
console.rule("Installing All Programs DNF ", style='checkt')
|
||||||
|
|
||||||
programs =[]
|
parser = SlimParser('data.conf')
|
||||||
others = []
|
parser.cleanAll()
|
||||||
flatpaks= []
|
|
||||||
|
|
||||||
with open("data.config", 'r') as file:
|
repos = parser.get('Repolist')
|
||||||
lines = file.readlines()
|
main = parser.get('Main')
|
||||||
|
programs = parser.get('Programs')
|
||||||
|
flatpaks= parser.get('Flatpak')
|
||||||
|
copr = parser.get('Copr')
|
||||||
|
|
||||||
# Variables to store line numbers of headers
|
|
||||||
main_index = 0
|
|
||||||
others_index = 0
|
|
||||||
flatpak_index = 0
|
|
||||||
|
|
||||||
# Find the line numbers of headers
|
#try to add repos
|
||||||
for index, line in enumerate(lines):
|
if repos:
|
||||||
if '[Main]' in line:
|
for url in repos:
|
||||||
main_index = index
|
try:
|
||||||
elif '[other-programs]' in line:
|
subprocess.run(f'dnf config-manager addrepo --from-repofile={url}')
|
||||||
others_index = index
|
except Exception as e:
|
||||||
elif '[Flatpak]' in line:
|
console.print(Exception(),":x:" , style='error')
|
||||||
flatpak_index = index
|
logging.critical(f"Error at Installing programs: {str(e)}")
|
||||||
|
|
||||||
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
|
#for some reason they have to be passed to dnf individually
|
||||||
# instead of unpacked list *programs
|
# instead of unpacked list *programs
|
||||||
programs.extend(others)
|
main.extend(programs)
|
||||||
for program in programs:
|
for program in main:
|
||||||
try:
|
try:
|
||||||
subprocess.run(f'dnf install -y {program} ', shell=True)
|
subprocess.run(f'dnf install -y {program} ', shell=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
'''
|
||||||
|
this script parses conf file [section] -> content as key value pairs of Slimparser()
|
||||||
|
'''
|
||||||
|
|
||||||
|
class SlimParser:
|
||||||
|
def __init__(self,file):
|
||||||
|
self.file = file
|
||||||
|
self.headers = {}
|
||||||
|
self.current_key = None
|
||||||
|
|
||||||
|
#run on init
|
||||||
|
with open(file, 'r') as f:
|
||||||
|
text = f.read()
|
||||||
|
|
||||||
|
lines = text.splitlines()
|
||||||
|
|
||||||
|
# Looks for [headers]
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
|
||||||
|
if (
|
||||||
|
line.startswith('[')
|
||||||
|
and line.endswith(']')
|
||||||
|
and len(line) > 2
|
||||||
|
and line.count('[') == 1
|
||||||
|
and line.count(']') == 1
|
||||||
|
):
|
||||||
|
section_name = line[1:-1].strip()
|
||||||
|
|
||||||
|
if section_name:
|
||||||
|
self.current_key = section_name
|
||||||
|
self.headers[self.current_key] = []
|
||||||
|
elif self.current_key:
|
||||||
|
self.headers[self.current_key].append(line)
|
||||||
|
|
||||||
|
|
||||||
|
def getHeaders(self):
|
||||||
|
return (self.headers.keys())
|
||||||
|
|
||||||
|
def get(self,section):
|
||||||
|
"""Returns the header"""
|
||||||
|
return self.headers.get(section)
|
||||||
|
|
||||||
|
def cleanSection(self, section):
|
||||||
|
"""Strips and removes empty lines, duplicates from a section."""
|
||||||
|
if section in self.headers:
|
||||||
|
self.headers[section] = list(set(
|
||||||
|
line.strip() for line in self.headers[section] if line.strip()
|
||||||
|
))
|
||||||
|
|
||||||
|
elif section not in self.headers:
|
||||||
|
raise ValueError(f"Section '{section}' not found in headers.")
|
||||||
|
|
||||||
|
def cleanAll(self):
|
||||||
|
"""Strips and removes empty lines, duplicates from a All the file."""
|
||||||
|
for section in self.headers.keys():
|
||||||
|
self.headers[section] = list(set(
|
||||||
|
line.strip() for line in self.headers[section] if line.strip()
|
||||||
|
))
|
||||||
Reference in New Issue
Block a user