Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/pacman/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/pacman/config.py')
-rw-r--r--archinstall/lib/pacman/config.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/archinstall/lib/pacman/config.py b/archinstall/lib/pacman/config.py
new file mode 100644
index 00000000..60d202bc
--- /dev/null
+++ b/archinstall/lib/pacman/config.py
@@ -0,0 +1,33 @@
+import re
+from pathlib import Path
+from shutil import copy2
+from typing import List
+
+from .repo import Repo
+
+
+class Config:
+ def __init__(self, target: Path):
+ self.path = Path("/etc") / "pacman.conf"
+ self.chroot_path = target / "etc" / "pacman.conf"
+ self.patterns: List[re.Pattern] = []
+
+ def enable(self, repo: Repo):
+ self.patterns.append(re.compile(r"^#\s*\[{}\]$".format(repo.value)))
+
+ def apply(self):
+ if not self.patterns:
+ return
+ lines = iter(self.path.read_text().splitlines(keepends=True))
+ with open(self.path, 'w') as f:
+ for line in lines:
+ if any(pattern.match(line) for pattern in self.patterns):
+ # Uncomment this line and the next.
+ f.write(line.lstrip('#'))
+ f.write(next(lines).lstrip('#'))
+ else:
+ f.write(line)
+
+ def persist(self):
+ if self.patterns:
+ copy2(self.path, self.chroot_path)