Esempio n. 1
0
def check_installation(sdk, tools_list, printer, prompt):
    '''Check that everything required has been installed'''
    success = True

    # Print the environment variables for debug purposes
    printer.string("{}environment is:".format(prompt))
    text = subprocess.check_output([
        "set",
    ], shell=True)
    for line in text.splitlines():
        printer.string("{}{}".format(prompt, line.decode()))

    # Check for the tools on the path
    printer.string("{}checking tools...".format(prompt))
    for item in tools_list:
        if not item["type"] or (item["type"].lower() == sdk.lower()):
            if u_utils.exe_where(item["which_string"], item["hint"], printer,
                                 prompt):
                if item["version_switch"]:
                    u_utils.exe_version(item["which_string"],
                                        item["version_switch"], printer,
                                        prompt)
            else:
                success = False

    return success
Esempio n. 2
0
def check_installation(tools_list, printer, prompt):
    '''Check that everything required has been installed'''
    success = True

    # Check for the tools on the path
    printer.string("{}checking tools...".format(prompt))
    for item in tools_list:
        if u_utils.exe_where(item["which_string"], item["hint"], printer,
                             prompt):
            if item["version_switch"]:
                u_utils.exe_version(item["which_string"],
                                    item["version_switch"], printer, prompt)
        else:
            success = False

    return success
Esempio n. 3
0
def check_installation(tools_list, compiler_dirs_list, printer, prompt):
    '''Check that everything required has been installed'''
    success = True

    # Check for the tools on the path
    printer.string("{}checking tools...".format(prompt))
    for item in tools_list:
        if not u_utils.exe_where(item["which_string"], item["hint"],
                                 printer, prompt):
            success = False

    # Check for existence of the given directories
    printer.string("{}checking directories...".format(prompt))
    for item in compiler_dirs_list:
        if not os.path.exists(item):
            printer.string("{}compiler include directory \"{}\""
                           " does not exist.".format(prompt, item))
            success = False

    return success
Esempio n. 4
0
def run(instance, ubxlib_dir, working_dir, printer, reporter):
    '''Run Doxygen'''
    return_value = 1
    got_doxygen = False
    instance_text = u_utils.get_instance_text(instance)

    prompt = PROMPT + instance_text + ": "

    # Print out what we've been told to do
    text = "running Doxygen from ubxlib directory \"" + ubxlib_dir + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_CHECK,
                   u_report.EVENT_START,
                   "Doxygen")

    got_doxygen = u_utils.exe_where("doxygen", \
                                    "ERROR: can't find Doxygen, please make"     \
                                    " sure that it is installed and on the path.", \
                                    printer, prompt)

    if got_doxygen:
        # Sort out any subst
        printer.string("{}Doxygen finds no files if run from a" \
                       " subst drive so convert {} to a real"      \
                       " path".format(prompt, ubxlib_dir))
        actual_ubxlib_dir = u_utils.get_actual_path(ubxlib_dir)
        printer.string("{}Actual ubxlib directory is {}".      \
                       format(prompt, actual_ubxlib_dir))
        # Run Doxygen
        config_path = actual_ubxlib_dir + os.sep + DOXYFILE
        printer.string("{}CD to {}...".format(prompt, actual_ubxlib_dir))
        with u_utils.ChangeDir(actual_ubxlib_dir):
            printer.string("{}in directory {} calling doxygen {}.".    \
                           format(prompt, os.getcwd(), config_path))
            try:
                my_env = os.environ.copy()
                my_env['UBX_WORKDIR'] = working_dir
                text = subprocess.check_output(["doxygen", config_path],
                                               stderr=subprocess.STDOUT,
                                               env=my_env,
                                               shell=True) # Jenkins hangs without this
                reporter.event(u_report.EVENT_TYPE_CHECK,
                               u_report.EVENT_PASSED)
                for line in text.splitlines():
                    printer.string("{}{}".format(prompt, line.decode()))
                return_value = 0
            except subprocess.CalledProcessError as error:
                reporter.event(u_report.EVENT_TYPE_CHECK,
                               u_report.EVENT_FAILED)
                printer.string("{}Doxygen returned error {}:".
                               format(prompt, error.returncode))
                for line in error.output.splitlines():
                    line = line.strip().decode()
                    if line:
                        reporter.event_extra_information(line)
                        printer.string("{}{}".format(prompt, line))
    else:
        reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                       u_report.EVENT_FAILED,
                       "there is a problem with the Doxygen installation")

    return return_value
