Exemple #1
0
def get_programs_dependencies() -> list:
    """
    Collects all programs dependencies and returns them in a list
    :return: list of program dependencies
    """
    dependencies = []
    programs = get_global_conf().getlist("install", "programs")

    for program in programs:
        conf = get_program_conf(program)

        for section in conf.sections():
            with suppress(NoOptionError):
                dependencies += conf.getlist(section, "depend")

    for plugin in get_global_conf().getlist("plugins", "enabled_plugins"):
        conf = get_plugin_conf(*plugin.split("."))
        for section in conf.sections():
            with suppress(NoOptionError):
                dependencies += conf.getlist(section, "depend")

    return dependencies
Exemple #2
0
def main(programs, force_installation, processes, **kwargs):
    """
    the main function. runs installers
    :param programs: the programs to install
    :param force_installation: if the installation must be done if the program was already installed
    :param kwargs: additional parameters to pass to the plugins
    """

    # pylint: disable=no-member,too-few-public-methods
    class InstallerProcess(multiprocessing.Process):
        """
        An Installer for a list of programs.
        :param _programs: the list of programs to launch
        :param _report_queue: the queue where to report the return value
        :param _max_tasks: the semaphore to acquire at the end to release a new worker
        """
        def __init__(self, _programs: list,
                     _report_queue: multiprocessing.Queue,
                     _max_tasks: multiprocessing.Semaphore):
            super().__init__()
            self.programs = _programs
            self.report_queue = _report_queue
            self.max_tasks = _max_tasks

        def run(self):
            """ Installs the programs and reports the value """
            error = None
            try:
                for _installer in self.programs:
                    try:
                        if (not _installer.run()) and _installer.conf.get(
                                "executable", None):
                            hooks.create_executables(installer=_installer)
                            hooks.post_install_run(installer=_installer,
                                                   **kwargs)
                    except InstallationErrorException as exception:
                        logging.error(exception.error_message)
                        logging.error(
                            "Won't install %(program)s",
                            dict(program=_installer.conf.get("name")))
                        error = constants.INSTALL_FAIL
            except Exception as exc:  # pylint: disable=broad-except
                error = constants.INSTALL_FAIL
                logging.error(exc)
                logging.debug("".join(traceback.format_tb(exc.__traceback__)))

            finally:
                logging.verbose("Cleaning environment")
                hooks.post_install_clean(**kwargs)
                self.max_tasks.release()
                self.report_queue.put(
                    (error or 0, self.programs[0].conf.get("name")))

    installers = []
    report_queue = multiprocessing.Queue()
    max_tasks = multiprocessing.Semaphore(processes)

    for program in programs:
        max_tasks.acquire()
        lib.logger.start_new_log_section(program, "installation")
        program_conf = get_program_conf(program)

        installer = InstallerProcess([
            Installer.factory(program_conf[prog], force_installation)
            for prog in program_conf.sections()
        ], report_queue, max_tasks)
        installer.start()
        installers.append(installer)

    return_value = 0
    counter = 0
    for _ in installers:
        counter += 1
        value, program = report_queue.get(block=True)
        if value:
            return_value = value
            logging.error("%(prog)s failed to compile correctly",
                          dict(prog=program))

        show_progress(counter, len(installers))

    return return_value
Exemple #3
0
def main(programs, force_installation, processes, **kwargs):
    """
    the main function. runs installers
    :param programs: the programs to install
    :param force_installation: if the installation must be done if the program was already installed
    :param kwargs: additional parameters to pass to the plugins
    """
    # pylint: disable=no-member,too-few-public-methods
    class InstallerProcess(multiprocessing.Process):
        """
        An Installer for a list of programs.
        :param _programs: the list of programs to launch
        :param _report_queue: the queue where to report the return value
        :param _max_tasks: the semaphore to acquire at the end to release a new worker
        """

        def __init__(
            self, _programs: list, _report_queue: multiprocessing.Queue, _max_tasks: multiprocessing.Semaphore
        ):
            super().__init__()
            self.programs = _programs
            self.report_queue = _report_queue
            self.max_tasks = _max_tasks

        def run(self):
            """ Installs the programs and reports the value """
            error = None
            try:
                for _installer in self.programs:
                    try:
                        if (not _installer.run()) and _installer.conf.get("executable", None):
                            hooks.create_executables(installer=_installer)
                            hooks.post_install_run(installer=_installer, **kwargs)
                    except InstallationErrorException as exception:
                        logging.error(exception.error_message)
                        logging.error("Won't install %(program)s", dict(program=_installer.conf.get("name")))
                        error = constants.INSTALL_FAIL
            except Exception as exc:  # pylint: disable=broad-except
                error = constants.INSTALL_FAIL
                logging.error(exc)
                logging.debug("".join(traceback.format_tb(exc.__traceback__)))

            finally:
                logging.verbose("Cleaning environment")
                hooks.post_install_clean(**kwargs)
                self.max_tasks.release()
                self.report_queue.put((error or 0, self.programs[0].conf.get("name")))

    installers = []
    report_queue = multiprocessing.Queue()
    max_tasks = multiprocessing.Semaphore(processes)

    for program in programs:
        max_tasks.acquire()
        lib.logger.start_new_log_section(program, "installation")
        program_conf = get_program_conf(program)

        installer = InstallerProcess(
            [Installer.factory(program_conf[prog], force_installation) for prog in program_conf.sections()],
            report_queue,
            max_tasks,
        )
        installer.start()
        installers.append(installer)

    return_value = 0
    counter = 0
    for _ in installers:
        counter += 1
        value, program = report_queue.get(block=True)
        if value:
            return_value = value
            logging.error("%(prog)s failed to compile correctly", dict(prog=program))

        show_progress(counter, len(installers))

    return return_value