def get_new_versions(localUpdatePath, updateVersionUrl):

    """
        获取服务器上的version.txt文件,同时将该version.txt存放到local/目录下
    """

    content = http_utils.get(updateVersionUrl, None)
    if content is None:
        return []

    lines = content.decode('utf-8').split('\n')

    if lines is None or len(lines) <= 0:
        return []

    #save the new version.txt
    versionFile = os.path.join(localUpdatePath, "version.txt")
    f = open(versionFile, "w")
    f.writelines(lines)
    f.close()

    sdkList = []
    for line in lines:
        line = line.strip()

        if line is None or len(line) <= 0:
            continue

        line = line[1:]
        line = line[:-1]
        sdkList.append(line.split(','))

    return sdkList
Пример #2
0
def get_messages(release):
    review = REVIEWS[release]
    detail_url = "{}/changes/{}/detail".format(GERRIT_URL, review)
    response = http_utils.get(url=detail_url, json_view=False)
    sanitized_content = "\n".join(response.split("\n")[1:])
    detail = json.loads(sanitized_content)
    return detail['messages']
Пример #3
0
def get_auth_token(api_key, api_secret, url, auth_service=None):

    if not api_key or not api_secret:
        raise GeneralError(
            'Invalid authorization parameters: initialize api key and secret')

    headers = {
        'x-wix-auth-nonce': os.urandom(6).encode("hex"),
        'x-wix-auth-ts': '%sZ' % datetime.utcnow().isoformat()
    }

    authorization_header = auth.create_authorization_header(
        api_key,
        api_secret,
        method="GET",
        path=urlparse(url).path,
        headers=headers,
        auth_service=auth_service)
    headers['Authorization'] = authorization_header

    http_status, response, response_headers = http_utils.get(url,
                                                             headers=headers)

    if http_status != 200:
        raise GeneralError(
            'Failed to get authorization token: http_status=%d' % http_status)

    response = json.loads(response)

    if response['scheme'] != AUTH_SCHEME:
        raise GeneralError('Invalid authorization scheme')

    return response['token']
Пример #4
0
def get_new_versions(localUpdatePath, updateVersionUrl):
    """
        获取服务器上的version.txt文件,同时将该version.txt存放到local/目录下
    """

    content = http_utils.get(updateVersionUrl, None)
    if content is None:
        return []

    lines = content.decode('utf-8').split('\n')

    if lines is None or len(lines) <= 0:
        return []

    #save the new version.txt
    versionFile = os.path.join(localUpdatePath, "version.txt")
    f = open(versionFile, "w")
    f.writelines(lines)
    f.close()

    sdkList = []
    for line in lines:
        line = line.strip()

        if line is None or len(line) <= 0:
            continue

        line = line[1:]
        line = line[:-1]
        sdkList.append(line.split(','))

    return sdkList
Пример #5
0
    def _get_media_metadata_from_service(self, metadata_id):

        headers = {'Authorization': AUTH_SCHEME + ' ' + self._auth_token}

        url = '%s%s' % (Client.WIX_MEDIA_GET_FILE_INFO_URL_PREFIX, metadata_id)
        http_status, content, _ = http_utils.get(url, headers)

        if http_status != 200:
            raise GeneralError('failed to get file metadata: http_status=%d' % http_status)

        return json.loads(content)
Пример #6
0
    def _get_upload_url(self, upload_url_endpoint):

        headers = {'Authorization': AUTH_SCHEME + ' ' + self._auth_token}

        http_status, content, _ = http_utils.get(upload_url_endpoint, headers)

        if http_status != 200:
            raise UploadError('failed to get upload url: http_status=%d' % http_status)

        metadata = json.loads(content)
        return metadata['upload_url']
Пример #7
0
    def _get_media_metadata_from_service(self, metadata_id):

        headers = {"Authorization": AUTH_SCHEME + " " + self._auth_token}

        url = "%s%s" % (self._wix_media_get_file_info_url_prefix, metadata_id)
        http_status, content, _ = http_utils.get(url, headers)

        if http_status != 200:
            raise GeneralError("failed to get file metadata: http_status=%d" % http_status)

        return json.loads(content)
