summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-10-21 22:11:40 +0200
committerMichael Vogt <mvo@debian.org>2013-10-21 22:11:40 +0200
commitc7ea1ebaef0edebfe41353f93a81ee2ada5870a8 (patch)
treeaf40749886aa5bb4323fd52cee04f0c780a87b91 /apt-private
parent3b1b0f2900347ef2836c7ee4cc3ee20c6cdcb621 (diff)
add APT::Status-deb822-Fd
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/private-install.cc11
-rw-r--r--apt-private/private-progress.cc87
-rw-r--r--apt-private/private-progress.h28
3 files changed, 122 insertions, 4 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 8d72faecc..1d2acee6c 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -23,7 +23,8 @@
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/indexfile.h>
-#include <apt-pkg/iprogress.h>
+
+#include <apt-private/private-progress.h>
#include <set>
#include <locale.h>
@@ -342,10 +343,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
// FIXME: make this a factory
// select the right progress
- int status_fd = _config->FindI("APT::Status-Fd",-1);
+ int status_fd = _config->FindI("APT::Status-Fd", -1);
+ int status_deb822_fd = _config->FindI("APT::Status-deb822-Fd", -1);
APT::Progress::PackageManager *progress = NULL;
- if (status_fd > 0)
+ if (status_deb822_fd > 0)
+ progress = new APT::Progress::PackageManagerProgressDeb822Fd(
+ status_deb822_fd);
+ else if (status_fd > 0)
progress = new APT::Progress::PackageManagerProgressFd(status_fd);
else if(_config->FindB("Dpkg::Progress-Fancy", false) == true)
progress = new APT::Progress::PackageManagerFancy();
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
diff --git a/apt-private/private-progress.h b/apt-private/private-progress.h
index 42fa89be4..9c31eac92 100644
--- a/apt-private/private-progress.h
+++ b/apt-private/private-progress.h
@@ -77,6 +77,34 @@ namespace Progress {
};
+ class PackageManagerProgressDeb822Fd : public PackageManager
+ {
+ protected:
+ int OutStatusFd;
+ int StepsDone;
+ int StepsTotal;
+ void WriteToStatusFd(std::string msg);
+
+ public:
+ PackageManagerProgressDeb822Fd(int progress_fd);
+
+ virtual void Start();
+ virtual void Stop();
+
+ virtual bool StatusChanged(std::string PackageName,
+ unsigned int StepsDone,
+ unsigned int TotalSteps,
+ std::string HumanReadableAction);
+ virtual void Error(std::string PackageName,
+ unsigned int StepsDone,
+ unsigned int TotalSteps,
+ std::string ErrorMessage);
+ virtual void ConffilePrompt(std::string PackageName,
+ unsigned int StepsDone,
+ unsigned int TotalSteps,
+ std::string ConfMessage);
+ };
+
class PackageManagerFancy : public PackageManager
{
protected: