Skip to content

Commit

Permalink
repos rpc: use dnf native method of writing repository configuration
Browse files Browse the repository at this point in the history
Since we have new enough dnf version, native write_raw_configfile() can
be used, instead of external iniparse module.

QubesOS/qubes-issues#4550
  • Loading branch information
marmarek committed Aug 28, 2019
1 parent 1089a7a commit 9962fab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 4 additions & 12 deletions qubes-rpc/qubes.repos.Disable
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# (probably an exception)

import dnf
import iniparse
import os
import sys

Expand All @@ -17,16 +16,9 @@ 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'] = 0

with open(repo.repofile + '.new', 'w') as fp:
fp.write(str(ini))

os.rename(repo.repofile + '.new', repo.repofile)
base.conf.write_raw_configfile(repo.repofile,
repo.id,
base.conf.substitutions,
{'enabled': '0'})

print('ok')
16 changes: 4 additions & 12 deletions qubes-rpc/qubes.repos.Enable
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# (probably an exception)

import dnf
import iniparse
import os
import sys

Expand All @@ -17,16 +16,9 @@ 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)
base.conf.write_raw_configfile(repo.repofile,
repo.id,
base.conf.substitutions,
{'enabled': '1'})

print('ok')

2 comments on commit 9962fab

@strugee
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this change will ship with Qubes 4.1, right?

@marmarek
Copy link
Owner Author

@marmarek marmarek commented on 9962fab Aug 29, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.