|
Packit |
6f3914 |
# Copyright (C) 2015 Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit |
6f3914 |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit |
6f3914 |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit |
6f3914 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
6f3914 |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit |
6f3914 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit |
6f3914 |
# Public License for more details. You should have received a copy of the
|
|
Packit |
6f3914 |
# GNU General Public License along with this program; if not, write to the
|
|
Packit |
6f3914 |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6f3914 |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit |
6f3914 |
# source code or documentation are not subject to the GNU General Public
|
|
Packit |
6f3914 |
# License and may only be used or replicated with the express permission of
|
|
Packit |
6f3914 |
# Red Hat, Inc.
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
"""An extension that ensures that given features are present."""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import sys
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import dnf
|
|
Packit |
6f3914 |
import dnf.module
|
|
Packit |
6f3914 |
import dnf.rpm
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
if __name__ == '__main__':
|
|
Packit |
6f3914 |
FTR_SPECS = {'acpi-1.7-10.fc29.x86_64'} # <-- SET YOUR FEATURES HERE.
|
|
Packit |
6f3914 |
RPM_SPECS = {'./acpi-1.7-10.fc29.x86_64.rpm'} # <-- SET YOUR RPMS HERE.
|
|
Packit |
6f3914 |
GRP_SPECS = {'kde-desktop'} # <-- SET YOUR GROUPS HERE.
|
|
Packit |
6f3914 |
MODULE_SPEC = {"nodejs:10/default"} # <-- SET YOUR MODULES HERE.
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
with dnf.Base() as base:
|
|
Packit |
6f3914 |
# Substitutions are needed for correct interpretation of repo files.
|
|
Packit |
6f3914 |
RELEASEVER = dnf.rpm.detect_releasever(base.conf.installroot)
|
|
Packit |
6f3914 |
base.conf.substitutions['releasever'] = RELEASEVER
|
|
Packit |
6f3914 |
# Repositories are needed if we want to install anything.
|
|
Packit |
6f3914 |
base.read_all_repos()
|
|
Packit |
6f3914 |
# A sack is required by marking methods and dependency resolving.
|
|
Packit |
6f3914 |
base.fill_sack()
|
|
Packit |
6f3914 |
# Feature marking methods set the user request.
|
|
Packit |
6f3914 |
for ftr_spec in FTR_SPECS:
|
|
Packit |
6f3914 |
try:
|
|
Packit |
6f3914 |
base.install(ftr_spec)
|
|
Packit |
6f3914 |
except dnf.exceptions.MarkingError:
|
|
Packit |
6f3914 |
sys.exit('Feature(s) cannot be found: ' + ftr_spec)
|
|
Packit |
6f3914 |
# Package marking methods set the user request.
|
|
Packit |
6f3914 |
for pkg in base.add_remote_rpms(RPM_SPECS, strict=False):
|
|
Packit |
6f3914 |
try:
|
|
Packit |
6f3914 |
base.package_install(pkg, strict=False)
|
|
Packit |
6f3914 |
except dnf.exceptions.MarkingError:
|
|
Packit |
6f3914 |
sys.exit('RPM cannot be found: ' + pkg)
|
|
Packit |
6f3914 |
# Comps data reading initializes the base.comps attribute.
|
|
Packit |
6f3914 |
if GRP_SPECS:
|
|
Packit |
6f3914 |
base.read_comps(arch_filter=True)
|
|
Packit |
6f3914 |
# Group marking methods set the user request.
|
|
Packit |
6f3914 |
if MODULE_SPEC:
|
|
Packit |
6f3914 |
module_base = dnf.module.module_base.ModuleBase(base)
|
|
Packit |
6f3914 |
module_base.install(MODULE_SPEC, strict=False)
|
|
Packit |
6f3914 |
for grp_spec in GRP_SPECS:
|
|
Packit |
6f3914 |
group = base.comps.group_by_pattern(grp_spec)
|
|
Packit |
6f3914 |
if not group:
|
|
Packit |
6f3914 |
sys.exit('Group cannot be found: ' + grp_spec)
|
|
Packit |
6f3914 |
base.group_install(group.id, ['mandatory', 'default'])
|
|
Packit |
6f3914 |
# Resolving finds a transaction that allows the packages installation.
|
|
Packit |
6f3914 |
try:
|
|
Packit |
6f3914 |
base.resolve()
|
|
Packit |
6f3914 |
except dnf.exceptions.DepsolveError:
|
|
Packit |
6f3914 |
sys.exit('Dependencies cannot be resolved.')
|
|
Packit |
6f3914 |
# The packages to be installed must be downloaded first.
|
|
Packit |
6f3914 |
try:
|
|
Packit |
6f3914 |
base.download_packages(base.transaction.install_set)
|
|
Packit |
6f3914 |
except dnf.exceptions.DownloadError:
|
|
Packit |
6f3914 |
sys.exit('Required package cannot be downloaded.')
|
|
Packit |
6f3914 |
# The request can finally be fulfilled.
|
|
Packit |
6f3914 |
base.do_transaction()
|