Example #1
0
 def output_custom_mirror_pool_file(self, selected_mirrors):
     """
     Output selected mirrors to custom mirror file
     :param selected_mirrors:
     :return:
     """
     print("\n.: {} {}".format(txt.INF_CLR, txt.CUSTOM_MIRROR_LIST))
     print("--------------------------")
     # output mirror file
     jsonFn.write_json_file(selected_mirrors, self.config["custom_file"])
     print(".: {} {}: {}".format(txt.INF_CLR, txt.CUSTOM_MIRROR_FILE_SAVED,
                                 self.config["custom_file"]))
Example #2
0
def write_custom_mirrors_json(self, selected_mirrors: list) -> None:
    """
    Output selected mirrors to custom mirror file
    :param self:
    :param selected_mirrors:
    :return:
    """
    util.msg(message=f"{txt.CUSTOM_MIRROR_LIST}",
             urgency=txt.INF_CLR,
             tty=self.tty)
    util.msg(
        message="------------------------------------------------------------",
        tty=self.tty)
    jsonFn.write_json_file(data=selected_mirrors,
                           filename=self.config["custom_file"])
    util.msg(
        message=f'{txt.CUSTOM_MIRROR_FILE_SAVED}: {self.config["custom_file"]}',
        urgency=txt.INF_CLR,
        tty=self.tty)
Example #3
0
def download_mirrors(config: object) -> tuple:
    """Retrieve mirrors from manjaro.org
    :param config:
    :returns: tuple with bool for mirrors.json and status.json
    :rtype: tuple
    """
    fetchmirrors = False
    fetchstatus = False
    try:
        # mirrors.json
        req = urllib.request.Request(url=config["url_mirrors_json"],
                                     headers=USER_AGENT)
        with urllib.request.urlopen(req) as response:
            mirrorlist = json.loads(response.read().decode("utf8"),
                                    object_pairs_hook=collections.OrderedDict)
        fetchmirrors = True
        tempfile = config["work_dir"] + "/.temp.file"
        jsonFn.json_dump_file(mirrorlist, tempfile)
        filecmp.clear_cache()
        if fileFn.check_file(conf.USR_DIR, folder=True):
            if not fileFn.check_file(config["mirror_file"]):
                jsonFn.json_dump_file(mirrorlist, config["mirror_file"])
            elif not filecmp.cmp(tempfile, config["mirror_file"]):
                jsonFn.json_dump_file(mirrorlist, config["mirror_file"])
        os.remove(tempfile)
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    try:
        # status.json
        req = urllib.request.Request(url=config["url_status_json"],
                                     headers=USER_AGENT)
        with urllib.request.urlopen(req) as response:
            statuslist = json.loads(
                response.read().decode("utf8"),
                object_pairs_hook=collections.OrderedDict)
        fetchstatus = True
        jsonFn.write_json_file(statuslist, config["status_file"])
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    # result
    return fetchmirrors, fetchstatus
Example #4
0
def download_mirrors(config):
    """Retrieve mirrors from manjaro.org
    :param config:
    :returns: tuple with bool for mirrors.json and status.json
    :rtype: tuple
    """
    fetchmirrors = False
    fetchstatus = False
    # mirrors.json
    try:
        with urlopen(config["url_mirrors_json"]) as response:
            mirrorlist = json.loads(response.read().decode("utf8"),
                                    object_pairs_hook=collections.OrderedDict)
        fetchmirrors = True
        tempfile = config["work_dir"] + "/temp.file"
        jsonFn.json_dump_file(mirrorlist, tempfile)
        filecmp.clear_cache()
        if fileFn.check_existance_of(conf.USR_DIR, folder=True):
            if not fileFn.check_existance_of(config["mirror_file"]):
                jsonFn.json_dump_file(mirrorlist, config["mirror_file"])
            elif not filecmp.cmp(tempfile, config["mirror_file"]):
                jsonFn.json_dump_file(mirrorlist, config["mirror_file"])
        os.remove(tempfile)
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    # status.json
    try:
        with urlopen(config["url_status_json"]) as response:
            statuslist = json.loads(
                response.read().decode("utf8"),
                object_pairs_hook=collections.OrderedDict)
        fetchstatus = True
        jsonFn.write_json_file(statuslist, config["status_file"])
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    # result
    return fetchmirrors, fetchstatus
Example #5
0
def convert_to_json():
    """Convert custom mirror file to json"""
    print(".: {} {}".format(txt.INF_CLR, txt.CONVERT_CUSTOM_MIRROR_FILE))
    mirrors = []
    with open(conf.O_CUST_FILE, "r") as mirrorfile:
        mirror_country = None
        for line in mirrorfile:
            country = get_country(line)
            if country:
                mirror_country = country
                continue
            mirror_url = get_url(line)
            if not mirror_url:
                continue
            mirror_protocol = get_protocol(mirror_url)
            # add to mirrors
            mirrors.append({
                "country": mirror_country,
                "protocols": [mirror_protocol],
                "url": mirror_url
            })
        # write new file
        jsonFn.write_json_file(mirrors, conf.CUSTOM_FILE)
        os.remove(conf.O_CUST_FILE)
Example #6
0
def download_mirrors(config):
    """Retrieve mirrors from manjaro.org
    :param config:
    :returns: tuple with bool for mirrors.json and status.json
    :rtype: tuple
    """
    fetchmirrors = False
    fetchstatus = False
    # mirrors.json
    try:
        with urlopen(config["url_mirrors_json"]) as response:
            mirror_data = json.loads(response.read().decode("utf8"),
                                    object_pairs_hook=collections.OrderedDict)
        fetchmirrors = True
        tempfile = config["work_dir"] + "/mirrors.temp"
        jsonFn.write_json_file(mirror_data, tempfile, True)
        filecmp.clear_cache()
        if fileFn.check_existance_of(conf.USR_DIR, folder=True):
            if not fileFn.check_existance_of(config["mirror_file"]):
                jsonFn.write_json_file(mirror_data, config["mirror_file"], True)
            elif not filecmp.cmp(tempfile, config["mirror_file"]):
                jsonFn.write_json_file(mirror_data, config["mirror_file"], True)
        os.remove(tempfile)
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    # status.json
    try:
        with urlopen(config["url_status_json"]) as response:
            statuslist = json.loads(
                response.read().decode("utf8"),
                object_pairs_hook=collections.OrderedDict)
        fetchstatus = True
        jsonFn.write_json_file(statuslist, config["status_file"])
    except (HTTPException, json.JSONDecodeError, URLError):
        pass
    result
    return fetchmirrors, fetchstatus