Пример #8
0
    def _get_upload_url(self, upload_url_endpoint):

        headers = {"Authorization": AUTH_SCHEME + " " + self._auth_token}
        print headers
        http_status, content, _ = http_utils.get(upload_url_endpoint, headers)

        if http_status != 200:
            raise UploadError("failed to get upload url: http_status=%d" % http_status)

        metadata = json.loads(content)
        return metadata["upload_url"]
Пример #9
0
    def _get_media_metadata_from_service(self, metadata_id):

        headers = {'Authorization': AUTH_SCHEME + ' ' + self._auth_token}

        url = '%s%s' % (self._wix_media_get_file_info_url_prefix, metadata_id)
        http_status, content, _ = http_utils.get(url, headers)

        if http_status != 200:
            raise GeneralError('failed to get file metadata: http_status=%d' % http_status)

        return json.loads(content)
Пример #10
0
    def _get_upload_url(self, upload_url_endpoint):

        headers = {'Authorization': AUTH_SCHEME + ' ' + self._auth_token}
        print headers
        http_status, content, _ = http_utils.get(upload_url_endpoint, headers)

        if http_status != 200:
            raise UploadError('failed to get upload url: http_status=%d' % http_status)

        metadata = json.loads(content)
        return metadata['upload_url']
Пример #11
0
def docker_api(url: str) -> Dict[str, Any]:
    """
    Run a paginated fetch from the public Docker Hub API
    """
    if TEST_DATA is not None:
        return TEST_DATA[url]
    pagination = f"?page_size={PAGE_SIZE}&page=1"
    url = DOCKER_API_BASE + url + pagination
    r, headers = get(url)
    reset = headers.get("x-ratelimit-reset")
    if reset is not None:
        reset = datetime.datetime.fromtimestamp(int(reset))
        reset = reset.isoformat()
    logging.info(
        f"Docker API Rate Limit: {headers.get('x-ratelimit-remaining')} / {headers.get('x-ratelimit-limit')} (reset at {reset})"
    )
    if "results" not in r:
        raise RuntimeError(f"Error fetching data, no results found in: {r}")
    return r
Пример #12
0
def docker_api(url: str, use_pagination: bool = False) -> Dict[str, Any]:
    """
    Run a paginated fetch from the public Docker Hub API
    """
    if TEST_DATA is not None:
        if url not in TEST_DATA:
            raise urllib.error.HTTPError(url, 404, "Not found", {}, None)
        return TEST_DATA[url]
    pagination = ""
    if use_pagination:
        pagination = f"?page_size={PAGE_SIZE}&page=1"
    url = DOCKER_API_BASE + url + pagination
    r, headers = get(url)
    reset = headers.get("x-ratelimit-reset")
    if reset is not None:
        reset = datetime.datetime.fromtimestamp(int(reset))
        reset = reset.isoformat()
    logging.info(
        f"Docker API Rate Limit: {headers.get('x-ratelimit-remaining')} / {headers.get('x-ratelimit-limit')} (reset at {reset})"
    )
    return r
Пример #13
0
def get_auth_token(api_key, api_secret, url, auth_service=None):

    if not api_key or not api_secret:
        raise GeneralError("Invalid authorization parameters: initialize api key and secret")

    headers = {"x-wix-auth-nonce": os.urandom(6).encode("hex"), "x-wix-auth-ts": "%sZ" % datetime.utcnow().isoformat()}

    authorization_header = auth.create_authorization_header(
        api_key, api_secret, method="GET", path=urlparse(url).path, headers=headers, auth_service=auth_service
    )
    headers["Authorization"] = authorization_header

    http_status, response, response_headers = http_utils.get(url, headers=headers)

    if http_status != 200:
        raise GeneralError("Failed to get authorization token: http_status=%d" % http_status)

    response = json.loads(response)

    if response["scheme"] != AUTH_SCHEME:
        raise GeneralError("Invalid authorization scheme")

    return response["token"]
