示例#1
0
 def i686_check(self, write=False):
     if platform.machine() == "i686" and "x32" not in self.config["branch"]:
         self.config["branch"] = "x32-{}".format(self.config["branch"])
         if write:
             apifn.write_config_branch(self.config["branch"],
                                       self.config["config_file"],
                                       quiet=True)
示例#2
0
def aarch64_check(self, write: bool = False) -> None:
    if platform.machine() == "aarch64":
        self.config["arm"] = True
        if "arm" not in self.config["branch"]:
            self.config["branch"] = "arm-{}".format(self.config["branch"])
            if write:
                apifn.write_config_branch(self.config["branch"],
                                          self.config["config_file"],
                                          quiet=True)
示例#3
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)
示例#4
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)
示例#5
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)