From 2ad29101b9af122f720aeb6dbc14b850b6353c5c Mon Sep 17 00:00:00 2001 From: Randy Barlow Date: Aug 30 2016 15:51:13 +0000 Subject: Allow fedpkg to be compatible with both bodhi 1 and bodhi 2. This commit modified fedpkg to detect the installed version of the bodhi CLI, and then use the appropriate bodhi command to create the update. This will allow fedpkg to be installed on a variety of OS versions with differing bodhi client versions. Signed-off-by: Randy Barlow --- diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index a6a5d9e..7d0d37a 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -16,6 +16,7 @@ import git import re import fedora_cert import platform +import subprocess from .lookaside import FedoraLookasideCache from pyrpkg.utils import cached_property @@ -304,9 +305,20 @@ class Commands(pyrpkg.Commands): def update(self, template='bodhi.template', bugs=[]): """Submit an update to bodhi using the provided template.""" - # build up the bodhi arguments - cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template', - '--user', self.user, self.nvr] + # build up the bodhi arguments, based on which version of bodhi is + # installed + bodhi_major_version = _get_bodhi_version()[0] + if bodhi_major_version < 2: + cmd = ['bodhi', '--new', '--release', self.branch_merge, + '--file', 'bodhi.template', self.nvr, '--username', + self.user] + elif bodhi_major_version == 2: + cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template', + '--user', self.user, self.nvr] + else: + msg = 'This system has bodhi v{0}, which is unsupported.' + msg = msg.format(bodhi_major_version) + raise Exception(msg) self._run_command(cmd, shell=True) def load_kojisession(self, anon=False): @@ -320,6 +332,18 @@ class Commands(pyrpkg.Commands): raise +def _get_bodhi_version(): + """ + Use bodhi --version to determine the version of the Bodhi CLI that's + installed on the system, then return a list of the version components. + For example, if bodhi --version returns "2.1.9", this function will return + [2, 1, 9]. + """ + bodhi = subprocess.Popen(['bodhi', '--version'], stdout=subprocess.PIPE) + version = bodhi.communicate()[0].strip() + return [int(component) for component in version.split('.')] + + if __name__ == "__main__": from fedpkg.__main__ import main main()