mirror of
https://github.com/clearlinux/autospec.git
synced 2026-06-16 02:45:56 +00:00
54636b48dd
The config module had a large amount of globals that were being touched across many modules that would import. This made changes to config very fragile as figuring out what would be modified in any given call chain was difficult to diagnose. It also made testing fragile as one would need to reset a given module's config import to the best of their knowledge before rerunning another test. To get away from that (and to try and reduce the number of globally modified variablies in autospec as a whole), refactor the config module to provide its state as part config class. The long running goal of changes like this is to better track what content can be updated by a particular function (if a function would have access to the config instance is now the hint rather than the config module getting imported).
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
#
|
|
# pkg_scan.py - part of autospec
|
|
# Copyright (C) 2017 Intel Corporation
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
import subprocess
|
|
|
|
import util
|
|
|
|
|
|
def get_whatrequires(pkg, yum_conf):
|
|
"""
|
|
Write list of packages.
|
|
|
|
Write packages that require the current package to a file
|
|
using dnf repoquery what-requires and --recursive commands.
|
|
"""
|
|
# clean up dnf cache to avoid 'no more mirrors repo' error
|
|
try:
|
|
subprocess.check_output(['dnf', '--config', yum_conf,
|
|
'--releasever', 'clear', 'clean', 'all'])
|
|
except subprocess.CalledProcessError as err:
|
|
util.print_warning("Unable to clean dnf repo: {}, {}".format(pkg, err))
|
|
return
|
|
|
|
try:
|
|
out = subprocess.check_output(['dnf', 'repoquery',
|
|
'--config', yum_conf,
|
|
'--releasever', 'clear',
|
|
'--archlist=src', '--recursive', '--queryformat=%{NAME}',
|
|
'--whatrequires', pkg]).decode('utf-8')
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
util.print_warning("dnf repoquery whatrequires for {} failed with: {}".format(pkg, err))
|
|
return
|
|
|
|
util.write_out('whatrequires', '# This file contains recursive sources that '
|
|
'require this package\n' + out)
|