nodebin/utils/cnpm.py
def cnpm2data(platform, nodesemver):
    """The returned data is list of dict."""
    # Get node version and bin from CNPM
    retry, errormsg = 0, ''
    while True:
        # Get response
        try:
            rv = requests.get(NODE_INDEX, timeout=EXTERNAL_SERVICE_TIMEOUT)
        except Exception as e:
            # Setup errormsg if exception
            errormsg = str(e)
        else:
            # Setup errormsg if status code is not 200
            if rv.status_code != 200:
                errormsg = 'CNPM returns {} status code'.format(rv.status_code)

        # Break if response is OK
        if not errormsg:
            break

        # Retry if response is not OK
        retry += 1
        if retry > EXTERNAL_SERVICE_MAXRETRY:
            raise Exception('CNPM service error: {}'.format(errormsg))

    # Process response
    response, data = rv.json(), []
    for package in response:
        _ = dict()
        _['number'] = _process_version(package['version'])
        _['url'] = _process_url(
            files=package['files'], version=_['number'], platform=platform
        )

        # Only output if url is valid
        if _['url']:
            data.append(_)

    # Filter by nodesemver range
    if nodesemver:
        data = _filter_by_semver(data, nodesemver)

    return data
The returned data is list of dict.
The returned data is list of dict.
The returned data is list of dict .
def cnpm2data(platform, nodesemver):
    retry, errormsg = 0, ''
    while True:
        try:
            rv = requests.get(NODE_INDEX, timeout=EXTERNAL_SERVICE_TIMEOUT)
        except Exception as e:
            errormsg = str(e)
        else:
            if rv.status_code != 200:
                errormsg = 'CNPM returns {} status code'.format(rv.status_code)
        if not errormsg:
            break
        retry += 1
        if retry > EXTERNAL_SERVICE_MAXRETRY:
            raise Exception('CNPM service error: {}'.format(errormsg))
    response, data = rv.json(), []
    for package in response:
        _ = dict()
        _['number'] = _process_version(package['version'])
        _['url'] = _process_url(
            files=package['files'], version=_['number'], platform=platform
        )
        if _['url']:
            data.append(_)
    if nodesemver:
        data = _filter_by_semver(data, nodesemver)
    return data
def cnpm2data ( platform , nodesemver ) : retry , errormsg = 0 , '' while True : try : rv = requests . get ( NODE_INDEX , timeout = EXTERNAL_SERVICE_TIMEOUT ) except Exception as e : errormsg = str ( e ) else : if rv . status_code != 200 : errormsg = 'CNPM returns {} status code' . format ( rv . status_code ) if not errormsg : break retry += 1 if retry > EXTERNAL_SERVICE_MAXRETRY : raise Exception ( 'CNPM service error: {}' . format ( errormsg ) ) response , data = rv . json ( ) , [ ] for package in response : _ = dict ( ) _ [ 'number' ] = _process_version ( package [ 'version' ] ) _ [ 'url' ] = _process_url ( files = package [ 'files' ] , version = _ [ 'number' ] , platform = platform ) if _ [ 'url' ] : data . append ( _ ) if nodesemver : data = _filter_by_semver ( data , nodesemver ) return data
The returned data is list of dict.
The returned data is list of dict .
"""The returned data is list of dict.""" # Get node version and bin from CNPM # Get response # Setup errormsg if exception # Setup errormsg if status code is not 200 # Break if response is OK # Retry if response is not OK # Process response # Only output if url is valid # Filter by nodesemver range
platform
nodesemver