#!/usr/bin/env python
#
# This script is used to assemble multiple jUnit test result files together
#    for display/processing by Jenkins. This allows assembling multiple
#    autotest tests into a single result in Jenkins.
#
# Typically, these jUnit files have been produced from individual autotest
#    test cases by the results2junit.py script.
#
# Usage:
#
#    glue_testsuites [jUnit_filename]...
#

import os
import sys


# file_load
#


def file_load(file_name):
    """
    Load the indicated file into a string and return the string.
    """

    retval = None
    if os.path.exists(file_name):
        f_obj = open(file_name, 'r')
        retval = f_obj.read()
        f_obj.close()
    else:
        sys.stderr.write("  ** Warning: The requested file (%s) does not exist.\n" % file_name)

    return retval


def main(argv):

    if (len(argv) > 0):
        print("<testsuites>")
        for fname in argv[0:]:
            content = file_load(fname).split('\n')
            for line in content[1:-2]:
                print(line)
        print("</testsuites>")
    else:
        print("No files specified on the command line.")

if __name__ == '__main__':
    main(sys.argv[1:])

# vi:set ts=4 sw=4 expandtab:
