当前位置: 首页>>代码示例>>Python>>正文


Python utility.jsonify函数代码示例

本文整理汇总了Python中pyfarm.master.utility.jsonify函数的典型用法代码示例。如果您正苦于以下问题:Python jsonify函数的具体用法?Python jsonify怎么用?Python jsonify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了jsonify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

    def delete(self, agent_id):
        """
        Delete a single agent

        .. http:delete:: /api/v1/agents/(uuid:agent_id) HTTP/1.1

            **Request (agent exists)**

            .. sourcecode:: http

                DELETE /api/v1/agents/b25ee7eb-9586-439a-b131-f5d022e0d403 HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 204 NO CONTENT
                Content-Type: application/json

        :statuscode 204: the agent was deleted or did not exist
        """
        agent = Agent.query.filter_by(id=agent_id).first()
        if agent is None:
            return jsonify(None), NO_CONTENT
        else:
            db.session.delete(agent)
            db.session.commit()
            assign_tasks.delay()
            return jsonify(None), NO_CONTENT
开发者ID:guidow,项目名称:pyfarm-master,代码行数:30,代码来源:agents.py

示例2: delete

    def delete(self, pathmap_id):
        """
        A ``DELETE`` to this endpoint will remove the specified pathmap

        .. http:delete:: /api/v1/pathmaps/<int:pathmap_id> HTTP/1.1

            **Request**

            .. sourcecode:: http

                DELETE /api/v1/pathmaps/1 HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 204 NO_CONTENT

        :statuscode 204: the path map was deleted or did not exist in the first
                         place
        """
        pathmap = PathMap.query.filter_by(id=pathmap_id).first()
        if not pathmap:
            return jsonify(None), NO_CONTENT

        db.session.delete(pathmap)
        db.session.commit()

        logger.info("deleted pathmap id %s", pathmap_id)

        return jsonify(None), NO_CONTENT
开发者ID:xlhtc007,项目名称:pyfarm-master,代码行数:32,代码来源:pathmaps.py

示例3: delete

    def delete(self, software_rq):
        """
        A ``DELETE`` to this endpoint will delete the requested software tag

        .. http:delete:: /api/v1/software/<str:softwarename> HTTP/1.1

            **Request**

            .. sourcecode:: http

                DELETE /api/v1/software/Autodesk%20Maya HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 204 NO_CONTENT

        :statuscode 204: the software tag was deleted or didn't exist
        """
        if isinstance(software_rq, STRING_TYPES):
            software = Software.query.filter_by(software=software_rq).first()
        else:
            software = Software.query.filter_by(id=software_rq).first()

        if not software:
            return jsonify(None), NO_CONTENT

        db.session.delete(software)
        db.session.commit()
        logger.info("Deleted software %s", software.software)

        return jsonify(None), NO_CONTENT
开发者ID:guidow,项目名称:pyfarm-master,代码行数:34,代码来源:software.py

示例4: delete

    def delete(self, jobtype_name, software):
        """
        A ``DELETE`` to this endpoint will delete the requested software
        requirement from the specified jobtype, creating a new version of the
        jobtype in the process

        .. http:delete:: /api/v1/jobtypes/[<str:name>|<int:id>]/software_requirements/<int:id> HTTP/1.1

            **Request**

            .. sourcecode:: http

                DELETE /api/v1/jobtypes/TestJobType/software_requirements/1 HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 204 NO CONTENT

        :statuscode 204:
            the software requirement was deleted or didn't exist
        """
        if isinstance(jobtype_name, STRING_TYPES):
            jobtype = JobType.query.filter_by(name=jobtype_name).first()
        else:
            jobtype = JobType.query.filter_by(id=jobtype_name).first()

        if not jobtype:
            return (jsonify(error="JobType %s not found" % jobtype_name), NOT_FOUND)

        jobtype_version = JobTypeVersion.query.filter_by(jobtype=jobtype).order_by("version desc").first()
        if not jobtype_version:
            return jsonify(error="JobType has no versions"), NOT_FOUND

        new_version = JobTypeVersion()
        for name in JobTypeVersion.types().columns:
            if name not in JobTypeVersion.types().primary_keys:
                setattr(new_version, name, getattr(jobtype_version, name))
        new_version.version += 1
        for old_req in jobtype_version.software_requirements:
            if old_req.software.software != software:
                new_req = JobTypeSoftwareRequirement()
                for name in JobTypeSoftwareRequirement.types().columns:
                    setattr(new_req, name, getattr(old_req, name))
                new_req.jobtype_version = new_version
                db.session.add(new_req)

        db.session.add(new_version)
        db.session.commit()
        logger.info(
            "Deleted software requirement %s for jobtype %s, creating " "new version %s",
            software,
            jobtype.id,
            new_version.version,
        )

        return jsonify(None), NO_CONTENT
