Skip to content

Commit

Permalink
Support multiple repos defined in a single .repo file
Browse files Browse the repository at this point in the history
Fixes #165
  • Loading branch information
asdil12 committed Dec 12, 2023
1 parent 74a4bcd commit ba2f180
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
26 changes: 13 additions & 13 deletions opi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,19 @@ def get_repos():
try:
cp = configparser.ConfigParser()
cp.read(os.path.join(REPO_DIR, repo_file))
mainsec = cp.sections()[0]
if not bool(int(cp.get(mainsec, 'enabled'))):
continue
repo = {
'alias': mainsec,
'filename': re.sub(r'\.repo$', '', repo_file),
'name': cp[mainsec].get('name', mainsec),
'url': cp[mainsec].get('baseurl'),
'auto_refresh': bool(int(cp[mainsec].get('autorefresh', '0'))),
}
if cp.has_option(mainsec, 'gpgkey'):
repo['gpgkey'] = cp[mainsec].get('gpgkey')
yield Repository(**repo)
for alias in cp.sections():
if not bool(int(cp.get(alias, 'enabled'))):
continue
repo = {
'alias': alias,
'filename': re.sub(r'\.repo$', '', repo_file),
'name': cp[alias].get('name', alias),
'url': cp[alias].get('baseurl'),
'auto_refresh': bool(int(cp[alias].get('autorefresh', '0'))),
}
if cp.has_option(alias, 'gpgkey'):
repo['gpgkey'] = cp[alias].get('gpgkey')
yield Repository(**repo)
except Exception as e:
print(f"Error parsing '{repo_file}': {e}")

Expand Down
38 changes: 38 additions & 0 deletions test/09_install_with_multi_repos_in_single_file_non_interactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/python3

import sys
import pexpect
import subprocess

subprocess.check_call("cat /etc/zypp/repos.d/*.repo > /tmp/singlefile.repo", shell=True)
subprocess.check_call("rm -v /etc/zypp/repos.d/*.repo", shell=True)
subprocess.check_call("mv -v /tmp/singlefile.repo /etc/zypp/repos.d/", shell=True)

c = pexpect.spawn('./bin/opi -n html2text', logfile=sys.stdout.buffer, echo=False)

c.expect(r'([0-9]+)\. html2text', timeout=10)
c.expect('Pick a number')
c.expect(r'([0-9]+)\. [^ ]*(openSUSE-Tumbleweed-Oss|Main Repository)', timeout=10)
c.expect('Installing from existing repo', timeout=10)
c.expect('Continue?', timeout=60)
c.interact()
c.wait()
c.close()
print()
assert c.exitstatus == 0, f'Exit code: {c.exitstatus}'
subprocess.check_call(['rpm', '-qi', 'html2text'])


c = pexpect.spawn('./bin/opi -n zfs', logfile=sys.stdout.buffer, echo=False)

c.expect(r'([0-9]+)\. zfs', timeout=10)
c.expect('Pick a number')
c.expect(r'([0-9]+)\. [^ ]*(filesystems)', timeout=10)
c.expect('Adding repo \'filesystems\'', timeout=10)
c.expect('Continue?', timeout=60)
c.interact()
c.wait()
c.close()
print()
assert c.exitstatus == 0, f'Exit code: {c.exitstatus}'
subprocess.check_call(['rpm', '-qi', 'zfs'])

0 comments on commit ba2f180

Please sign in to comment.