Exemplo n.º 1
0
def extract_gzip_data(data, headers):
    """Extract and json-serialize gzipped data from a response.

    :param data: The data from the response.
    :param headers: The headers of the response.
    :return The data itself or a json object.
    """
    read_data = None
    if "content-encoding" in headers:
        if "gzip" in headers["content-encoding"]:
            in_buffer = io.BytesIO()
            in_buffer.write(data)
            in_buffer.seek(io.SEEK_SET)

            with gzip.GzipFile(mode="rb", fileobj=in_buffer) as g_data:
                read_data = g_data.read()

    if read_data:
        json_data = None
        json_data = json.loads(read_data, encoding="utf-8")
        read_data = data = None
    else:
        json_data = data

    return json_data
Exemplo n.º 2
0
def _get_build_results(date_range=1):
    """Retrieve build resulsts from the backend.

    By default retrieve only 1 day of data.

    :param date_range: The number of days of data to retrieve.
    :type date_range: integer
    :return The status code (integer) and the data from the backend (json).
    """
    results = []
    params = [("date_range", date_range), ("sort", "created_on"),
              ("sort_order", -1)]
    data, status, headers = backend.request_get(BUILD_URL, params=params)

    if status == 200:
        read_data = data

        if "content-encoding" in headers:
            if "gzip" in headers["content-encoding"]:
                in_buffer = io.BytesIO()
                in_buffer.write(data)
                in_buffer.seek(io.SEEK_SET)

                with gzip.GzipFile(mode="rb", fileobj=in_buffer) as g_data:
                    read_data = g_data.read()

        if read_data:
            json_data = None
            json_data = json.loads(read_data, encoding="utf_8")
            read_data = data = None

            if json_data:
                results = json_data.get("result", [])

    return status, results
 def load_online_module(self):
     """Fetch online modules"""
     repositories = self.app.get('repositories')
     data = {}
     for repo in repositories:
         path = repo['path']
         if path[-1:] == '/':
             path = repo[:-1]
         try:
             raw_json = urlopen(self.app, str(path + '/index.json'), {'cache':3600} )
             raw = json.loads(raw_json)
             modules = dict( ( module['name'] , {'version': module['version'], 'country': module['country'], 'description': module['desc'], 'path': path + '/' + module['name'] +'/'}) for module in raw['modules'] )
             data.update(modules)
         except:
             print traceback.format_exc()
     return data
Exemplo n.º 4
0
def _get_build_results(date_range=1):
    """Retrieve build resulsts from the backend.

    By default retrieve only 1 day of data.

    :param date_range: The number of days of data to retrieve.
    :type date_range: integer
    :return The status code (integer) and the data from the backend (json).
    """
    results = []
    params = [
        ("date_range", date_range),
        ("sort", "created_on"),
        ("sort_order", -1)
    ]
    data, status, headers = backend.request_get(BUILD_URL, params=params)

    if status == 200:
        read_data = data

        if "content-encoding" in headers:
            if "gzip" in headers["content-encoding"]:
                in_buffer = io.BytesIO()
                in_buffer.write(data)
                in_buffer.seek(io.SEEK_SET)

                with gzip.GzipFile(mode="rb", fileobj=in_buffer) as g_data:
                    read_data = g_data.read()

        if read_data:
            json_data = None
            json_data = json.loads(read_data, encoding="utf_8")
            read_data = data = None

            if json_data:
                results = json_data.get("result", [])

    return status, results