#!/usr/bin/python3 # # Quick and Dirty Python script to build C-Kermit v10 Beta snapshot # and collect all the build logs. # # This is meant for a Fedora 36 or later system, probably x86_64. # # David Cantrell # import datetime import os import requests import shutil import subprocess import tabulate import tarfile import tempfile # file containing OS version information OSRELEASE = '/etc/os-release' # what source snapshot to fetch #SNAPSHOT = "https://www.kermitproject.org/ftp/kermit/test/tar/u.tar.gz" SNAPSHOT = "https://kermitproject.org/ftp/kermit/tmp/u.tar.gz" # build targets to test TARGETS = ["linux-clang", "linux-pedantic", "linux+ssl", "linux+shadow+pam", "linux-nodeprecated", "linux+krb5 K5LIB=-L/usr/lib64", "linux+krb5+ssl K5LIB=-L/usr/lib64", "linux KFLAGS=-DNOTELNET", "linux KFLAGS=-DNORLOGIN", "linux-notcp", "linux-nodeprecated"] def get_var(script, var): cmd = 'echo $(. %s; echo $%s)' % (script, var) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, executable='/bin/sh') return p.stdout.readlines()[0].strip().decode('UTF-8') def capture_stdout(cmd): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, executable='/bin/sh') return p.stdout.readlines()[0].strip().decode('UTF-8') if __name__ == "__main__": table = [["OS and version", "Arch", "Build", "Date", "Size", "Compiler", "Status", "Details"]] cwd = os.getcwd() tmpdir = tempfile.mkdtemp() today = datetime.date.today() # fetch and unpack the snapshot srcfile = os.path.basename(SNAPSHOT) srcdir = os.path.join(tmpdir, "src") tardest = os.path.join(tmpdir, srcfile) if not os.path.isdir(srcdir): os.mkdir(srcdir) with requests.get(SNAPSHOT) as response, open(tardest, 'wb') as out: out.write(response.content) with tarfile.open(tardest) as src: src.extractall(srcdir) # create a directory for results logbase = "ckermit-10beta-logs-%s" % today.strftime("%Y-%m-%d") logs = os.path.join(tmpdir, logbase) if not os.path.isdir(logs): os.mkdir(logs) # read in /etc/os-release if os.path.isfile(OSRELEASE): osrel = "%s %s" % (get_var(OSRELEASE, "NAME"), get_var(OSRELEASE, "VERSION_ID")) else: osrel = "Unknown" # gather version information about compilers and libs gccver = capture_stdout("gcc --version | head -n 1") clangver = capture_stdout("clang --version | head -n 1") opensslver = capture_stdout("openssl version") krb5ver = capture_stdout("krb5-config --version") # build and log each target os.chdir(srcdir) for target in TARGETS: # clean first p = subprocess.Popen("make clean", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, executable='/bin/sh') p.communicate() # run the target cmd = "make %s" % target print("Running '%s'" % cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, executable='/bin/sh') (out, err) = p.communicate() # write out the build log buildlog = os.path.join(logs, target.replace(' ', '_').replace('/', '_') + ".txt") logfile = open(buildlog, 'w') logfile.write("stdout:\n") logfile.write(out.decode('UTF-8')) logfile.write("\nstderr:\n") logfile.write(err.decode('UTF-8')) logfile.close() # add to the table row = [osrel, os.uname().machine, cmd, today.strftime("%Y-%m-%d")] if os.path.isfile('wermit'): row.append("%d" % os.stat('wermit').st_size) else: row.append("N/A") if target.find('clang') != -1: row.append(clangver) else: row.append(gccver) if p.returncode == 0: row.append("OK") else: row.append("Failed") row.append("") table.append(row) # create an html table with open(os.path.join(logs, 'table.html'), 'w') as results: results.write(tabulate.tabulate(table, tablefmt='html', headers="firstrow", stralign="left")) # create a tar file of the results with tarfile.open(os.path.join(cwd, "%s.tar.gz" % logbase), 'w:gz') as archive: archive.add(logs, arcname=os.path.basename(logs)) # clean up shutil.rmtree(tmpdir, ignore_errors=True)