开发者ID:xlhtc007,项目名称:pyfarm-master,代码行数:59,代码来源:jobtypes.py

示例5: post

    def post(self):
        """
        A ``POST`` to this endpoint will create a new job queue.

        .. http:post:: /api/v1/jobqueues/ HTTP/1.1

            **Request**

            .. sourcecode:: http

                POST /api/v1/jobqueues/ HTTP/1.1
                Accept: application/json

                {
                    "name": "Test Queue"
                }


            **Response**

            .. sourcecode:: http

                HTTP/1.1 201 CREATED
                Content-Type: application/json

                {
                    "weight": 10,
                    "jobs": [],
                    "minimum_agents": null,
                    "priority": 5,
                    "name": "Test Queue",
                    "maximum_agents": null,
                    "id": 1,
                    "parent": null,
                    "parent_jobqueue_id": null
                }

        :statuscode 201: a new job queue was created
        :statuscode 400: there was something wrong with the request (such as
                         invalid columns being included)
        :statuscode 409: a job queue with that name already exists
        """
        jobqueue = JobQueue.query.filter_by(name=g.json["name"]).first()
        if jobqueue:
            return (jsonify(error="Job queue %s already exists" %
                            g.json["name"]), CONFLICT)

        jobqueue = JobQueue(**g.json)
        db.session.add(jobqueue)
        db.session.flush()

        jobqueue.fullpath = jobqueue.path()
        db.session.add(jobqueue)
        db.session.commit()

        jobqueue_data = jobqueue.to_dict()
        logger.info("Created job queue %s: %r", jobqueue.name, jobqueue_data)

        return jsonify(jobqueue_data), CREATED
开发者ID:guidow,项目名称:pyfarm-master,代码行数:59,代码来源:jobqueues.py

示例6: get

    def get(self, software_rq, version_name):
        """
        A ``GET`` to this endpoint will return the specified version

        .. http:get:: /api/v1/software/<str:softwarename>/versions/<str:version> HTTP/1.1

            **Request**

            .. sourcecode:: http

                GET /api/v1/software/Autodesk%20Maya/versions/2014 HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 200 OK
                Content-Type: application/json

                {
                    "version": "2013",
                    "id": 1,
                    "rank": 100,
                    "discovery_function_name": null
                }

        :statuscode 200: no error
        :statuscode 404: the requested software tag or version was not found
        """
        if isinstance(software_rq, STRING_TYPES):
            software = Software.query.filter_by(software=software_rq).first()
        else:
            software = Software.query.filter_by(id=software_rq).first()

        if not software:
            return jsonify(error="Requested software not found"), NOT_FOUND

        if isinstance(version_name, STRING_TYPES):
            version = SoftwareVersion.query.filter(
                SoftwareVersion.software==software,
                SoftwareVersion.version==version_name).first()
        else:
            version = SoftwareVersion.query.filter_by(id=version_name).first()

        if not version:
            return jsonify(error="Requested version not found"), NOT_FOUND

        out = {
            "id": version.id,
            "version": version.version,
            "rank": version.rank,
            "discovery_function_name": version.discovery_function_name}
        return jsonify(out), OK
开发者ID:guidow,项目名称:pyfarm-master,代码行数:54,代码来源:software.py

示例7: get

    def get(self, job_id, task_id, attempt, log_identifier):
        """
        A ``GET`` to this endpoint will return metadata about the specified
        logfile

        .. http:get:: /api/v1/jobs/<job_id>/tasks/<task_id>/attempts/<attempt>/logs/<log_identifier> HTTP/1.1

            **Request**

            .. sourcecode:: http

                GET /api/v1/jobs/4/tasks/1300/attempts/5/logs/2014-09-03_10-58-59_4_4ee02475335911e4a935c86000cbf5fb.csv HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 200 OK
                Content-Type: application/json

                {
                    "id": 147,
                    "identifier": "2014-09-03_10-58-59_4_4ee02475335911e4a935c86000cbf5fb.csv",
                    "created_on": "2014-09-03T10:58:59.754880",
                    "agent_id": "836ce137-6ad4-443f-abb9-94c4465ff87c"
                }

        :statuscode 200: no error
        :statuscode 404: task or logfile not found
        """
        task = Task.query.filter_by(id=task_id, job_id=job_id).first()
        if not task:
            return jsonify(task_id=task_id, job_id=job_id,
                           error="Specified task not found"), NOT_FOUND

        log = TaskLog.query.filter_by(identifier=log_identifier).first()
        if not log:
            return jsonify(task_id=task_id, job_id=job_id,
                           error="Specified log not found"), NOT_FOUND

        association = TaskTaskLogAssociation.query.filter_by(
            task=task,
            log=log,
            attempt=attempt).first()
        if not association:
            return jsonify(task_id=task.id, log=log.identifier,
                           error="Specified log not found in task"), NOT_FOUND

        return jsonify(log.to_dict(unpack_relationships=False))
