Exemple #1
0
    def update_build(self, state=None):
        """
        Record a build by hitting the API.

        Returns nothing
        """
        if not self.record:
            return None

        self.build['builder'] = socket.gethostname()
        self.build['state'] = state
        if self.done:
            self.build['success'] = self.successful

            # TODO drop exit_code and provide a more meaningful UX for error
            # reporting
            if self.failure and isinstance(self.failure,
                                           BuildEnvironmentException):
                self.build['exit_code'] = self.failure.status_code
            elif len(self.commands) > 0:
                self.build['exit_code'] = max([cmd.status
                                               for cmd in self.commands])

        self.build['setup'] = self.build['setup_error'] = ""
        self.build['output'] = self.build['error'] = ""

        if self.start_time:
            build_length = (datetime.datetime.utcnow() - self.start_time)
            self.build['length'] = build_length.total_seconds()

        # TODO Replace this with per-command output tracking in the db
        self.build['output'] = '\n'.join([str(cmd)
                                          for cmd in self.commands
                                          if cmd is not None])
        errors = []
        if self.failure is not None:
            errors.append(str(self.failure))
        errors.extend([str(cmd) for cmd in self.commands
                       if cmd is not None and cmd.failed])
        self.build['error'] = '\n'.join(errors)

        # Attempt to stop unicode errors on build reporting
        for key, val in self.build.items():
            if isinstance(val, basestring):
                self.build[key] = val.decode('utf-8', 'ignore')

        try:
            api_v1.build(self.build['id']).put(self.build)
        except Exception:
            log.error("Unable to post a new build", exc_info=True)
Exemple #2
0
    def get_build(build_pk):
        """
        Retrieve build object from API

        :param build_pk: Build primary key
        """
        build = {}
        if build_pk:
            build = api_v1.build(build_pk).get()
        return dict((key, val) for (key, val) in build.items() if key not in
                    ['project', 'version', 'resource_uri', 'absolute_uri'])
Exemple #3
0
    def get_build(build_pk):
        """
        Retrieve build object from API

        :param build_pk: Build primary key
        """
        build = {}
        if build_pk:
            build = api_v1.build(build_pk).get()
        return dict((key, val) for (key, val) in build.items()
                    if key not in ['project', 'version', 'resource_uri',
                                   'absolute_uri'])
Exemple #4
0
def create_build(build_pk):
    """
    Old placeholder for build creation. Now it just gets it from the database.
    """
    if build_pk:
        build = api_v1.build(build_pk).get()
        for key in ['project', 'version', 'resource_uri', 'absolute_uri']:
            if key in build:
                del build[key]
    else:
        build = {}
    return build
Exemple #5
0
def record_build(record, build, results, state, start_time=None):
    """
    Record a build by hitting the API.

    Returns nothing
    """

    if not record:
        return None

    build['builder'] = socket.gethostname()

    setup_steps = ['checkout', 'venv', 'doc_builder', 'requirements', 'install']
    output_steps = ['html']
    all_steps = setup_steps + output_steps

    build['state'] = state
    if 'html' in results:
        build['success'] = results['html'][0] == 0
    else:
        build['success'] = False

    # Set global state
    # for step in all_steps:
    #     if results.get(step, False):
    #         if results.get(step)[0] != 0:
    #             results['success'] = False

    build['exit_code'] = max([results.get(step, [0])[0] for step in all_steps])

    build['setup'] = build['setup_error'] = ""
    build['output'] = build['error'] = ""

    if start_time:
        build['length'] = (datetime.datetime.utcnow() - start_time).total_seconds()

    for step in setup_steps:
        if step in results:
            build['setup'] += "\n\n%s\n-----\n\n" % step
            try:
                build['setup'] += results.get(step)[1]
            except (IndexError, TypeError):
                pass
            build['setup_error'] += "\n\n%s\n-----\n\n" % step
            try:
                build['setup_error'] += results.get(step)[2]
            except (IndexError, TypeError):
                pass

    for step in output_steps:
        if step in results:
            build['output'] += "\n\n%s\n-----\n\n" % step
            try:
                build['output'] += results.get(step)[1]
            except (IndexError, TypeError):
                pass
            build['error'] += "\n\n%s\n-----\n\n" % step
            try:
                build['error'] += results.get(step)[2]
            except (IndexError, TypeError):
                pass

    # Attempt to stop unicode errors on build reporting
    for key, val in build.items():
        if isinstance(val, basestring):
            build[key] = val.decode('utf-8', 'ignore')

    try:
        api_v1.build(build['id']).put(build)
    except Exception:
        log.error("Unable to post a new build", exc_info=True)