diff options
author | Michael Vogt <mvo@debian.org> | 2013-10-21 22:11:40 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2013-10-21 22:11:40 +0200 |
commit | c7ea1ebaef0edebfe41353f93a81ee2ada5870a8 (patch) | |
tree | af40749886aa5bb4323fd52cee04f0c780a87b91 /apt-private/private-progress.cc | |
parent | 3b1b0f2900347ef2836c7ee4cc3ee20c6cdcb621 (diff) |
add APT::Status-deb822-Fd
Diffstat (limited to 'apt-private/private-progress.cc')
-rw-r--r-- | apt-private/private-progress.cc | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/apt-private/private-progress.cc b/apt-private/private-progress.cc index daa7695e2..1d15228c2 100644 --- a/apt-private/private-progress.cc +++ b/apt-private/private-progress.cc @@ -1,8 +1,9 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/fileutl.h> -#include <apt-pkg/iprogress.h> #include <apt-pkg/strutl.h> +#include <apt-private/private-progress.h> + #include <apti18n.h> #include <termios.h> @@ -117,6 +118,89 @@ bool PackageManagerProgressFd::StatusChanged(std::string PackageName, return true; } + +PackageManagerProgressDeb822Fd::PackageManagerProgressDeb822Fd(int progress_fd) + : StepsDone(0), StepsTotal(1) +{ + OutStatusFd = progress_fd; +} + +void PackageManagerProgressDeb822Fd::WriteToStatusFd(std::string s) +{ + FileFd::Write(OutStatusFd, s.c_str(), s.size()); +} + +void PackageManagerProgressDeb822Fd::Start() +{ + // FIXME: use SetCloseExec here once it taught about throwing + // exceptions instead of doing _exit(100) on failure + fcntl(OutStatusFd,F_SETFD,FD_CLOEXEC); + + // send status information that we are about to fork dpkg + std::ostringstream status; + status << "Status: " << "progress" << std::endl + << "Percent: " << (StepsDone/float(StepsTotal)*100.0) << std::endl + << "Message: " << _("Running dpkg") << std::endl + << std::endl; + WriteToStatusFd(status.str()); +} + +void PackageManagerProgressDeb822Fd::Stop() +{ + // clear the Keep-Fd again + _config->Clear("APT::Keep-Fds", OutStatusFd); +} + +void PackageManagerProgressDeb822Fd::Error(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string ErrorMessage) +{ + std::ostringstream status; + status << "Status: " << "Error" << std::endl + << "Package:" << PackageName << std::endl + << "Percent: " << (StepsDone/float(TotalSteps)*100.0) << std::endl + << "Message: " << ErrorMessage << std::endl + << std::endl; + WriteToStatusFd(status.str()); +} + +void PackageManagerProgressDeb822Fd::ConffilePrompt(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string ConfMessage) +{ + std::ostringstream status; + status << "Status: " << "ConfFile" << std::endl + << "Package:" << PackageName << std::endl + << "Percent: " << (StepsDone/float(TotalSteps)*100.0) << std::endl + << "Message: " << ConfMessage << std::endl + << std::endl; + WriteToStatusFd(status.str()); +} + + +bool PackageManagerProgressDeb822Fd::StatusChanged(std::string PackageName, + unsigned int xStepsDone, + unsigned int xTotalSteps, + std::string message) +{ + StepsDone = xStepsDone; + StepsTotal = xTotalSteps; + + // build the status str + std::ostringstream status; + status << "Status: " << "progress" << std::endl + << "Package: " << PackageName << std::endl + << "Percent: " << (StepsDone/float(StepsTotal)*100.0) << std::endl + << "Message: " << message << std::endl + << std::endl; + WriteToStatusFd(status.str()); + + return true; +} + + void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows) { // scroll down a bit to avoid visual glitch when the screen @@ -217,5 +301,6 @@ bool PackageManagerText::StatusChanged(std::string PackageName, } + }; // namespace progress }; // namespace apt |