summaryrefslogtreecommitdiff
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
parent3b1b0f2900347ef2836c7ee4cc3ee20c6cdcb621 (diff)
add APT::Status-deb822-Fd
-rw-r--r--apt-private/private-install.cc11
-rw-r--r--apt-private/private-progress.cc87
-rw-r--r--apt-private/private-progress.h28
-rwxr-xr-x[-rw-r--r--]test/integration/test-apt-progress-fd-deb82264
4 files changed, 159 insertions, 31 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:
diff --git a/test/integration/test-apt-progress-fd-deb822 b/test/integration/test-apt-progress-fd-deb822
index 0a7be0cd8..9d227942d 100644..100755
--- a/test/integration/test-apt-progress-fd-deb822
+++ b/test/integration/test-apt-progress-fd-deb822
@@ -1,4 +1,4 @@
-
+#!/bin/sh
set -e
TESTDIR=$(readlink -f $(dirname $0))
@@ -15,40 +15,50 @@ setupaptarchive
# install native
exec 3> apt-progress.log
testsuccess aptget install testing=0.1 -y -o APT::Status-deb822-Fd=3
-testequal "# and compare
-testequal "percent:0
-message: Running dpkg
-package: testing2
-percent: 0
-message: Installing testing2 (i386)
+testequal "Status: progress
+Percent: 0
+Message: Running dpkg
+
+Status: progress
+Package: testing:amd64
+Percent: 0
+Message: Installing testing (amd64)
-package: testing2
-percent: 20
-message: Preparing testing2 (i386)
+Status: progress
+Package: testing:amd64
+Percent: 20
+Message: Preparing testing (amd64)
-package: testing2
-percent: 40
-message: Unpacking testing2 (i386)
+Status: progress
+Package: testing:amd64
+Percent: 40
+Message: Unpacking testing (amd64)
-package: testing2
-percent: 60
-message: Preparing to configure testing2 (i386)
+Status: progress
+Package: testing:amd64
+Percent: 60
+Message: Preparing to configure testing (amd64)
-percent: 60
-message: Running dpkg
+Status: progress
+Percent: 60
+Message: Running dpkg
-package: testing2
-percent: 60
-message: Configuring testing2 (i386)
+Status: progress
+Package: testing:amd64
+Percent: 60
+Message: Configuring testing (amd64)
-package: testing2
-percent: 80
-message: Configuring testing2 (i386)
+Status: progress
+Package: testing:amd64
+Percent: 80
+Message: Configuring testing (amd64)
-package: testing2
-percent: 100
-message: Installed testing2 (i386)" cat apt-progress.log
+Status: progress
+Package: testing:amd64
+Percent: 100
+Message: Installed testing (amd64)
+" cat apt-progress.log
rm -f apt-progress*.log