示例#1
0
    def update_workspace(self, environ, start_response, job_id, build_id):
        """ Store workspace archive """
        if validators.validate_job_id(job_id) == None:
            self.log.error("Job_id validation failure, '%s'", job_id)
            return response.send_error(start_response, 400, constants.ERROR_JOB_INVALID_ID)
        if validators.validate_build_id(build_id) != build_id:
            self.log.error("Build_id validation failure, '%s'", build_id)
            return response.send_error(start_response, 400, constants.ERROR_BUILD_INVALID_ID)
        if not os.path.isdir(self._build_dir(job_id, build_id)):
            return response.send_error(start_response, 404, constants.ERROR_BUILD_NOT_FOUND)

        ifh, data_len = request.get_request_data_handle_and_length(environ)

        try:
            ofh = open(self._build_workspace_file(job_id, build_id), 'wb')
        except IOError:
            return response.send_error(start_response, 500, constants.ERROR_BUILD_WRITE_FAILED)

        try:
            while data_len > 0:
                read_len = data_len
                if read_len > 1024*128:
                    read_len = 1024*128
                data = ifh.read(read_len)
                ofh.write(data)
                data_len = data_len - len(data)
        except IOError:
            ofh.close()
            return response.send_error(start_response, 500, constants.ERROR_BUILD_WRITE_FAILED)

        ofh.close()

        return response.send_response(start_response, 204)
示例#2
0
    def create_or_update_artifact(self,
                                  environ,
                                  start_response,
                                  job_id,
                                  build_id,
                                  artifact_id_param=None):
        """ Create or update an artifact """
        if artifact_id_param is not None:
            artifact_id = artifact_id_param
            if validators.validate_artifact_id(artifact_id) != artifact_id:
                return response.send_error(start_response, 400,
                                           constants.ERROR_ARTIFACT_INVALID_ID)
            if not os.path.isfile(
                    self._build_artifact_file(job_id, build_id, artifact_id)):
                return response.send_error(start_response, 404,
                                           constants.ERROR_ARTIFACT_NOT_FOUND)
        else:
            artifact_id = str(uuid.uuid4())

        if not os.path.isdir(self._build_artifact_dir(job_id, build_id)):
            try:
                os.mkdir(self._build_artifact_dir(job_id, build_id))
            except IOError:
                return response.send_error(
                    start_response, 400, constants.ERROR_ARTIFACT_WRITE_FAILED)

        ifh, data_len = request.get_request_data_handle_and_length(environ)

        try:
            ofh = open(
                self._build_artifact_file(job_id, build_id, artifact_id), 'wb')
        except IOError:
            return response.send_error(start_response, 400,
                                       constants.ERROR_ARTIFACT_WRITE_FAILED)

        try:
            while data_len > 0:
                read_len = data_len
                if read_len > 1024 * 128:
                    read_len = 1024 * 128
                data = ifh.read(read_len)
                ofh.write(data)
                data_len = data_len - len(data)
        except IOError:
            ofh.close()
            return response.send_error(start_response, 400,
                                       constants.ERROR_ARTIFACT_WRITE_FAILED)

        ofh.close()

        return response.send_response(
            start_response, 200 if artifact_id_param else 201,
            json.dumps({
                'job_id': job_id,
                'build_number': int(build_id),
                'artifact_id': artifact_id
            }))
示例#3
0
    def create_or_update_artifact(self, environ, start_response, job_id, build_id, artifact_id_param = None):
        """ Create or update an artifact """
        if artifact_id_param is not None:
            artifact_id = artifact_id_param
            if validators.validate_artifact_id(artifact_id) != artifact_id:
                return response.send_error(start_response, 400, constants.ERROR_ARTIFACT_INVALID_ID)
            if not os.path.isfile(self._build_artifact_file(job_id, build_id, artifact_id)):
                return response.send_error(start_response, 404, constants.ERROR_ARTIFACT_NOT_FOUND)
        else:
            artifact_id = str(uuid.uuid4())

        if not os.path.isdir(self._build_artifact_dir(job_id, build_id)):
            try:
                os.mkdir(self._build_artifact_dir(job_id, build_id))
            except IOError:
                return response.send_error(start_response, 400, constants.ERROR_ARTIFACT_WRITE_FAILED)

        ifh, data_len = request.get_request_data_handle_and_length(environ)

        try:
            ofh = open(self._build_artifact_file(job_id, build_id, artifact_id), 'wb')
        except IOError:
            return response.send_error(start_response, 400, constants.ERROR_ARTIFACT_WRITE_FAILED)

        try:
            while data_len > 0:
                read_len = data_len
                if read_len > 1024*128:
                    read_len = 1024*128
                data = ifh.read(read_len)
                ofh.write(data)
                data_len = data_len - len(data)
        except IOError:
            ofh.close()
            return response.send_error(start_response, 400, constants.ERROR_ARTIFACT_WRITE_FAILED)

        ofh.close()

        return response.send_response(start_response, 200 if artifact_id_param else 201, json.dumps({'job_id': job_id, 'build_number': int(build_id), 'artifact_id': artifact_id}))
示例#4
0
    def update_workspace(self, environ, start_response, job_id, build_id):
        """ Store workspace archive """
        if validators.validate_job_id(job_id) == None:
            self.log.error("Job_id validation failure, '%s'", job_id)
            return response.send_error(start_response, 400,
                                       constants.ERROR_JOB_INVALID_ID)
        if validators.validate_build_id(build_id) != build_id:
            self.log.error("Build_id validation failure, '%s'", build_id)
            return response.send_error(start_response, 400,
                                       constants.ERROR_BUILD_INVALID_ID)
        if not os.path.isdir(self._build_dir(job_id, build_id)):
            return response.send_error(start_response, 404,
                                       constants.ERROR_BUILD_NOT_FOUND)

        ifh, data_len = request.get_request_data_handle_and_length(environ)

        try:
            ofh = open(self._build_workspace_file(job_id, build_id), 'wb')
        except IOError:
            return response.send_error(start_response, 500,
                                       constants.ERROR_BUILD_WRITE_FAILED)

        try:
            while data_len > 0:
                read_len = data_len
                if read_len > 1024 * 128:
                    read_len = 1024 * 128
                data = ifh.read(read_len)
                ofh.write(data)
                data_len = data_len - len(data)
        except IOError:
            ofh.close()
            return response.send_error(start_response, 500,
                                       constants.ERROR_BUILD_WRITE_FAILED)

        ofh.close()

        return response.send_response(start_response, 204)