Exemplo n.º 1
0
def getCloudInput(benchmark):

    (requirements, numberOfRuns, limitsAndNumRuns, runDefinitions, sourceFiles) = getBenchmarkDataForCloud(benchmark)
    (workingDir, toolpaths) = getToolDataForCloud(benchmark)

    # prepare cloud input, we make all paths absolute, TODO necessary?
    outputDir = benchmark.log_folder
    absOutputDir = os.path.abspath(outputDir)
    absWorkingDir = os.path.abspath(workingDir)
    absToolpaths = list(map(os.path.abspath, toolpaths))
    absSourceFiles = list(map(os.path.abspath, sourceFiles))
    absBaseDir = util.common_base_dir(absSourceFiles + absToolpaths)

    if absBaseDir == "": sys.exit("No common base dir found.")

    numOfRunDefLinesAndPriorityStr = [numberOfRuns + 1] # add 1 for the headerline
    if benchmark.config.cloudPriority:
        numOfRunDefLinesAndPriorityStr.append(benchmark.config.cloudPriority)

    # build the input for the cloud,
    # see external vcloud/README.txt for details.
    cloudInput = [
                toTabList(absToolpaths),
                toTabList([absBaseDir, absOutputDir, absWorkingDir]),
                toTabList(requirements)
            ]
    if benchmark.result_files_pattern:
        cloudInput.append(benchmark.result_files_pattern)

    cloudInput.extend([
                toTabList(numOfRunDefLinesAndPriorityStr),
                toTabList(limitsAndNumRuns)
            ])
    cloudInput.extend(runDefinitions)
    return ("\n".join(cloudInput), numberOfRuns)
Exemplo n.º 2
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        sourcefiles = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(sourcefiles) + os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(
            len(file) for file in sourcefiles) if sourcefiles else 20
        runSet.max_length_of_filename = max(
            20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1 else
                            "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      numberOfFilesStr +
                      (TERMINAL_TITLE.format(runSet.full_name)
                       if USE_COLORS and sys.stdout.isatty() else ""))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(
                run.identifier, runSet)

            # prepare XML structure for each run and runSet
            run.xml = ET.Element(
                "run", {
                    "name": run.identifier,
                    "files": "[" + ", ".join(run.sourcefiles) + "]"
                })
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                run.xml.set("properties", " ".join(sorted(run.properties)))
            run.xml.extend(self.xml_dummy_elements)

        runSet.xml = self.runs_to_xml(runSet, runSet.runs)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        xml_file_name = self.get_filename(runSet.name, "xml")
        runSet.xml_file = filewriter.FileWriter(
            xml_file_name, self._result_xml_to_string(runSet.xml))
        runSet.xml_file.lastModifiedTime = util.read_monotonic_time()
        self.all_created_files.append(xml_file_name)
        self.xml_file_names.append(xml_file_name)
Exemplo n.º 3
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        sourcefiles = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(sourcefiles) + os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(len(file) for file in sourcefiles) if sourcefiles else 20
        runSet.max_length_of_filename = max(20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1
                        else "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set"
            + (" '" + runSet.name + "'" if runSet.name else "")
            + numberOfFilesStr
            + (TERMINAL_TITLE.format(runSet.full_name) if USE_COLORS and sys.stdout.isatty() else ""))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(run.identifier, runSet)

        # prepare XML structure for each run and runSet
            run.xml = ET.Element("run",
                                 {"name": run.identifier, "files": "[" + ", ".join(run.sourcefiles) + "]"})
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                run.xml.set("properties", " ".join(sorted(run.properties)))
            run.xml.extend(self.xml_dummy_elements)

        runSet.xml = self.runs_to_xml(runSet, runSet.runs)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        xml_file_name = self.get_filename(runSet.name, "xml")
        runSet.xml_file = filewriter.FileWriter(xml_file_name,
                       self._result_xml_to_string(runSet.xml))
        runSet.xml_file.lastModifiedTime = util.read_monotonic_time()
        self.all_created_files.append(xml_file_name)
        self.xml_file_names.append(xml_file_name)
Exemplo n.º 4
0
def getCloudInput(benchmark):

    (
        requirements,
        numberOfRuns,
        limitsAndNumRuns,
        runDefinitions,
        sourceFiles,
    ) = getBenchmarkDataForCloud(benchmark)
    (workingDir, toolpaths) = getToolDataForCloud(benchmark)

    # prepare cloud input, we make all paths absolute, TODO necessary?
    outputDir = benchmark.log_folder
    absOutputDir = os.path.abspath(outputDir)
    absWorkingDir = os.path.abspath(workingDir)
    absToolpaths = list(map(os.path.abspath, toolpaths))
    absSourceFiles = list(map(os.path.abspath, sourceFiles))
    absBaseDir = util.common_base_dir(absSourceFiles + absToolpaths)

    if absBaseDir == "":
        sys.exit("No common base dir found.")

    numOfRunDefLinesAndPriorityStr = [numberOfRuns + 1
                                      ]  # add 1 for the headerline
    if benchmark.config.cloudPriority:
        numOfRunDefLinesAndPriorityStr.append(benchmark.config.cloudPriority)

    # build the input for the cloud,
    # see external vcloud/README.txt for details.
    cloudInput = [
        toTabList(absToolpaths),
        toTabList([absBaseDir, absOutputDir, absWorkingDir]),
        toTabList(requirements),
    ]
    if benchmark.result_files_patterns:
        if len(benchmark.result_files_patterns) > 1:
            sys.exit(
                "Multiple result-files patterns not supported in cloud mode.")
        cloudInput.append(benchmark.result_files_patterns[0])

    cloudInput.extend([
        toTabList(numOfRunDefLinesAndPriorityStr),
        toTabList(limitsAndNumRuns)
    ])
    cloudInput.extend(runDefinitions)
    return ("\n".join(cloudInput), numberOfRuns)
