fix: remove aur packages from pacman packages #1

Merged
amiraref merged 1 commit from fix-duplicate-packages into main 2024-09-04 14:09:30 -04:00
2 changed files with 222 additions and 23 deletions

163
.gitignore vendored Normal file
View file

@ -0,0 +1,163 @@
# custom
*.toml
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

View file

@ -3,46 +3,56 @@ import subprocess
import os
import argparse
def run_subprocess(command, verbose=False):
try:
if verbose:
result = subprocess.run(command)
else:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if result.returncode != 0:
print(f"Error running command: {' '.join(command)}")
return result
except subprocess.CalledProcessError as e:
print(f"Subprocess error: {e}")
def install_generic_packages(command, packages):
for package in packages:
print(f"Installing package: {package}")
run_subprocess(command + [package])
def install_packages(packages):
install_generic_packages(["sudo", "pacman", "-S", "--noconfirm"], packages)
def install_aur_packages(aur_packages):
install_generic_packages(["paru", "-S", "--noconfirm"], aur_packages)
def install_flatpak_packages(flatpak_packages):
install_generic_packages(["flatpak", "install", "-y"], flatpak_packages)
def clone_config(config):
for app, details in config.items():
if app == "nvim":
url = details['url']
url = details["url"]
target_dir = os.path.expanduser("~/.config/nvim")
print(f"Cloning Neovim config from {url} to {target_dir}")
run_subprocess(["git", "clone", url, target_dir])
def enable_systemd_services(services):
for service in services:
print(f"Enabling systemd service: {service}")
run_subprocess(["sudo", "systemctl", "enable", service])
run_subprocess(["sudo", "systemctl", "start", service])
def check_toml(toml_file):
try:
toml.load(toml_file)
@ -50,13 +60,21 @@ def check_toml(toml_file):
except toml.TomlDecodeError as e:
print(f"Error in {toml_file}: {e}")
def generate_system_toml(output_file):
# Get Pacman packages
pacman_packages = subprocess.check_output(["pacman", "-Qeq"], text=True).splitlines()
pacman_packages = subprocess.check_output(
["pacman", "-Qeq"], text=True
).splitlines()
# Get AUR packages (using paru or yay, assuming paru here)
aur_packages = subprocess.check_output(["paru", "-Qmq"], text=True).splitlines()
# Get Flatpak packages
flatpak_packages = subprocess.check_output(["flatpak", "list", "--app", "--columns=application"], text=True).splitlines()
flatpak_packages = subprocess.check_output(
["flatpak", "list", "--app", "--columns=application"], text=True
).splitlines()
# remove aur packages from pacman packages
pacman_packages = list(set(pacman_packages) - set(aur_packages))
# Create TOML structure
config = {
@ -83,14 +101,15 @@ def generate_system_toml(output_file):
print(f"TOML file saved as {output_file}")
def generate_file_toml(input_file, output_file):
config = {
"packages": {"packages": []},
"aur": {"aur_packages": []},
"flatpak": {"flatpak_packages": []}
"flatpak": {"flatpak_packages": []},
}
with open(input_file, 'r') as file:
with open(input_file, "r") as file:
for line in file:
line = line.strip()
if not line or ":" not in line:
@ -116,7 +135,7 @@ def generate_file_toml(input_file, output_file):
continue
# Write the config to the output TOML file
with open(output_file, 'w') as toml_file:
with open(output_file, "w") as toml_file:
toml.dump(config, toml_file)
print(f"TOML file generated at: {output_file}")
@ -133,13 +152,29 @@ def generate_file_toml(input_file, output_file):
print(f"TOML file saved as {output_file}")
def main():
parser = argparse.ArgumentParser(description="Install packages and manage configurations from a TOML file.")
parser.add_argument('--load', type=str, help='Path to the TOML file to load and install packages.')
parser.add_argument('--check', type=str, help='Path to the TOML file to check for errors.')
parser.add_argument('--generate-system', type=str, help='Generate a TOML file with system installed packages.')
parser.add_argument('--generate-file', type=str, nargs=2, metavar=('input', 'output'),
help='Generate a TOML file from a text file. Provide input and output file paths.')
parser = argparse.ArgumentParser(
description="Install packages and manage configurations from a TOML file."
)
parser.add_argument(
"--load", type=str, help="Path to the TOML file to load and install packages."
)
parser.add_argument(
"--check", type=str, help="Path to the TOML file to check for errors."
)
parser.add_argument(
"--generate-system",
type=str,
help="Generate a TOML file with system installed packages.",
)
parser.add_argument(
"--generate-file",
type=str,
nargs=2,
metavar=("input", "output"),
help="Generate a TOML file from a text file. Provide input and output file paths.",
)
args = parser.parse_args()
@ -152,24 +187,24 @@ def main():
return
# Install packages
if 'packages' in config:
install_packages(config['packages']['packages'])
if "packages" in config:
install_packages(config["packages"]["packages"])
# Install AUR packages
if 'aur' in config:
install_aur_packages(config['aur']['aur_packages'])
if "aur" in config:
install_aur_packages(config["aur"]["aur_packages"])
# Install Flatpak packages
if 'flatpak' in config:
install_flatpak_packages(config['flatpak']['flatpak_packages'])
if "flatpak" in config:
install_flatpak_packages(config["flatpak"]["flatpak_packages"])
# Clone configuration
if 'config' in config:
clone_config(config['config'])
if "config" in config:
clone_config(config["config"])
# Enable systemd services
if 'systemd' in config:
enable_systemd_services(config['systemd']['systemd_services'])
if "systemd" in config:
enable_systemd_services(config["systemd"]["systemd_services"])
elif args.check:
toml_file = args.check
@ -186,5 +221,6 @@ def main():
else:
print("Please provide a valid argument.")
if __name__ == "__main__":
main()