Esempio n. 1
0
    def update(self) -> None:
        command = "apt-get update"
        self.logger.info(command)

        _proc = subprocess.run(command,
                               shell=True,
                               env=self._get_environment())
        shell.assert_successful_result(_proc)
Esempio n. 2
0
 def _run_apt_cache_pkgnames(self):
     command = "{apt-cache} pkgnames".format(**self._deps)
     self.logger.debug(command)
     proc = subprocess.run(command,
                           stdout=subprocess.PIPE,
                           shell=True,
                           env=self._get_environment())
     shell.assert_successful_result(proc)
     return proc
Esempio n. 3
0
 def extract_package(self, package, target):
     path = self._apt_archives_path / package.get_expected_file_name()
     command = "{dpkg-deb} -x {archive} {directory}".format(
         **self._deps, archive=path, directory=target)
     self.logger.debug(command)
     output = subprocess.run(command,
                             shell=True,
                             env=self._get_environment())
     shell.assert_successful_result(output)
Esempio n. 4
0
    def install_download_only(self, packages: [Package]):
        packages_str = " ".join([str(pkg) for pkg in packages])

        command = "{apt-get} install -y --download-only --no-install-recommends {packages}".format(
            **self._deps, packages=packages_str)
        self.logger.info(command)

        output = subprocess.run(command,
                                shell=True,
                                env=self._get_environment())
        shell.assert_successful_result(output)
Esempio n. 5
0
    def _run_apt_get_install_download_only(self, packages: [str]):
        command = (
            "{apt-get} install -y --no-install-recommends --download-only -o Debug::pkgAcquire=1 "
            "{packages}".format(**self._deps, packages=" ".join(packages)))
        self.logger.debug(command)
        command = subprocess.run(
            command,
            stderr=subprocess.PIPE,
            shell=True,
            env=self._get_environment(),
        )

        shell.assert_successful_result(command)
        return command
Esempio n. 6
0
    def _run_apt_cache_show(self, package_names: [str]):
        if not package_names:
            return None

        command = "{apt-cache} show %s" % " ".join(package_names)
        command = command.format(**self._deps)
        self.logger.debug(command)

        _proc = subprocess.run(command,
                               stdout=subprocess.PIPE,
                               shell=True,
                               env=self._get_environment())
        shell.assert_successful_result(_proc)
        return _proc
Esempio n. 7
0
    def _run_apt_get_simulate_install(self, packages: [str]):
        command = (
            "{apt-get} install -y --no-install-recommends --simulate {packages}"
            .format(**self._deps, packages=" ".join(packages)))
        self.logger.debug(command)
        command = subprocess.run(
            command,
            stdout=subprocess.PIPE,
            shell=True,
            env=self._get_environment(),
        )

        shell.assert_successful_result(command)
        return command
Esempio n. 8
0
    def _run_command(
        self,
        command,
        stdout=sys.stdout,
        assert_success=True,
        wait_for_completion=True,
        wait_for_completion_timeout=None,
        **kwargs,
    ):
        """
        Runs a command as a subprocess
        :param command: command to execute, does not need to be formatted
        :param stdout: where to pipe the standard output
        :param assert_success: should we check if the process succeeded?
        :param wait_for_completion: should we wait for completion?
        :param wait_for_completion_timeout: if yes, how much?
        :param kwargs: additional params which should be passed to format
        :return:
        """
        command = command.format(config=self._config_path,
                                 **self._deps,
                                 **kwargs)
        # log it
        self._logger.debug(command)

        # need to split the command into args
        _proc = subprocess.Popen(shlex.split(command),
                                 stdout=stdout,
                                 stdin=sys.stdin,
                                 stderr=sys.stderr)

        if wait_for_completion:
            _proc.wait(wait_for_completion_timeout)

        if assert_success:
            shell.assert_successful_result(_proc)

        # return the process instance for future use
        # if necessary
        return _proc