Example #1
0
 def handleTrackingDict(self, dictionary):
     f = open(os.path.join(self.dest, 'metadata.json'), 'w')
     metadata = simple_json.dumps(dictionary, indent='    ', sort_keys = True)
     f.write("var metadata = ")
     f.write(metadata)
     f.write(';')
     f.flush()
     f.close()
 def render_GET(self, request):
     request.setHeader("content-type", "application/json")
     return dumps({
         'time': time(),
         'control': sets['control'],
         'balbula_1': sets['balbula_1'],
         'input1': input1
     })
Example #3
0
 def json(self, errno, message, data=None):
     self.set_header("Content-Type", "application/json")
     self.write(
         json.dumps({
             'errno': errno,
             'message': message,
             'data': data
         }))
Example #4
0
def _get_boots_count(result):
    """Get the boot counts.

    :param result: The boot element for which to get the count of.
    :type result: dict
    :return: A dictionary with the counts.
    """
    queries = []

    query_str = "status=%(status)s&job=%(job)s&kernel=%(kernel)s"
    total_query_str = "job=%(job)s&kernel=%(kernel)s" % result

    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    result["status"] = "PASS"
    queries.append({
        "method": "GET",
        "operation_id": "passed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % result
    })

    result["status"] = "FAIL"
    queries.append({
        "method": "GET",
        "operation_id": "failed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % result
    })

    data, status, headers = backend.request_post(
        backend.create_url(CONFIG_GET("BATCH_API_ENDPOINT")),
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60*60
    )

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": 0,
            "other_boots": 0,
            "passed_boots": 0,
            "total_boots": 0,
        }

    return count_results
Example #5
0
def _get_boots_count(result):
    """Get the boot counts.

    :param result: The boot element for which to get the count of.
    :type result: dict
    :return: A dictionary with the counts.
    """
    queries = []

    query_str = "status=%(status)s&job=%(job)s&kernel=%(kernel)s"
    total_query_str = "job=%(job)s&kernel=%(kernel)s" % result

    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    result["status"] = "PASS"
    queries.append({
        "method": "GET",
        "operation_id": "passed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % result
    })

    result["status"] = "FAIL"
    queries.append({
        "method": "GET",
        "operation_id": "failed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % result
    })

    data, status, headers = backend.request_post(
        backend.create_url(CONFIG_GET("BATCH_API_ENDPOINT")),
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60*60
    )

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": 0,
            "other_boots": 0,
            "passed_boots": 0,
            "total_boots": 0,
        }

    return count_results
Example #6
0
def details(request):
#        [more stuff]
    if request.POST:
            # Get all the mark for this recipe
            list_mark = Mark.objects.values('mark').filter(recipe__pk=r.id)
            # loop to get the total
            total = 0
            for element in list_mark:
                    total+= element['mark']
            # round it
            total = round((float(total) /  len(list_mark)),1)
            # update the total
            r.total_mark= total
            # save the user mark
            r.save()

            # Now the intersting part for this tut
            import simple_json
            # it was a french string, if we dont't use unicode
            # the result at the output of json in Dojo is wrong.
            message = unicode( message, "utf-8" )
            #
            jsonList = simple_json.dumps((my_mark, total, form_message ,message))
            return HttpResponse(jsonList)
Example #7
0
def _get_job_counts(query_params):
    """Retrieve the builds and boots count.

    :param query_params: The result from the previous query to be used as
    parameter.
    :type query_params: dict
    :return: A dictionary with the buils and boots count.
    """
    queries = []

    query_params["job_id"] = query_params["_id"]["$oid"]
    query_str = "status=%(status)s&job=%(job)s&kernel=%(kernel)s"
    total_query_str = "job=%(job)s&kernel=%(kernel)s" % query_params

    # Get the totals.
    queries.append({
        "method": "GET",
        "operation_id": "total_builds",
        "resource": "count",
        "document": "build",
        "query": total_query_str
    })
    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    # Get the passed ones first.
    query_params["status"] = "PASS"
    queries.append({
        "method": "GET",
        "operation_id": "passed_builds",
        "resource": "count",
        "document": "build",
        "query": query_str % query_params
    })

    queries.append({
        "method": "GET",
        "operation_id": "passed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % query_params
    })

    # Then the failed ones.
    query_params["status"] = "FAIL"
    queries.append({
        "method": "GET",
        "operation_id": "failed_builds",
        "resource": "count",
        "document": "build",
        "query": query_str % query_params
    })

    queries.append({
        "method": "GET",
        "operation_id": "failed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % query_params
    })

    data, status, headers = backend.request_post(
        backend.create_url(CONFIG_GET("BATCH_API_ENDPOINT")),
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60 * 60)

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": u"N/A",
            "failed_builds": u"N/A",
            "other_boots": u"N/A",
            "other_builds": u"N/A",
            "passed_boots": u"N/A",
            "passed_builds": u"N/A",
            "total_boots": u"N/A",
            "total_builds": u"N/A"
        }

    return count_results
 def render_GET(self, request):
     request.setHeader("content-type", "application/json")
     return dumps({'time': time(), 'control': sets['control'], 'balbula_1': sets['balbula_1'], 'input1': input1})
Example #9
0
 def saveToMySQL(self):
     #TODO: save to mysql
     Log("TODO: save to mysql " + json.dumps(self.d))
