コード例 #1
0
class ModelRegisterFields:
    resource_fields = dict(name=String, type=type_field_factory(ModelType),
                           destinations=List(Nested(DestinationFields.resource_fields)),
                           example=Nested(TaskStructureCreateFields.resource_fields))
コード例 #2
0
parser_put.add_argument("desc", dest="desc", type=str, help="请输入任务描述")

# ============================================== [ parser done ] ==============================================
post_fields = {
    "jobName": String(attribute="job_name"),
    "job_type": String(attribute="job_type"),
    "jobCmd": String(attribute="job_cmd"),
    "timeStyle": String(attribute="time_style"),
    "timeData": String(attribute="time_data")
}

posts_fields = {
    "status": Integer,
    "msg": String,
    "total": Integer,
    "data": List(Nested(post_fields))
}

job_fields = {
    "jobName": String(attribute="job_name"),
    "jobType": String(attribute="job_type"),
    "jobCmd": String(attribute="job_cmd"),
    "timeStyle": String(attribute="time_style"),
    "timeData": String(attribute="time_data"),
    "nextRunTime": DateTime(attribute="next_run_time", dt_format="iso8601"),
    "category": String(attribute="category"),
    "file": String(attribute="file_name", default=""),
    "comment": String(attribute="desc"),
}