Esempio n. 5
0
def run(instance, ubxlib_dir, working_dir, printer, reporter):
    '''Run Pylint'''
    return_value = 1
    got_pylint = False
    min_rating = 10
    instance_text = u_utils.get_instance_text(instance)

    prompt = PROMPT + instance_text + ": "

    # Print out what we've been told to do
    text = "running Pylint from ubxlib directory \"" + ubxlib_dir + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    text += ", checking for minimum rating " + str(MIN_RATING)
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_CHECK,
                   u_report.EVENT_START,
                   "Pylint")
    got_pylint = u_utils.exe_where("pylint", \
                        "ERROR: can't find pylint, please make"     \
                        " sure that it is installed and on the path.", \
                        printer, prompt)


    if got_pylint:
        # Run Pylint on all the .py files in PYTHON_PATHS
        return_value = 0
        for py_path in PYTHON_PATHS:
            abs_py_path = ubxlib_dir + os.sep + py_path
            if os.path.exists(abs_py_path):
                printer.string("{}CD to {}...".format(prompt, abs_py_path))
                with u_utils.ChangeDir(abs_py_path):
                    for py_file in os.listdir(abs_py_path):
                        if py_file.endswith(".py"):
                            printer.string("{}running Pylint on {}...".format(prompt, py_file))
                            got_rating = False
                            try:
                                # ignore u_settings module as it sets members programatically and
                                # will thus generate a bunch of lint warnings
                                text = subprocess.check_output(["pylint", "--exit-zero",
                                                                "--ignored-modules=u_settings",
                                                                py_file],
                                                               stderr=subprocess.STDOUT,
                                                               shell=True) # Stop Jenkins hanging
                                rating = 0
                                for line in text.splitlines():
                                    line = line.decode()
                                    printer.string("{}{}".format(prompt, line))
                                    # See if there is a rating in this line
                                    outcome = line.rpartition("Your code has been rated at ")
                                    if len(outcome) == 3:
                                        outcome = outcome[2].split("/")
                                        # Get the bit before the "/" in the "x/y" rating
                                        try:
                                            rating = float(outcome[0])
                                            got_rating = True
                                            if rating < min_rating:
                                                min_rating = rating
                                            if rating < MIN_RATING:
                                                return_value += 1
                                        except ValueError:
                                            # Can't have been a rating line
                                            pass
                                if got_rating:
                                    if rating < MIN_RATING:
                                        reporter.event(u_report.EVENT_TYPE_CHECK,
                                                       u_report.EVENT_ERROR,
                                                       "rating {} < minimum ({})".  \
                                                       format(rating, MIN_RATING))
                                        for line in text.splitlines():
                                            line = line.strip().decode()
                                            if line:
                                                reporter.event_extra_information(line)
                                else:
                                    reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                                   u_report.EVENT_FAILED,
                                                   "Pylint returned no rating for file \"{}\"". \
                                                   format(py_file))
                                    printer.string("{}Pylint returned no rating.". \
                                                   format(prompt))
                                    # No rating returned, flag an error
                                    return_value += 1
                            except subprocess.CalledProcessError as error:
                                reporter.event(u_report.EVENT_TYPE_CHECK,
                                               u_report.EVENT_FAILED)
                                printer.string("{}Pylint returned error {}:".
                                               format(prompt, error.returncode))
                                for line in error.output.splitlines():
                                    line = line.strip().decode()
                                    if line:
                                        reporter.event_extra_information(line)
                                        printer.string("{}{}".format(prompt, line))
            else:
                # Flag an error if a path doesn't exist
                reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                               u_report.EVENT_FAILED,
                               "path {} does not exit".format(abs_py_path))
                printer.string("{}path \"{}\" does not exist.".   \
                               format(prompt, abs_py_path))
                return_value += 1

        printer.string("{}Pylint check complete, minimum rating {}.".
                       format(prompt, min_rating))
        if min_rating < MIN_RATING:
            reporter.event(u_report.EVENT_TYPE_CHECK,
                           u_report.EVENT_FAILED)
        else:
            reporter.event(u_report.EVENT_TYPE_CHECK,
                           u_report.EVENT_PASSED)

    else:
        reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                       u_report.EVENT_FAILED,
                       "there is a problem with the Pylint installation")

    return return_value