Exemplo n.º 5
0
    def output_before_run_set(self, runSet, start_time=None):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        xml_file_name = self.get_filename(runSet.name, "xml")

        identifier_names = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(identifier_names)
        if runSet.common_prefix:
            runSet.common_prefix += os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = (max(
            len(file)
            for file in identifier_names) if identifier_names else 20)
        runSet.max_length_of_filename = max(
            20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1 else
                            f"     ({numberOfFiles} files)")
        util.printOut("\nexecuting run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      numberOfFilesStr +
                      TERMINAL_TITLE.format(runSet.full_name))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(
                run.identifier, runSet)

            if run.sourcefiles:
                adjusted_identifier = util.relative_path(
                    run.identifier, xml_file_name)
            else:
                # If no source files exist the task doesn't point to any file that could be downloaded.
                # In this case, the name doesn't have to be adjusted because it's no path.
                adjusted_identifier = run.identifier

            # prepare XML structure for each run and runSet
            run.xml = ElementTree.Element("run", name=adjusted_identifier)
            if run.sourcefiles:
                adjusted_sourcefiles = (util.relative_path(s, xml_file_name)
                                        for s in run.sourcefiles)
                run.xml.set("files",
                            "[" + ", ".join(adjusted_sourcefiles) + "]")
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                all_properties = (prop.name for prop in run.properties)
                run.xml.set("properties", " ".join(sorted(all_properties)))
            if len(run.properties) == 1:
                prop = run.properties[0]
                run.xml.set("propertyFile",
                            util.relative_path(prop.filename, xml_file_name))
                expected_result = str(
                    run.expected_results.get(prop.filename, ""))
                if expected_result:
                    run.xml.set("expectedVerdict", expected_result)

        block_name = runSet.blocks[0].name if len(runSet.blocks) == 1 else None
        runSet.xml = self.runs_to_xml(runSet, runSet.runs, block_name)
        if start_time:
            runSet.xml.set("starttime", start_time.isoformat())
        elif not self.benchmark.config.start_time:
            runSet.xml.set("starttime", util.read_local_time().isoformat())

        # write (empty) results to XML
        runSet.xml_file_name = xml_file_name
        self._write_rough_result_xml_to_file(runSet.xml, runSet.xml_file_name)
        runSet.xml_file_last_modified_time = time.monotonic()
        self.all_created_files.add(runSet.xml_file_name)
        self.xml_file_names.append(runSet.xml_file_name)
Exemplo n.º 6
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        xml_file_name = self.get_filename(runSet.name, "xml")

        identifier_names = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(identifier_names)
        if runSet.common_prefix:
            runSet.common_prefix += os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(len(file) for file in identifier_names) if identifier_names else 20
        runSet.max_length_of_filename = max(20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1
                        else "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set"
            + (" '" + runSet.name + "'" if runSet.name else "")
            + numberOfFilesStr
            + TERMINAL_TITLE.format(runSet.full_name))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(run.identifier, runSet)

            if run.sourcefiles:
                adjusted_identifier = util.relative_path(run.identifier, xml_file_name)
            else:
                # If no source files exist the task doesn't point to any file that could be downloaded.
                # In this case, the name doesn't have to be adjusted because it's no path.
                adjusted_identifier = run.identifier

        # prepare XML structure for each run and runSet
            run_attributes = {'name': adjusted_identifier}
            if run.sourcefiles:
                adjusted_sourcefiles = [util.relative_path(s, xml_file_name) for s in run.sourcefiles]
                run_attributes['files'] = '[' + ', '.join(adjusted_sourcefiles) + ']'
            run.xml = ET.Element("run", run_attributes)
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                all_properties = [prop_name for prop in run.properties for prop_name in prop.names]
                run.xml.set("properties", " ".join(sorted(all_properties)))
            run.xml.extend(self.xml_dummy_elements)

        block_name = runSet.blocks[0].name if len(runSet.blocks) == 1 else None
        runSet.xml = self.runs_to_xml(runSet, runSet.runs, block_name)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        runSet.xml_file_name = xml_file_name
        self._write_rough_result_xml_to_file(runSet.xml, runSet.xml_file_name)
        runSet.xml_file_last_modified_time = util.read_monotonic_time()
        self.all_created_files.add(runSet.xml_file_name)
        self.xml_file_names.append(runSet.xml_file_name)