Example #1
0
 def test_full_run_rank(self, mock_build_config, mock_os_getuid):
     """TEST: pacman-mirrors -c all"""
     mock_os_getuid.return_value = 0
     mock_build_config.return_value = test_conf
     with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "all"]):
         app = PacmanMirrors()
         app.config = configFn.setup_config()
         fileFn.create_dir(test_conf["work_dir"])
         cliFn.parse_command_line(app, True)
         httpFn.update_mirror_pool(app.config)
         defaultFn.load_default_mirror_pool(app)
         common.build_mirror_list(app)
Example #2
0
 def test_full_run_rank(self, mock_build_config, mock_os_getuid):
     """TEST: pacman-mirrors -c all"""
     mock_os_getuid.return_value = 0
     mock_build_config.return_value = test_conf
     with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "all"]):
         app = PacmanMirrors()
         app.config = configFn.build_config()
         fileFn.create_dir(test_conf["work_dir"])
         app.command_line_parse()
         httpFn.update_mirrors(app.config)
         app.load_all_mirrors()
         app.build_common_mirror_list()
 def run(self):
     """
     Run
     # Setup config: retunrs the config dictionary and true/false on custom
     # Parse commandline
     # i686 check - change branch to x32-$branch
     # sanitize config
     # Check network
     # Update mirror pool
     # Check if mirrorlist is not to be touched - normal exit
     # Handle missing network
     # Load default mirror pool
     # Build mirror list
     """
     (self.config, self.custom) = config_setup.setup_config()
     fileFn.create_dir(self.config["work_dir"])
     cliFn.parse_command_line(self, gtk_available=GTK_AVAILABLE)
     util.i686_check(self, write=True)
     util.aarch64_check(self, write=True)
     if not config_setup.sanitize_config(config=self.config):
         sys.exit(2)
     self.network = httpFn.check_internet_connection(tty=self.tty)
     if self.network:
         httpFn.download_mirror_pool(config=self.config, tty=self.tty, quiet=self.quiet)
     if self.no_mirrorlist:
         sys.exit(0)
     if not self.network:
         if not self.quiet:
             pacman_mirrors.functions.util.internet_message(tty=self.tty)
         self.config["method"] = "random"
         self.fasttrack = False
     """
     # Load configured mirror pool
     """
     defaultFn.load_config_mirror_pool(self)
     """
     # Decide which type of mirrorlist to create
     * Fasttrack
     * Interactive
     * Default
     """
     if self.use_async:
         util.async_disclaimer()
         resp = input()
         if resp.lower() == "n":
             exit(0)
     if self.fasttrack:
         fasttrack.build_mirror_list(self, limit=self.fasttrack)
     elif self.interactive:
         interactive.build_mirror_list(self)
     else:
         common.build_mirror_list(self)
 def test_full_run_rank(self,
                        mock_build_config,
                        mock_os_getuid):
     """TEST: pacman-mirrors -c all"""
     mock_os_getuid.return_value = 0
     mock_build_config.return_value = test_conf
     with unittest.mock.patch("sys.argv",
                              ["pacman-mirrors",
                               "-c", "all"]):
         app = PacmanMirrors()
         app.config = configFn.setup_config()
         fileFn.create_dir(test_conf["work_dir"])
         cliFn.parse_command_line(app, True)
         httpFn.update_mirror_pool(app.config)
         defaultFn.load_default_mirror_pool(app)
         common.build_mirror_list(app)
Example #5
0
 def run(self):
     """
     Run
     # Setup config: retunrs the config dictionary and true/false on custom
     # Parse commandline
     # i686 check - change branch to x32-$branch
     # sanitize config
     # Check network
     # Update mirror pool
     # Check if mirrorlist is not to be touched - normal exit
     # Handle missing network
     # Load default mirror pool
     # Build mirror list
     """
     (self.config, self.custom) = configFn.setup_config()
     fileFn.create_dir(self.config["work_dir"])
     cliFn.parse_command_line(self, GTK_AVAILABLE)
     util.i686_check(self, write=True)
     if not configFn.sanitize_config(self.config):
         sys.exit(2)
     self.network = httpFn.inet_conn_check()
     if self.network:
         httpFn.update_mirror_pool(self.config, quiet=self.quiet)
     if self.no_mirrorlist:
         sys.exit(0)
     if not self.network:
         if not self.quiet:
             pacman_mirrors.functions.util.internet_message()
         self.config["method"] = "random"
         self.fasttrack = False
     """
     # Load configured mirror pool
     """
     defaultFn.load_config_mirror_pool(self)
     """
     # Decide which type of mirrorlist to create
     * Fasttrack
     * Interactive
     * Default
     """
     if self.fasttrack:
         fasttrack.build_mirror_list(self, self.fasttrack)
     elif self.interactive:
         interactive.build_mirror_list(self)
     else:
         common.build_mirror_list(self)
