]> git.saurik.com Git - apt.git/commitdiff
add APT::Status-deb822-Fd
authorMichael Vogt <mvo@debian.org>
Mon, 21 Oct 2013 20:11:40 +0000 (22:11 +0200)
committerMichael Vogt <mvo@debian.org>
Mon, 21 Oct 2013 20:11:40 +0000 (22:11 +0200)
apt-private/private-install.cc
apt-private/private-progress.cc
apt-private/private-progress.h
test/integration/test-apt-progress-fd-deb822 [changed mode: 0644->0755]

index 8d72faecc1689600d5df83cfe362a3060b158cf1..1d2acee6ca886d41d9663b1e20664ee5baf6bc4a 100644 (file)
@@ -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();
index daa7695e27bcd7d8cb13fdde5ce5bacce74a5623..1d15228c2c80bc10b7d2accd153a506d72c3523a 100644 (file)
@@ -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
index 42fa89be48251336b4800b4b729a335ad57e145a..9c31eac928ebf0c7ad0f0e70dcdcf571a582a0a7 100644 (file)
@@ -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:
old mode 100644 (file)
new mode 100755 (executable)
index 0a7be0c..9d22794
@@ -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