jobs_fields = {
コード例 #3
0
ファイル: auth.py プロジェクト: gamdwk/seaflow

auth_field = {'access_token': String, 'refresh_token': String}

user_field = {
    "uid": Integer,
    "email": String,
    "sex": Integer,
    "introduction": String,
    "lock": Boolean,
    "pageBgc": String,
    "avatar": String,
    "username": String
}
user_register_field = {"email": String, "uid": Integer}
email_field = {'email': String}

friends = {"friends": List(Integer), "current": Integer, "pages": Integer}
UserList = {
    "users": List(Nested(user_field)),
    "current": Integer,
    "pages": Integer
}
auth_response = ResponseField(auth_field)
user_response = ResponseField(user_field)
email_response = ResponseField(email_field)
user_register_response = ResponseField(user_register_field)
friendsRes = ResponseField(friends)
userListRes = ResponseField(UserList)
randomUserRes = ResponseField({"users": List(Nested(user_field))})
コード例 #4
0
ファイル: logs.py プロジェクト: MaiXiaochai/SnailAPI
log_fields_running = {
    "jobName": String(attribute="job_name"),
    "jobCmd": String(attribute="job_cmd"),
    "startDate": DateTime(attribute="start_date", dt_format="iso8601"),
    "endDate": DateTime(attribute="end_date", dt_format="iso8601"),
    "returnCode": Integer(attribute="return_code"),
    "stdout": String,
    "stderr": String
}

logs_fields_running = {
    "status": Integer,
    "msg": String,
    "total": Integer,
    "data": List(Nested(log_fields_running))
}


class LogResource(Resource):
    def get(self, job_name):
        args = parser_logs.parse_args()
        total = args.total

        error, data, len_data = "", "", 0
        try:
            if total <= 1:
                # 查询单个job_name最新的运行日志
                data = RunningLog.query.filter(
                    RunningLog.job_name == job_name).order_by(
                        -RunningLog.id).first()
コード例 #5
0
ファイル: admin.py プロジェクト: gamdwk/seaflow
from ..fields import ResponseField
from flask_restful.fields import Integer, Raw, List, Boolean, Nested

Lock_fields = {'uid': Integer, 'lock': Boolean()}

Locks_fields = {'users': List(Nested(Lock_fields))}
LockRes = ResponseField(Locks_fields)
コード例 #6
0
class MeasurementResource(ResourceBase):

    db_table = Measurement

    measurement_file = {
        "label": String,
        "path": String(
            attribute=lambda x: "files/measurement/{}/{}".format(
                x.measurement_id, x.path
            )
        ),
    }

    fields = {
        "id": Integer,
        "label": String,
        "start_date": String,
        "end_date": String,
        "meta_data": Raw,
        "files": List(Nested(measurement_file)),
        "jobs": List(IDField),
    }

    def get(self, id_):
        """
        Receive a measurement
        ---
        summary: Find a measurement by ID
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: successful operation
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied
            404:
                description: Measurement not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def delete(self, id_):
        """
        Delete a measurement
        ---
        summary: Deletes a measurement
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: Measurement deleted and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied
            404:
                description: Measurement not found
            405:
                description: Cannot delete measurement associated with a job
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            return self.delete_resource(
                current_app.config["MEASUREMENT_FILES_FOLDER"], resource
            )
        except ResourceForbiddenActionException as e:
            return {"status": str(e)}, e.response_code

    def put(self, id_):
        """
        Update the basic information about a measurement
        ---
        summary: Updates a measurement with new data
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        requestBody:
            content:
                multipart/form-data:
                    schema:
                        properties:
                            start_date:
                              type: string
                              format: date-time
                            end_date:
                                type: string
                                format: date-time
                            label:
                                type: string
                            meta_data:
                                type: string
        responses:
            200:
                description: Measurement updated and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied or invalid input
            404:
                description: Measurement not found
        """

        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            self._update_measurement(resource)
        except ResourceInvalidInputException as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def _update_measurement(self, resource):
        start_date, end_date = self.parse_dates(
            str(resource.start_date), str(resource.end_date)
        )
        resource.start_date = start_date
        resource.end_date = end_date
        resource.label = request.form.get("label", resource.label)
        self.load_metadata(request.form.get("meta_data", "{}"), resource)
        db.session.commit()

    @staticmethod
    def parse_dates(start=None, end=None):
        try:
            start_date = date_parser(request.form.get("start_date", start))
            end_date = date_parser(request.form.get("end_date", end))
        except ValueError as e:
            raise ResourceInvalidInputException(str(e))

        if end_date < start_date:
            raise ResourceInvalidInputException("end date < start date")
        return start_date, end_date
コード例 #7
0
class JobResource(ResourceBase):

    db_table = Job

    job_inputfile = {
        "label": String,
        "value": String(attribute=lambda x: make_input_value(x)),
    }

    job_outputfile = {
        "label":
        String,
        "path":
        String(attribute=lambda x: "files/job/{}/output/{}".format(
            x.job.id, x.path)),
    }

    fields = {
        "id":
        Integer,
        "label":
        String,
        "date":
        String(attribute=lambda x: x.date.strftime("%Y-%m-%d %H:%M")),
        "status":
        String,
        "log":
        String(attribute=lambda x: "files/job/{}/{}".format(x.id, x.log)
               if x.log else ""),
        "analysis":
        IDField,
        "measurement":
        IDField,
        "input":
        List(Nested(job_inputfile)),
        "table_output":
        List(Nested(job_outputfile)),
        "figure_output":
        List(Nested(job_outputfile)),
        "reports":
        List(JobReportFile),
    }

    def get(self, id_):
        """
        Receive a job
        ---
        summary: Find a job by ID
        tags:
            - jobs
        parameters:
            -   name: id
                in: path
                description: ID of job to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: successful operation
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Job"
            400:
                description: Invalid ID supplied
            404:
                description: Job not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def delete(self, id_):
        """
        Delete a job
        ---
        summary: Deletes a job
        tags:
            - jobs
        parameters:
            -   name: id
                in: path
                description: ID of job to delete
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: Job deleted and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Job"
            400:
                description: Invalid ID supplied
            404:
                description: Job not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            return self.delete_resource(current_app.config["JOB_FILES_FOLDER"],
                                        resource)
        except ResourceForbiddenActionException as e:
            return {"status": str(e)}, e.response_code
コード例 #8
0
from . import ResponseField
from flask_restful.fields import Integer, Nested, String, Boolean, DateTime, List
from . import StaticUrl
newsfield = {
    'content': String(),
    'imgs': List(StaticUrl()),
    'time': DateTime(dt_format='iso8601'),
    'uid': Integer,
    'tid': Integer,
    'liked': Boolean,
    'likes': Integer,
    "comments": Integer,
    "avatar": StaticUrl,
    "sex": Integer,
    "username": String
}

createnewsfield = {
    'uid': Integer,
    'tid': Integer
}

newslist = {
    "news": []
}
newslike = {
    'tid': Integer,
    'uid': Integer,
    'likes': Integer,
    'liked': Boolean(default=False)
}