Ejemplo n.º 1
0
def list_apt_packages(p_repo, p_isJSON):
    cli_ver = get_cli_ver(p_repo)
    raw_list = util.read_file_string(get_apt_repo_file_name())
    repoList = []
    repoDict = {}
    for line in raw_list.splitlines():
        data = line.split()
        if len(data) != 2:
            continue
        if data[0] == "Package:":
            repoDict['component'] = data[1]
        if data[0] == "Version:":
            version = data[1]

        if data[0] == "Filename:":
            repoDict['filename'] = data[1]
            p1 = version.find(".pgdg" + cli_ver)
            if p1 > 0:
                repoDict['version'] = version[0:p1]
                repoList.append(repoDict)
            repoDict = {}

    keys = ['component', 'version']
    headers = ['Component', 'Version']

    if p_isJSON:
        print(json.dumps(repoList, sort_keys=True, indent=2))
    else:
        print(api.format_data_to_table(repoList, keys, headers))

    return (0)
Ejemplo n.º 2
0
def get_json_file(p_file, p_isJSON):
    json_file = p_file + ".txt"
    repo = util.get_value("GLOBAL", "REPO")
    repo_file = repo + "/" + json_file
    out_dir = os.getenv("MY_HOME") + os.sep + "conf" + os.sep + "cache"

    if util.http_get_file(False, json_file, repo, out_dir, False, ""):
        out_file = out_dir + os.sep + json_file
        try:
            return (json.loads(util.read_file_string(out_file)))
        except:
            pass

    util.exit_message("Cannot process json_file '" + p_file + "'", 1, p_isJSON)