def check_sdk_update():

    """
        检查版本更新,在config/local目录下,存放一个打包工具使用的配置文件local.properties
        在该配置文件中,配置渠道SDK更新的服务器地址sdk_update_url.

        每次更新将远程的version.txt存放在local目录下
        用于下一次更新时,将远程的version.txt和本地的version.txt进行比对,从而筛选出需要
        更新的渠道SDK

        根据version.txt比对的结果,下载服务器上的需要更新的渠道SDK的zip文件
        临时放在local目录下

        然后解压到渠道SDK配置目录下,同时删除zip文件

    """

    print("checking update, please wait...")

    local_config = config_utils.getLocalConfig()

    if "sdk_update_url" not in local_config:
        print("the sdk_update_url is not exists in local.properties. check update failed.")
        return

    localUpdatePath = './local'
    if not os.path.exists(localUpdatePath):
        os.makedirs(localUpdatePath)

    sdkPath = './config/sdk'
    if not os.path.exists(sdkPath):
        os.makedirs(sdkPath)

    updateUrl = local_config['sdk_update_url']
    updateVersionUrl = updateUrl + "version.txt"

    old_updates = get_old_versions(localUpdatePath)
    new_updates = get_new_versions(localUpdatePath, updateVersionUrl)

    olds = []
    for sdk in new_updates:
        for old_sdk in old_updates:
            if sdk[0] == old_sdk[0] and sdk[1] == old_sdk[1]:
                olds.append(sdk)
                break

    new_updates = [sdk for sdk in new_updates if sdk not in olds]

    updateCount = len(new_updates)

    if updateCount <= 0:
        print("There is no sdk need update.")
    else:
        input("Total %s sdk to update, Press Enter to update:" % updateCount)

    for sdk in new_updates:
        print("Now to download %s ..." % sdk[0])
        url = updateUrl + sdk[2]
        zipFile = os.path.join(localUpdatePath, sdk[2])
        content = http_utils.get(url, None)

        f = open(zipFile, 'wb')
        f.write(content)
        f.close()

        print("%s update success, now to unzip..." % sdk[0])

        currsdkPath = os.path.join(sdkPath, sdk[0])
        if os.path.exists(currsdkPath):
            shutil.rmtree(currsdkPath)

        os.makedirs(currsdkPath)

        shutil.unpack_archive(zipFile, currsdkPath)

        os.remove(zipFile)
Пример #15
0
def check_sdk_update():
    """
        检查版本更新,在config/local目录下,存放一个打包工具使用的配置文件local.properties
        在该配置文件中,配置渠道SDK更新的服务器地址sdk_update_url.

        每次更新将远程的version.txt存放在local目录下
        用于下一次更新时,将远程的version.txt和本地的version.txt进行比对,从而筛选出需要
        更新的渠道SDK

        根据version.txt比对的结果,下载服务器上的需要更新的渠道SDK的zip文件
        临时放在local目录下

        然后解压到渠道SDK配置目录下,同时删除zip文件

    """

    print("checking update, please wait...")

    local_config = config_utils.getLocalConfig()

    if "sdk_update_url" not in local_config:
        print(
            "the sdk_update_url is not exists in local.properties. check update failed."
        )
        return

    localUpdatePath = './local'
    if not os.path.exists(localUpdatePath):
        os.makedirs(localUpdatePath)

    sdkPath = './config/sdk'
    if not os.path.exists(sdkPath):
        os.makedirs(sdkPath)

    updateUrl = local_config['sdk_update_url']
    updateVersionUrl = updateUrl + "version.txt"

    old_updates = get_old_versions(localUpdatePath)
    new_updates = get_new_versions(localUpdatePath, updateVersionUrl)

    olds = []
    for sdk in new_updates:
        for old_sdk in old_updates:
            if sdk[0] == old_sdk[0] and sdk[1] == old_sdk[1]:
                olds.append(sdk)
                break

    new_updates = [sdk for sdk in new_updates if sdk not in olds]

    updateCount = len(new_updates)

    if updateCount <= 0:
        print("There is no sdk need update.")
    else:
        input("Total %s sdk to update, Press Enter to update:" % updateCount)

    for sdk in new_updates:
        print("Now to download %s ..." % sdk[0])
        url = updateUrl + sdk[2]
        zipFile = os.path.join(localUpdatePath, sdk[2])
        content = http_utils.get(url, None)

        f = open(zipFile, 'wb')
        f.write(content)
        f.close()

        print("%s update success, now to unzip..." % sdk[0])

        currsdkPath = os.path.join(sdkPath, sdk[0])
        if os.path.exists(currsdkPath):
            shutil.rmtree(currsdkPath)

        os.makedirs(currsdkPath)

        shutil.unpack_archive(zipFile, currsdkPath)

        os.remove(zipFile)