开发者ID:guidow,项目名称:pyfarm-master,代码行数:50,代码来源:tasklogs.py

示例8: get

    def get(self, tagname=None):
        """
        A ``GET`` to this endpoint will list all agents associated with this
        tag.

        .. http:get:: /api/v1/tags/<str:tagname>/agents/ HTTP/1.1

            **Request**

            .. sourcecode:: http

                GET /api/v1/tags/interesting/agents/ HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 201 CREATED
                Content-Type: application/json

                [
                    {
                        "hostname": "agent3",
                        "id": 1,
                        "href": "/api/v1/agents/1
                    }
                ]

        :statuscode 200: the list of agents associated with this tag is returned
        :statuscode 404: the tag specified does not exist
        """
        if isinstance(tagname, STRING_TYPES):
            tag = Tag.query.filter_by(tag=tagname).first()
        else:
            tag = Tag.query.filter_by(id=tagname).first()

        if tag is None:
            return jsonify(error="tag %s not found" % tagname), NOT_FOUND

        out = []
        for agent in tag.agents:
            out.append({
                "id": agent.id,
                "hostname": agent.hostname,
                "href": url_for(".single_agent_api", agent_id=agent.id)})

        return jsonify(out), OK
开发者ID:guidow,项目名称:pyfarm-master,代码行数:48,代码来源:tags.py

示例9: schema

def schema():
    """
    Returns the basic schema of :class:`.Tag`

    .. http:get:: /api/v1/tags/schema/ HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/tags/schema/ HTTP/1.1
            Accept: application/json

        **Response**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "id": "INTEGER",
                "tag": "VARCHAR(64)"
            }

    :statuscode 200: no error
    """
    return jsonify(Tag.to_schema())
开发者ID:guidow,项目名称:pyfarm-master,代码行数:28,代码来源:tags.py

示例10: schema

def schema():
    """
    Returns the basic schema of :class:`.Agent`

    .. http:get:: /api/v1/pathmaps/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/pathmaps/schema HTTP/1.1
            Accept: application/json

        **Response**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "id": "INTEGER",
                "path_linux": "VARCHAR(512)",
                "path_windows": "VARCHAR(512)",
                "path_osx": "VARCHAR(512)",
                "tag": "VARCHAR(64)"
            }

    :statuscode 200: no error
    """
    out = PathMap.to_schema()
    del out["tag_id"]
    out["tag"] = "VARCHAR(%s)" % config.get("max_tag_length")
    return jsonify(out)
开发者ID:xlhtc007,项目名称:pyfarm-master,代码行数:34,代码来源:pathmaps.py

示例11: schema

def schema():
    """
    Returns the basic schema of :class:`.JobQueue`

    .. http:get:: /api/v1/jobqueues/schema HTTP/1.1

        **Request**

        .. sourcecode:: http

            GET /api/v1/jobqueues/schema HTTP/1.1
            Accept: application/json

        **Response**

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/json

            {
                "id": "INTEGER",
                "name": VARCHAR(255)",
                "minimum_agents": "INTEGER",
                "maximum_agents": "INTEGER",
                "priority": "INTEGER",
                "weight": "INTEGER",
                "parent_jobqueue_id": "INTEGER"
            }

    :statuscode 200: no error
    """
    return jsonify(JobQueue.to_schema()), OK
开发者ID:guidow,项目名称:pyfarm-master,代码行数:33,代码来源:jobqueues.py

示例12: get

    def get(self):
        """
        A ``GET`` to this endpoint will return a list of all registered path
        maps, with id.
        It can be made with a for_agent query parameter, in which case it will
        return only those path maps that apply to that agent.

        .. http:get:: /api/v1/pathmaps/ HTTP/1.1

            **Request**

            .. sourcecode:: http

                GET /api/v1/pathmaps/ HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 200 OK
                Content-Type: application/json

                [
                    {
                        "id": 1,
                        "path_osx": "/mnt/nfs",
                        "path_windows": "\\\\domains\\cifs_server",
                        "path_linux": "/mnt/nfs"
                    },
                    {
                        "id": 7,
                        "path_osx": "/renderout",
                        "path_windows": "c:\\renderout",
                        "path_linux": "/renderout"
                        "tag": "usual",
                    }
                ]

        :statuscode 200: no error
        """
        query = PathMap.query

        for_agent = get_uuid_argument("for_agent")

        if for_agent:
            query = query.filter(or_(PathMap.tag == None, PathMap.tag.has(Tag.agents.any(Agent.id == for_agent))))

        logger.debug("Query: %s", str(query))

        output = []
        for map in query:
            map_dict = map.to_dict(unpack_relationships=False)
            if map.tag:
                map_dict["tag"] = map.tag.tag
            del map_dict["tag_id"]
            output.append(map_dict)

        return jsonify(output), OK