Example #10
0
def _get_boot_counts(query_params):
    """Retrieve the builds and boots count.

    :param query_params: The result from the previous query to be used as
    parameter.
    :type query_params: dict
    :return: A dictionary with the buils and boots count.
    """
    queries = []

    query_str = "status=%(status)s&job=%(job)s&mach=%(mach)s"
    total_query_str = "job=%(job)s&mach=%(mach)s" % query_params

    if query_params.get("job_id", None):
        query_str += "&job_id=" + query_params["job_id"]["$oid"]
        total_query_str += "&job_id=" + query_params["job_id"]["$oid"]

    # In the aggregation result, the _id field is the one that gets aggregated.
    if all([query_params["kernel"],
            query_params["kernel"] == query_params.get("_id", None)]):
        query_str += "&kernel=" + query_params["kernel"]
        total_query_str += "&kernel=" + query_params["kernel"]

    # Get the totals.
    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    # Get the passed ones first.
    query_params["status"] = "PASS"
    queries.append(
        {
            "method": "GET",
            "operation_id": "passed_boots",
            "resource": "count",
            "document": "boot",
            "query": query_str % query_params
        }
    )

    # Then the failed ones.
    query_params["status"] = "FAIL"
    queries.append(
        {
            "method": "GET",
            "operation_id": "failed_boots",
            "resource": "count",
            "document": "boot",
            "query": query_str % query_params
        }
    )

    data, status, headers = backend.request_post(
        BACKEND_BATCH_URL,
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60*60
    )

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": 0,
            "other_boots": 0,
            "passed_boots": 0,
            "total_boots": 0
        }

    return count_results
Example #11
0
def escape(value):
    """escape value for zabbix"""
    return json.dumps(value, separators=',:')
Example #12
0
 def saveToLog(self):
     #TODO: save to log
     Log('TODO: save to log ' + json.dumps(self.d))
Example #13
0
def _get_job_counts(query_params):
    """Retrieve the builds and boots count.

    :param query_params: The result from the previous query to be used as
    parameter.
    :type query_params: dict
    :return: A dictionary with the buils and boots count.
    """
    queries = []

    query_params["job_id"] = query_params["_id"]["$oid"]
    query_str = "status=%(status)s&job=%(job)s&kernel=%(kernel)s"
    total_query_str = "job=%(job)s&kernel=%(kernel)s" % query_params

    # Get the totals.
    queries.append({
        "method": "GET",
        "operation_id": "total_builds",
        "resource": "count",
        "document": "build",
        "query": total_query_str
    })
    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    # Get the passed ones first.
    query_params["status"] = "PASS"
    queries.append(
        {
            "method": "GET",
            "operation_id": "passed_builds",
            "resource": "count",
            "document": "build",
            "query": query_str % query_params
        }
    )

    queries.append(
        {
            "method": "GET",
            "operation_id": "passed_boots",
            "resource": "count",
            "document": "boot",
            "query": query_str % query_params
        }
    )

    # Then the failed ones.
    query_params["status"] = "FAIL"
    queries.append(
        {
            "method": "GET",
            "operation_id": "failed_builds",
            "resource": "count",
            "document": "build",
            "query": query_str % query_params
        }
    )

    queries.append(
        {
            "method": "GET",
            "operation_id": "failed_boots",
            "resource": "count",
            "document": "boot",
            "query": query_str % query_params
        }
    )

    data, status, headers = backend.request_post(
        backend.create_url(CONFIG_GET("BATCH_API_ENDPOINT")),
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60*60
    )

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": u"N/A",
            "failed_builds": u"N/A",
            "other_boots": u"N/A",
            "other_builds": u"N/A",
            "passed_boots": u"N/A",
            "passed_builds": u"N/A",
            "total_boots": u"N/A",
            "total_builds": u"N/A"
        }

    return count_results
Example #14
0
def _get_boot_counts(query_params):
    """Retrieve the builds and boots count.

    :param query_params: The result from the previous query to be used as
    parameter.
    :type query_params: dict
    :return: A dictionary with the buils and boots count.
    """
    queries = []

    query_str = "status=%(status)s&job=%(job)s&mach=%(mach)s"
    total_query_str = "job=%(job)s&mach=%(mach)s" % query_params

    if query_params.get("job_id", None):
        query_str += "&job_id=" + query_params["job_id"]["$oid"]
        total_query_str += "&job_id=" + query_params["job_id"]["$oid"]

    # In the aggregation result, the _id field is the one that gets aggregated.
    if all([
            query_params["kernel"],
            query_params["kernel"] == query_params.get("_id", None)
    ]):
        query_str += "&kernel=" + query_params["kernel"]
        total_query_str += "&kernel=" + query_params["kernel"]

    # Get the totals.
    queries.append({
        "method": "GET",
        "operation_id": "total_boots",
        "resource": "count",
        "document": "boot",
        "query": total_query_str
    })

    # Get the passed ones first.
    query_params["status"] = "PASS"
    queries.append({
        "method": "GET",
        "operation_id": "passed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % query_params
    })

    # Then the failed ones.
    query_params["status"] = "FAIL"
    queries.append({
        "method": "GET",
        "operation_id": "failed_boots",
        "resource": "count",
        "document": "boot",
        "query": query_str % query_params
    })

    data, status, headers = backend.request_post(
        BACKEND_BATCH_URL,
        json.dumps({"batch": queries}),
        headers={"Content-Type": "application/json"},
        timeout=60 * 60)

    if status == 200:
        count_results = _parse_batch_results(
            backend.extract_gzip_data(data, headers))
    else:
        count_results = {
            "failed_boots": 0,
            "other_boots": 0,
            "passed_boots": 0,
            "total_boots": 0
        }

    return count_results
Example #15
0
 def saveToMySQL(self):
     #TODO: save to mysql
     Log("TODO: save to mysql " + json.dumps(self.d))
Example #16
0
 def saveToLog(self):
     #TODO: save to log
     Log('TODO: save to log ' + json.dumps(self.d))
Example #17
0
 def json(self, errno, message, data=None):
     self.set_header("Content-Type", "application/json")
     self.write(json.dumps({'errno': errno, 'message': message, 'data': data}))