qubes-core-admin-linux/qubes-rpc/qubes.repos.Enable
2019-04-08 12:55:50 -04:00

33 lines
648 B
Python
Executable File

#!/usr/bin/python3
# `ok` on stdout indicates success; any stderr output indicates an error
# (probably an exception)
import dnf
import iniparse
import os
import sys
os.umask(0o022)
base = dnf.Base()
base.read_all_repos()
reponame = sys.argv[1]
repo = base.repos[reponame]
# Loosely based on write_raw_configfile() from DNF source code, because
# that method was introduced in DNF 2.0 but Qubes dom0 has DNF 1.x.
with open(repo.repofile) as fp:
ini = iniparse.INIConfig(fp)
ini[reponame]['enabled'] = 1
with open(repo.repofile + '.new', 'w') as fp:
fp.write(str(ini))
os.rename(repo.repofile + '.new', repo.repofile)
print('ok')