开发者ID:xlhtc007,项目名称:pyfarm-master,代码行数:59,代码来源:pathmaps.py

示例13: delete

    def delete(self, queue_rq):
        """
        A ``DELETE`` to this endpoint will delete the specified job queue

        .. http:delete:: /api/v1/jobqueue/[<str:name>|<int:id>]

            **Request**

            .. sourcecode:: http

                DELETE /api/v1/jobqueues/Test%20Queue HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 204 NO_CONTENT

        :statuscode 204: the job queue was deleted or didn't exist
        :statuscode 409: the job queue cannot be deleted because it still
                         contains jobs or child queues
        """
        if isinstance(queue_rq, STRING_TYPES):
            jobqueue = JobQueue.query.filter_by(name=queue_rq).first()
        else:
            jobqueue = JobQueue.query.filter_by(id=queue_rq).first()

        if not jobqueue:
            return jsonify(), NO_CONTENT

        num_sub_queues = JobQueue.query.filter_by(parent=jobqueue).count()
        if num_sub_queues > 0:
            return (jsonify(error="Cannot delete: job queue has child queues"),
                    CONFLICT)

        num_jobs = Job.query.filter_by(queue=jobqueue).count()
        if num_jobs > 0:
            return (jsonify(error="Cannot delete: job queue has jobs assigned"),
                    CONFLICT)

        db.session.delete(jobqueue)
        db.session.commit()
        logger.info("Deleted job queue %s", jobqueue.name)

        return jsonify(), NO_CONTENT
开发者ID:guidow,项目名称:pyfarm-master,代码行数:46,代码来源:jobqueues.py

示例14: get

    def get(self, queue_rq):
        """
        A ``GET`` to this endpoint will return the requested job queue

        .. http:get:: /api/v1/jobqueues/[<str:name>|<int:id>] HTTP/1.1

            **Request**

            .. sourcecode:: http

                GET /api/v1/jobqueues/Test%20Queue HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 200 OK
                Content-Type: application/json

                {
                    "id": 1,
                    "parent": [],
                    "jobs": [],
                    "weight": 10,
                    "parent_jobqueue_id": null,
                    "priority": 5,
                    "minimum_agents": null,
                    "name": "Test Queue",
                    "maximum_agents": null
                }

        :statuscode 200: no error
        :statuscode 404: the requested job queue was not found
        """
        if isinstance(queue_rq, STRING_TYPES):
            jobqueue = JobQueue.query.filter_by(name=queue_rq).first()
        else:
            jobqueue = JobQueue.query.filter_by(id=queue_rq).first()

        if not jobqueue:
            return (jsonify(error="Requested job queue %r not found" % queue_rq),
                    NOT_FOUND)

        return jsonify(jobqueue.to_dict()), OK
开发者ID:guidow,项目名称:pyfarm-master,代码行数:45,代码来源:jobqueues.py

示例15: delete

    def delete(self, tagname=None):
        """
        A ``DELETE`` to this endpoint will delete the tag under this URI,
        including all relations to tags or jobs.

        .. http:delete:: /api/v1/tags/<str:tagname> HTTP/1.1

            **Request**

            .. sourcecode:: http

                DELETE /api/v1/tags/interesting HTTP/1.1
                Accept: application/json

            **Response**

            .. sourcecode:: http

                HTTP/1.1 201 CREATED
                Content-Type: application/json

                {
                    "id": 1,
                    "tag": "interesting"
                }

        :statuscode 204: the tag was deleted or did not exist in the first place
        """
        if isinstance(tagname, STRING_TYPES):
            tag = Tag.query.filter_by(tag=tagname).first()
        else:
            tag = Tag.query.filter_by(id=tagname).first()

        if tag is None:
            return jsonify(None), NO_CONTENT

        db.session.delete(tag)
        db.session.commit()

        logger.info("deleted tag %s", tag.tag)

        return jsonify(None), NO_CONTENT
开发者ID:guidow,项目名称:pyfarm-master,代码行数:42,代码来源:tags.py


注:本文中的pyfarm.master.utility.jsonify函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。