Michael Vogt лет назад: 12
Родитель
Сommit
c7ea1ebaef

+ 8 - 3
apt-private/private-install.cc

@@ -23,7 +23,8 @@
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/indexfile.h>
-#include <apt-pkg/iprogress.h>
+
+#include <apt-private/private-progress.h>
 
 
 #include <set>
 #include <set>
 #include <locale.h>
 #include <locale.h>
@@ -342,10 +343,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       
       
       // FIXME: make this a factory
       // FIXME: make this a factory
       // select the right progress
       // 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;
       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);
          progress = new APT::Progress::PackageManagerProgressFd(status_fd);
       else if(_config->FindB("Dpkg::Progress-Fancy", false) == true)
       else if(_config->FindB("Dpkg::Progress-Fancy", false) == true)
          progress = new APT::Progress::PackageManagerFancy();
          progress = new APT::Progress::PackageManagerFancy();

+ 86 - 1
apt-private/private-progress.cc

@@ -1,8 +1,9 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/iprogress.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/strutl.h>
 
 
+#include <apt-private/private-progress.h>
+
 #include <apti18n.h>
 #include <apti18n.h>
 
 
 #include <termios.h>
 #include <termios.h>
@@ -117,6 +118,89 @@ bool PackageManagerProgressFd::StatusChanged(std::string PackageName,
    return true;
    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)
 void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
 {
 {
      // scroll down a bit to avoid visual glitch when the screen
      // scroll down a bit to avoid visual glitch when the screen
@@ -217,5 +301,6 @@ bool PackageManagerText::StatusChanged(std::string PackageName,
 }
 }
 
 
 
 
+
 }; // namespace progress
 }; // namespace progress
 }; // namespace apt
 }; // namespace apt

+ 28 - 0
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
  class PackageManagerFancy : public PackageManager
  {
  {
  protected:
  protected:

+ 37 - 27
test/integration/test-apt-progress-fd-deb822

@@ -1,4 +1,4 @@
-
+#!/bin/sh
 set -e
 set -e
 
 
 TESTDIR=$(readlink -f $(dirname $0))
 TESTDIR=$(readlink -f $(dirname $0))
@@ -15,40 +15,50 @@ setupaptarchive
 # install native
 # install native
 exec 3> apt-progress.log
 exec 3> apt-progress.log
 testsuccess aptget install testing=0.1 -y -o APT::Status-deb822-Fd=3
 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
 rm -f apt-progress*.log