3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#!/usr/bin/env python
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Extract build dependencies from an RPM .spec file.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Copyright (C) 2014 Red Hat
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is free software; you can redistribute it and/or modify
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# it under the terms of the GNU General Public License as published by
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# the Free Software Foundation; either version 3 of the License, or
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# (at your option) any later version.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is distributed in the hope that it will be useful,
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# but WITHOUT ANY WARRANTY; without even the implied warranty of
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# GNU General Public License for more details.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# You should have received a copy of the GNU General Public License
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# along with this program. If not, see <http://www.gnu.org/licenses/>.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovimport sys
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovimport re
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovimport rpm
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdef usage(file):
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov file.write(("Usage: %s SPEC\n" +
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov "Extract build dependencies from an RPM .spec file.\n") %
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov re.match(".*?([^/]+)$", sys.argv[0]).group(1))
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovif len(sys.argv) != 2:
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov usage(sys.stderr)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov sys.exit(1)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovspec = rpm.spec(sys.argv[1])
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfor d in rpm.ds(spec.sourceHeader, 'requires'):
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov print d.DNEVR()[2:]