diff --git a/gwkoji/packager.py b/gwkoji/packager.py index 19ac65b0f4fd9dc6d605d94b4d6d71e220c206e6..e8af0f13671dd854eb94600bb7c0bbea568c758e 100755 --- a/gwkoji/packager.py +++ b/gwkoji/packager.py @@ -32,6 +32,7 @@ import tempfile from . import ( __version__, koji, + rpm, ) from .build import build_src_rpm from .utils import source_type @@ -142,17 +143,6 @@ def parse_options(): return args -# method to get the package name from the source -def get_package_name_from_source_rpm(source): - try: - cmd = ['rpm', '--queryformat', '%{NAME}', '-qp', source] - pkg_name = subprocess.check_output(cmd) - except subprocess.CalledProcessError as e: - print('Unable to determine package name, %s' % e) - sys.exit(1) - return pkg_name.decode() - - # # main program # @@ -187,10 +177,14 @@ def main(): logger.info("temporary src.rpm generated as '{0}'".format(args.source)) # get pkg name from source rpm - if args.source_type != "git": - pkg_name = get_package_name_from_source_rpm(args.source) - logger.info('package name = %s' % pkg_name) - # how do we determine this when source is from git? + try: + if args.source_type != "git": + pkg_name = rpm.get_package_name_from_source_rpm(args.source) + logger.info('package name = %s' % pkg_name) + # how do we determine this when source is from git? + except subprocess.CalledProcessError as e: + logger.critical("unable to determine package name, %s" % e) + raise # check that we can authenticate to koji try: diff --git a/gwkoji/rpm.py b/gwkoji/rpm.py new file mode 100644 index 0000000000000000000000000000000000000000..be22c3ed79b50bf8f064f9bf70c541c429766de0 --- /dev/null +++ b/gwkoji/rpm.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright(C) 2019 Adam Mercer +# +# This file is part of gwkoji. +# +# gwkoji 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 . + +"""Interactions with rpm +""" + +import subprocess + + +# method to get the package name from the source +def get_package_name_from_source_rpm(source): + cmd = ['rpm', '--queryformat', '%{NAME}', '-qp', source] + return subprocess.check_output(cmd).decode()