Example #6
0
 def run(self):
     """
     Run
     # Setup config: retunrs the config dictionary and true/false on custom
     # Parse commandline
     # i686 check - change branch to x32-$branch
     # sanitize config
     # Check network
     # Update mirror pool
     # Check if mirrorlist is not to be touched - normal exit
     # Handle missing network
     # Load default mirror pool
     # Build mirror list
     """
     (self.config, self.custom) = configFn.setup_config()
     fileFn.create_dir(self.config["work_dir"])
     cliFn.parse_command_line(self, GTK_AVAILABLE)
     util.i686_check(self, write=True)
     if not configFn.sanitize_config(self.config):
         sys.exit(2)
     self.network = httpFn.inet_conn_check()
     if self.network:
         httpFn.update_mirror_pool(self.config, quiet=self.quiet)
     if self.no_mirrorlist:
         sys.exit(0)
     if not self.network:
         if not self.quiet:
             pacman_mirrors.functions.util.internet_message()
         self.config["method"] = "random"
         self.fasttrack = False
     """
     # Load configured mirror pool
     """
     defaultFn.load_config_mirror_pool(self)
     """
     # Decide which type of mirrorlist to create
     * Fasttrack
     * Interactive
     * Default
     """
     if self.fasttrack:
         fasttrack.build_mirror_list(self, self.fasttrack)
     elif self.interactive:
         interactive.build_mirror_list(self)
     else:
         common.build_mirror_list(self)
Example #7
0
 def run(self):
     """
     Run
     # Build internal config dictionary
     # Returns the config dictionary and true/false on custom
     # Parse commandline
     # i686 check - change branch to x32-$branch
     # Check network
     # Check if mirrorlist is not to be touched - normal exit
     # Handle missing network
     """
     (self.config, self.custom) = configFn.build_config()
     fileFn.create_dir(self.config["work_dir"])
     self.command_line_parse()
     self.i686_check(write=True)
     self.network = httpFn.inet_conn_check()
     if self.network:
         httpFn.update_mirrors(self.config, quiet=self.quiet)
     if self.no_mirrorlist:
         sys.exit(0)
     if not self.network:
         if not self.quiet:
             pacman_mirrors.functions.util.internet_message()
         self.config["method"] = "random"
         self.fasttrack = False
     """
     # Load all mirrors
     """
     self.load_all_mirrors()
     """
     # Decide which type of mirrorlist to create
     * Fasttrack
     * Interactive
     * Default
     """
     if self.fasttrack:
         self.build_fasttrack_mirror_list(self.fasttrack)
     elif self.interactive:
         self.build_interactive_mirror_list()
     else:
         self.build_common_mirror_list()
