def output_dir(self):
        """Return the path to the directory where to generate the HTML report.

        :return: the full path to the output directory
        :rtype: str
        """

        return os.path.join(GNAThub.root(), self.name)
Exemple #2
0
    def workdir():
        """Return the path to sonar execution directory.

        Located within GNAThub's root directory:

            :file:`<project_object_dir>/gnathub/sonar`

        :return: the path to the working directory
        :rtype: str
        """
        return os.path.join(GNAThub.root(), SonarQube.EXEC_DIRECTORY)
Exemple #3
0
    def mainloop(self):
        """Plugin main loop."""
        LOG.info('registered %d plugins', len(self.plugins))
        backlog = []

        # Early exit if no plug-in are scheduled to be run
        if not self.plugins:
            self.info('nothing to do')
            return

        # Execute each plug-in in order
        try:
            for cls in self.plugins:
                try:
                    # Create a new instance
                    plugin, elapsed = cls(), None

                    # Execute the plug-in
                    elapsed = self.execute(plugin)
                except KeyboardInterrupt:
                    raise
                except Exception as why:
                    LOG.exception('plug-in execution failed')
                    self.error('%s: unexpected error: %s', plugin.name, why)
                finally:
                    if plugin.exec_status != GNAThub.NOT_EXECUTED:
                        # A plugin could not have been executed depending on
                        # the command line (--runners-only/--reporters-only).
                        backlog.append((plugin.name, {
                            'time':
                            elapsed or 0,
                            'success':
                            (plugin.exec_status == GNAThub.EXEC_SUCCESS)
                        }))
        except KeyboardInterrupt:
            self.info(os.linesep + 'Interrupt caught...')

        # Write results to file
        fname = os.path.join(GNAThub.root(), 'gnathub.backlog')
        try:
            with open(fname, 'w') as fd:
                fd.write(json.dumps(backlog))
        except IOError as why:
            LOG.exception('could not write result file %s', fname)
            self.error('%s: unexpected error: %s', fname, why)

        if not GNAThub.dry_run() and not GNAThub.quiet():
            # Display a summary
            for plugin, results in backlog:
                if results['success']:
                    Console.ok(plugin)
                else:
                    Console.ko(plugin)
    def mainloop(self):
        """Plugin main loop."""
        LOG.info('registered %d plugins', len(self.plugins))
        backlog = []

        # Early exit if no plug-in are scheduled to be run
        if not self.plugins:
            self.info('nothing to do')
            return

        # Execute each plug-in in order
        try:
            for cls in self.plugins:
                try:
                    # Create a new instance
                    plugin, elapsed = cls(), None

                    # Execute the plug-in
                    elapsed = self.execute(plugin)
                except KeyboardInterrupt:
                    raise
                except Exception as why:
                    LOG.exception('plug-in execution failed')
                    self.error('%s: unexpected error: %s', plugin.name, why)
                finally:
                    if plugin.exec_status != GNAThub.NOT_EXECUTED:
                        # A plugin could not have been executed depending on
                        # the command line (--runners-only/--reporters-only).
                        backlog.append((plugin.name, {
                            'time': elapsed or 0,
                            'success': (
                                plugin.exec_status == GNAThub.EXEC_SUCCESS)
                        }))
        except KeyboardInterrupt:
            self.info(os.linesep + 'Interrupt caught...')

        # Write results to file
        fname = os.path.join(GNAThub.root(), 'gnathub.backlog')
        try:
            with open(fname, 'w') as fd:
                fd.write(json.dumps(backlog))
        except IOError as why:
            LOG.exception('could not write result file %s', fname)
            self.error('%s: unexpected error: %s', fname, why)

        if not GNAThub.dry_run() and not GNAThub.quiet():
            # Display a summary
            for plugin, results in backlog:
                if results['success']:
                    Console.ok(plugin)
                else:
                    Console.ko(plugin)
            return True
    return False


def relpath(path):
    """Returns the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str

    """

    return os.path.relpath(path, BASEDIR)


assertTrue(os.path.isdir(GNAThub.root()))
assertEqual(relpath(GNAThub.root()), os.path.join('obj', 'gnathub'))

assertTrue(os.path.isdir(GNAThub.logs()))
assertEqual(relpath(GNAThub.logs()), os.path.join('obj', 'gnathub', 'logs'))

assertTrue(os.path.isfile(GNAThub.database()))
assertEqual(relpath(GNAThub.database()),
            os.path.join('obj', 'gnathub', 'gnathub.db'))

#DB content check

# Check tool exists
TOOL = 'gnatcheck'
assertTrue(contains(TOOL))
Exemple #6
0
else:
    msg = 'load script from ' + script_path + ' repository'
    Console.info(msg, prefix=MODULE)

    # Build server script full path
    server_script_path = os.path.join(script_path, SCRIPT_NAME)
    if os.path.exists(server_script_path):
        if os.path.isfile(server_script_path):
            try:
                port = DEFAULT_PORT
                if GNAThub.port():
                    port = GNAThub.port()
                msg_exec = 'execute ' + SCRIPT_NAME
                msg_exec = msg_exec + ' (PORT NUMBER: ' + str(port) + ')'
                Console.info(msg_exec, prefix=MODULE)
                html_dir = os.path.join(GNAThub.root(), 'html-report')
                os.environ["FLASK_RUN_PORT"] = str(port)
                os.environ["WEBUI_HTML_FOLDER"] = html_dir
                exec(compile(open(server_script_path).read(),
                             server_script_path, 'exec'))

            except Exception as why:
                msg_excpt = 'failed to load script: ' + server_script_path
                msg_err = msg_excpt + ' ' + str(why)
                Console.info(msg_excpt, prefix=MODULE)
                Console.error(msg_err, prefix=MODULE)

    else:
        file_msg = server_script_path + ' server script does not exist'
        Console.error(file_msg, prefix=MODULE)
        if tool.name == tool_name:
            return True
    return False

def relpath(path):
    """Returns the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str

    """

    return os.path.relpath(path, BASEDIR)


assertTrue(os.path.isdir(GNAThub.root()))
assertEqual(relpath(GNAThub.root()), os.path.join('obj', 'gnathub'))

assertTrue(os.path.isdir(GNAThub.logs()))
assertEqual(relpath(GNAThub.logs()), os.path.join('obj', 'gnathub', 'logs'))

assertTrue(os.path.isfile(GNAThub.database()))
assertEqual(
    relpath(GNAThub.database()),
    os.path.join('obj', 'gnathub', 'gnathub.db')
)

#DB content check

# Check tool exists
TOOL = 'gnatmetric'