def find_latest(pkg_name, url='/content/units/rpm/search/'):
    """
    returns the highest version and release of the specified package found
    in the specified environment

    env: the juicer environment to search
    pkg_name: the name of the package for which to search
    """
    connectors, defaults = juicer.utils.get_login_info()
    connector = connectors[defaults['start_in']]
    # this data block is... yeah. searching in pulp v2 is painful
    #
    # https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/content/retrieval.html#search-for-units
    # https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/conventions/criteria.html#search-criteria
    #
    # those are the API docs for searching
    data = {
        'criteria': {
            'filters': {'name': pkg_name},
            'sort': [['version', 'descending'], ['release', 'descending']],
            'limit': 1,
            'fields': ['name', 'description', 'version', 'release', 'arch', 'filename']
        },
        'include_repos': 'true'
    }

    # search pulp for package
    _r = connector.post(url, data)
    if not _r.status_code == Constants.PULP_POST_OK:
        juicer.utils.Log.log_debug("Expected PULP_POST_OK, got %s", _r.status_code)
        _r.raise_for_status()
    content = juicer.utils.load_json_str(_r.content)
    if len(content) < 1:
        juicer.utils.Log.log_info("%s was not found in %s.", (pkg_name, defaults['start_in']))
        return False, False
    else:
        pkg_info = content[0]
        juicer.utils.Log.log_debug("found %s version %s" % (pkg_info['version'], pkg_info['release']))

        return pkg_info['version'], pkg_info['release']
def find_latest ( pkg_name , url = '/content/units/rpm/search/' ) : connectors , defaults = juicer . utils . get_login_info ( ) connector = connectors [ defaults [ 'start_in' ] ] data = { 'criteria' : { 'filters' : { 'name' : pkg_name } , 'sort' : [ [ 'version' , 'descending' ] , [ 'release' , 'descending' ] ] , 'limit' : 1 , 'fields' : [ 'name' , 'description' , 'version' , 'release' , 'arch' , 'filename' ] } , 'include_repos' : 'true' } _r = connector . post ( url , data ) if not _r . status_code == Constants . PULP_POST_OK : juicer . utils . Log . log_debug ( "Expected PULP_POST_OK, got %s" , _r . status_code ) _r . raise_for_status ( ) content = juicer . utils . load_json_str ( _r . content ) if len ( content ) < 1 : juicer . utils . Log . log_info ( "%s was not found in %s." , ( pkg_name , defaults [ 'start_in' ] ) ) return False , False else : pkg_info = content [ 0 ] juicer . utils . Log . log_debug ( "found %s version %s" % ( pkg_info [ 'version' ] , pkg_info [ 'release' ] ) ) return pkg_info [ 'version' ] , pkg_info [ 'release' ]
returns the highest version and release of the specified package found
    in the specified environment

    env: the juicer environment to search
    pkg_name: the name of the package for which to search