Example #1
0
    def __init__(self, package: str, name_in_distros: t.Dict[str, str] = None):
        """
        Creates an instance.

        :param package: name of the package
        :param name_in_distros: name in each supported linux distribution if it differs
        from the already given name
        """
        super().__init__()
        self.package = package  # type: str
        """ Name of the package """
        self.name_in_distros = name_in_distros or {}  # type: t.Dict[str, str]
        """ Name in each supported linux distribution if it differs from the package name """
        pkg = {}
        for distro in self.name_in_distros:
            if distro not in self.supported_distributions:
                logging.warning(
                    "Ignore unsupported distribution {}".format(distro))
            else:
                pkg[distro] = self.name_in_distros[distro]
        for distro in self.supported_distributions:
            if distro not in pkg:
                pkg[distro] = package
        self.name_in_distros = pkg
        self.typecheck()
        self._current_distro = get_distribution_name()
        self._current_package_name = self.name_in_distros[self._current_distro]
        self._current_install_cmd = self.install_cmds[
            self._current_distro].format(self._current_package_name)
        self._current_check_cmd = self.check_cmds[self._current_distro].format(
            self._current_package_name)
        self._current_uninstall_cmd = self.uninstall_cmds[
            self._current_distro].format(self._current_package_name)
Example #2
0
    def __init__(self, package: str, name_in_distros: t.Dict[str, str] = None):
        """
        Creates an instance.

        :param package: name of the package
        :param name_in_distros: name in each supported linux distribution if it differs
        from the already given name
        """
        super().__init__()
        self.package = package  # type: str
        """ Name of the package """
        self.name_in_distros = name_in_distros or {}  # type: t.Dict[str, str]
        """ Name in each supported linux distribution if it differs from the package name """
        pkg = {}
        for distro in self.name_in_distros:
            if distro not in self.supported_distributions:
                logging.warning("Ignore unsupported distribution {}".format(distro))
            else:
                pkg[distro] = self.name_in_distros[distro]
        for distro in self.supported_distributions:
            if distro not in pkg:
                pkg[distro] = package
        self.name_in_distros = pkg
        self.typecheck()
        self._current_distro = get_distribution_name()
        self._current_package_name = self.name_in_distros[self._current_distro]
        self._current_install_cmd = self.install_cmds[self._current_distro].format(self._current_package_name)
        self._current_check_cmd = self.check_cmds[self._current_distro].format(self._current_package_name)
        self._current_uninstall_cmd = self.uninstall_cmds[self._current_distro].format(self._current_package_name)
Example #3
0
 def _unsupported_distribution(self) -> bool:
     current_distro = get_distribution_name()
     current_release = get_distribution_release()
     for (distro, release) in self.possible_distributions:
         if distro == current_distro and release == current_release:
             return False
     return True
Example #4
0
 def _unsupported_distribution(self) -> bool:
     current_distro = get_distribution_name()
     current_release = get_distribution_release()
     for (distro, release) in self.possible_distributions:
         if distro == current_distro and release == current_release:
             return False
     return True
Example #5
0
 def _execute(self, db: Database):
     if self._unsupported_distribution():
         expected = join_strs(
             ["{} {} ".format(*l) for l in self.possible_distributions],
             "or")
         self._fail(
             "Unsupported distribution {} and release {}, expected {}".
             format(get_distribution_name(), get_distribution_release(),
                    expected))
Example #6
0
    def __init__(self, possible_distributions: t.List[str] = [get_distribution_name()]):
        """
        Creates an instance.

        :param possible_distributions: names of the allowed linux distributions
        """
        super().__init__()
        self.possible_distributions = possible_distributions  # type: t.List[str]
        """ Names of the allowed linux distributions """
        self.typecheck()
Example #7
0
    def __init__(self, possible_distributions: t.List[t.Tuple[str, str]] = [(get_distribution_name(),
                                                                             get_distribution_release())]):
        """
        Creates an instance.

        :param possible_distributions: allowed (distribution, release) tuples
        """
        super().__init__()
        self.possible_distributions = possible_distributions  # type: t.List[t.Tuple[str, str]]
        """ Allowed (distribution, release) tuples """
        self.typecheck()
Example #8
0
    def __init__(self,
                 possible_distributions: t.List[t.Tuple[str, str]] = [
                     (get_distribution_name(), get_distribution_release())
                 ]):
        """
        Creates an instance.

        :param possible_distributions: allowed (distribution, release) tuples
        """
        super().__init__()
        self.possible_distributions = possible_distributions  # type: t.List[t.Tuple[str, str]]
        """ Allowed (distribution, release) tuples """
        self.typecheck()
Example #9
0
    def __init__(self,
                 possible_distributions: t.List[str] = [
                     get_distribution_name()
                 ]):
        """
        Creates an instance.

        :param possible_distributions: names of the allowed linux distributions
        """
        super().__init__()
        self.possible_distributions = possible_distributions  # type: t.List[str]
        """ Names of the allowed linux distributions """
        self.typecheck()
Example #10
0
 def _fail_on_unsupported_distro(self):
     if get_distribution_name() not in self.name_in_distros:
         self._fail("Unsupported distribution {} for package {}".format(get_distribution_name(), self.package))
Example #11
0
 def _execute(self, db: Database):
     if self._unsupported_distribution():
         expected = join_strs(["{} {} ".format(*l) for l in self.possible_distributions], "or")
         self._fail("Unsupported distribution {} and release {}, expected {}".format(get_distribution_name(),
                                                                                     get_distribution_release(),
                                                                                     expected))
Example #12
0
 def _execute(self, db: Database):
     if self._unsupported_distribution():
         self._fail("Unsupported distribution {}, expected {}".format(get_distribution_name(),
                                                                     join_strs(self.possible_distributions, "or")))
Example #13
0
 def _unsupported_distribution(self) -> bool:
     return get_distribution_name() not in self.possible_distributions
Example #14
0
 def _execute(self, db: Database):
     if self._unsupported_distribution():
         self._fail("Unsupported distribution {}, expected {}".format(
             get_distribution_name(),
             join_strs(self.possible_distributions, "or")))
Example #15
0
 def _unsupported_distribution(self) -> bool:
     return get_distribution_name() not in self.possible_distributions
Example #16
0
 def _fail_on_unsupported_distro(self):
     if get_distribution_name() not in self.name_in_distros:
         self._fail("Unsupported distribution {} for package {}".format(
             get_distribution_name(), self.package))