Esempio n. 6
0
def run(instance, ubxlib_dir, working_dir, printer, reporter):
    '''Run AStyle'''
    return_value = 1
    got_astyle = False
    call_list = []
    instance_text = u_utils.get_instance_text(instance)

    prompt = PROMPT + instance_text + ": "

    # Print out what we've been told to do
    text = "running AStyle from ubxlib directory \"" + ubxlib_dir +  \
           "\" using configuration file \"" + ubxlib_dir + os.sep +  \
           CONFIG_FILE + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_CHECK, u_report.EVENT_START, "AStyle")
    got_astyle = u_utils.exe_where("astyle", \
                        "ERROR: can't find AStyle, please make"      \
                        " sure that it is installed and on the path.", \
                        printer, prompt)
    if got_astyle:
        # Run AStyle
        printer.string("{}CD to {}...".format(prompt, ubxlib_dir))
        with u_utils.ChangeDir(ubxlib_dir):
            # Assemble the call list
            call_list.append("astyle")
            call_list.append("--options=" + CONFIG_FILE)  # Options file
            call_list.append("--dry-run")  # Don't make changes
            call_list.append("--formatted")  # Only list changed files
            call_list.append(
                "--suffix=none")  # Don't leave .orig files everywhere
            call_list.append("--verbose")  # Print out stats
            for exclude_dir in EXCLUDE_DIRS:  # Exclude these directories
                call_list.append("--exclude=" + exclude_dir)
            call_list.append(
                "--ignore-exclude-errors-x")  # Ignore unfound excludes
            call_list.append("--recursive")  # Recurse through...
            for include_dir in ASTYLE_DIRS:  # ...these files
                call_list.append(include_dir + os.sep + ASTYLE_FILE_EXTENSIONS)

            # Print what we're gonna do
            tmp = ""
            for item in call_list:
                tmp += " " + item
            printer.string("{}in directory {} calling{}".         \
                           format(prompt, os.getcwd(), tmp))
            try:
                text = subprocess.check_output(
                    call_list, stderr=subprocess.STDOUT,
                    shell=True)  # Jenkins hangs without this
                formatted = []
                for line in text.splitlines():
                    line = line.decode(encoding="utf-8", errors="ignore")
                    printer.string("{}{}".format(prompt, line))
                    # AStyle doesn't return anything other than 0,
                    # need to look for the word "Formatted" to find
                    # a file it has fiddled with
                    if line.startswith("Formatted"):
                        formatted.append(line)
                if not formatted:
                    reporter.event(u_report.EVENT_TYPE_CHECK,
                                   u_report.EVENT_PASSED)
                else:
                    reporter.event(u_report.EVENT_TYPE_CHECK,
                                   u_report.EVENT_WARNING)
                    for line in formatted:
                        reporter.event_extra_information(line)
                # We don't return any errors about formatting
                return_value = 0
            except subprocess.CalledProcessError as error:
                reporter.event(u_report.EVENT_TYPE_CHECK,
                               u_report.EVENT_FAILED)
                printer.string("{}AStyle returned error {}:".format(
                    prompt, error.returncode))
                for line in error.output.splitlines():
                    line = line.strip()
                    if line:
                        reporter.event_extra_information(line)
                        printer.string("{}{}".format(prompt, line))
    else:
        reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                       u_report.EVENT_FAILED,
                       "there is a problem with the AStyle installation")

    return return_value