Example #8
0
    def api_config(self,
                   set_pfx=None,
                   set_branch=None,
                   re_branch=False,
                   get_branch=False,
                   set_protocols=False,
                   set_url=None):
        """
        Api configuration function
        :param set_pfx: prefix to the config paths
        :param set_branch: replace branch in pacman-mirrors.conf
        :param re_branch: replace branch in mirrorlist
        :param get_branch: sys.exit with branch
        :param set_protocols: replace protocols in pacman-mirrors.conf
        :param set_url: replace mirror url in mirrorlist
        """
        if set_url is None:
            set_url = ""

        if set_pfx is None:
            set_pfx = ""
        """
        # Order of API tasks does matter
        # First API task
        """
        if get_branch:
            print(self.config["branch"])
            return
        """
        # apply api configuration to internal configuration object
        # Apply prefix if present
        """
        if set_pfx:
            set_pfx = apifn.sanitize_prefix(set_pfx)
            self.config["config_file"] = set_pfx + self.config["config_file"]
            self.config["custom_file"] = set_pfx + self.config["custom_file"]
            self.config["mirror_file"] = set_pfx + self.config["mirror_file"]
            self.config["mirror_list"] = set_pfx + self.config["mirror_list"]
            self.config["status_file"] = set_pfx + self.config["status_file"]
            self.config["work_dir"] = set_pfx + self.config["work_dir"]
        """
        # Second API task: Set branch
        """
        if set_branch:
            # Apply branch to internal config
            self.config["branch"] = set_branch
            self.i686_check(write=False)
            """
            # pacman-mirrors.conf could absent so check for it
            """
            if not fileFn.check_existance_of(self.config["config_file"]):
                """
                # Copy from host system
                """
                fileFn.create_dir(set_pfx + "/etc")
                shutil.copyfile("/etc/pacman-mirrors.conf",
                                self.config["config_file"])
                """
                # Normalize config
                """
                apifn.normalize_config(self.config["config_file"])
            """
            # Write branch to config
            """
            apifn.write_config_branch(self.config["branch"],
                                      self.config["config_file"],
                                      quiet=self.quiet)
        """
        # Third API task: Create a mirror list
        """
        if set_url:
            """
            # mirror list dir could absent so check for it
            """
            fileFn.create_dir(set_pfx + "/etc/pacman.d")
            mirror = [{
                "url": apifn.sanitize_url(set_url),
                "country": "BUILDMIRROR",
                "protocols": [set_url[:set_url.find(":")]],
                "resp_time": "00.00"
            }]
            fileFn.write_mirror_list(self.config, mirror, quiet=self.quiet)
            # exit gracefully
            sys.exit(0)
        """
        # Fourth API task: Write protocols to config
        """
        if set_protocols:
            apifn.write_protocols(self.config["protocols"],
                                  self.config["config_file"],
                                  quiet=self.quiet)
        """
        # Fifth API task: Rebranch the mirrorlist
        """
        if re_branch:
            if not set_branch:
                print(".: {} {}".format(txt.ERR_CLR, txt.API_ERROR_BRANCH))
                sys.exit(1)
            apifn.write_mirrorlist_branch(self.config["branch"],
                                          self.config["config_file"],
                                          quiet=self.quiet)
Example #9
0
def set_config(self, set_pfx=None, set_branch=None, re_branch=False, set_protocols=False, set_url=None):
    """
    Api configuration function
    :param self:
    :param set_pfx: prefix to the config paths
    :param set_branch: replace branch in pacman-mirrors.conf
    :param re_branch: replace branch in mirror list
    :param set_protocols: replace protocols in pacman-mirrors.conf
    :param set_url: replace mirror url in mirror list
    """
    if set_url is None:
        set_url = ""

    if set_pfx is None:
        set_pfx = ""

    """
    # apply api configuration to internal configuration object
    # Apply prefix if present
    """
    if set_pfx:
        set_pfx = apifn.sanitize_prefix(set_pfx)
        self.config["config_file"] = set_pfx + self.config["config_file"]
        self.config["custom_file"] = set_pfx + self.config["custom_file"]
        self.config["mirror_file"] = set_pfx + self.config["mirror_file"]
        self.config["mirror_list"] = set_pfx + self.config["mirror_list"]
        self.config["status_file"] = set_pfx + self.config["status_file"]
        self.config["work_dir"] = set_pfx + self.config["work_dir"]

    """
    # First API task: Set branch
    """
    if set_branch:
        # Apply branch to internal config
        self.config["branch"] = set_branch
        util.i686_check(self, write=False)
        """
        # pacman-mirrors.conf could absent so check for it
        """
        if not fileFn.check_existance_of(self.config["config_file"]):
            """
            # Copy from host system
            """
            fileFn.create_dir(set_pfx + "/etc")
            shutil.copyfile("/etc/pacman-mirrors.conf",
                            self.config["config_file"])
            """
            # Normalize config
            """
            apifn.normalize_config(self.config["config_file"])
        """
        # Write branch to config
        """
        apifn.write_config_branch(self.config["branch"],
                                  self.config["config_file"],
                                  quiet=self.quiet)
    """
    # Second API task: Create a mirror list
    """
    if set_url:
        """
        # mirror list dir could absent so check for it
        """
        fileFn.create_dir(set_pfx + "/etc/pacman.d")
        mirror = [
            {
                "url": apifn.sanitize_url(set_url),
                "country": "BUILDMIRROR",
                "protocols": [set_url[:set_url.find(":")]],
                "resp_time": "00.00"
            }
        ]
        fileFn.write_mirror_list(self.config, mirror, quiet=self.quiet)
        # exit gracefully
        sys.exit(0)
    """
    # Third API task: Write protocols to config
    """
    if set_protocols:
        apifn.write_protocols(self.config["protocols"],
                              self.config["config_file"],
                              quiet=self.quiet)
    """
    # Fourth API task: Rebranch the mirrorl ist
    """
    if re_branch:
        if not set_branch:
            print(".: {} {}".format(txt.ERR_CLR, txt.API_ERROR_BRANCH))
            sys.exit(1)
        apifn.write_mirrorlist_branch(self.config["branch"],
                                      self.config["config_file"],
                                      quiet=self.quiet)
