1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# This file is part of libmodulemd 4# Copyright (C) 2020 Stephen Gallagher 5# 6# Fedora-License-Identifier: MIT 7# SPDX-2.0-License-Identifier: MIT 8# SPDX-3.0-License-Identifier: MIT 9# 10# This program is free software. 11# For more information on the license, see COPYING. 12# For more information on free software, see 13# <https://www.gnu.org/philosophy/free-sw.en.html>. 14 15import xmlrpc.client 16import time 17 18KOJI_URL = "https://koji.fedoraproject.org/kojihub" 19 20 21def get_fedora_rawhide_version(session): 22 # Koji sometimes disconnects for no apparent reason. Retry up to 5 23 # times before failing. 24 for attempt in range(5): 25 try: 26 build_targets = session.getBuildTargets("rawhide") 27 except requests.exceptions.ConnectionError: 28 logging.warning( 29 "Connection lost while retrieving rawhide branch, retrying..." 30 ) 31 else: 32 # Succeeded this time, so break out of the loop 33 break 34 time.sleep(3) 35 36 return build_targets[0]["build_tag_name"].partition("-build")[0][1:] 37 38 39def main(): 40 session = xmlrpc.client.ServerProxy(KOJI_URL) 41 print(get_fedora_rawhide_version(session)) 42 43 44if __name__ == "__main__": 45 main() 46