Example #10
0
def set_config(self, set_pfx: str = None, set_branch: str = None,
               re_branch: bool = False, set_protocols: bool = False, set_url: str = None) -> None:
    """
    Api configuration function
    :param self:
    :param set_pfx: prefix to the config paths
    :param set_branch: replace branch in pacman-mirrors.conf
    :param re_branch: replace branch in mirror list
    :param set_protocols: replace protocols in pacman-mirrors.conf
    :param set_url: replace mirror url in mirror list
    """
    if set_url is None:
        set_url = ""

    if set_pfx is None:
        set_pfx = ""

    """
    # apply api configuration to internal configuration object
    # Apply prefix if present
    """
    if set_pfx:
        set_pfx = apifn.sanitize_prefix(set_pfx)
        self.config["config_file"] = set_pfx + self.config["config_file"]
        self.config["custom_file"] = set_pfx + self.config["custom_file"]
        self.config["mirror_file"] = set_pfx + self.config["mirror_file"]
        self.config["mirror_list"] = set_pfx + self.config["mirror_list"]
        self.config["status_file"] = set_pfx + self.config["status_file"]
        self.config["work_dir"] = set_pfx + self.config["work_dir"]

    """
    # First API task: Set branch
    """
    if set_branch:
        # Apply branch to internal config
        self.config["branch"] = set_branch
        util.i686_check(self=self, write=False)
        """
        # pacman-mirrors.conf could absent so check for it
        """
        if not fileFn.check_file(filename=self.config["config_file"]):
            """
            # Copy from host system
            """
            fileFn.create_dir(set_pfx + "/etc")
            shutil.copyfile("/etc/pacman-mirrors.conf",
                            self.config["config_file"])
            """
            # Normalize config
            """
            apifn.normalize_config(filename=self.config["config_file"])
        """
        # Write branch to config
        """
        apifn.write_config_branch(
            branch=self.config["branch"], filename=self.config["config_file"], tty=self.tty, quiet=self.quiet)
    """
    # Second API task: Create a mirror list
    """
    if set_url:
        """
        # mirror list dir could absent so check for it
        """
        fileFn.create_dir(foldername=set_pfx + "/etc/pacman.d")
        mirror = [
            {
                "url": apifn.sanitize_url(set_url),
                "country": "BUILDMIRROR",
                "protocols": [set_url[:set_url.find(":")]],
                "resp_time": "00.00"
            }
        ]
        fileFn.write_mirror_list(
            config=self.config, servers=mirror, tty=self.tty, quiet=self.quiet)
        # exit gracefully
        sys.exit(0)
    """
    # Third API task: Write protocols to config
    """
    if set_protocols:
        apifn.write_protocols(
            protocols=self.config["protocols"], filename=self.config["config_file"], tty=self.tty, quiet=self.quiet)
    """
    # Fourth API task: Rebranch the mirrorl ist
    """
    if re_branch:
        if not set_branch:
            util.msg(message=f"{txt.API_ERROR_BRANCH}", urgency=txt.ERR_CLR, tty=self.tty)
            # print(".: {} {}".format(txt.ERR_CLR, txt.API_ERROR_BRANCH))
            sys.exit(1)
        apifn.write_mirrorlist_branch(
            newbranch=self.config["branch"], filename=self.config["config_file"], tty=self.tty, quiet=self.quiet)