[haiku-commits] haiku: hrev48937 - src/bin/pkgman

  • From: waddlesplash@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 27 Mar 2015 21:20:30 +0100 (CET)

hrev48937 adds 3 changesets to branch 'master'
old head: 9f543f804419a785c804eadf40fade0a4a3093a5
new head: c771066bd2216500496b5e5ca360e06db74bf819
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=c771066bd221+%5E9f543f804419

----------------------------------------------------------------------------

e22040efac37: pkgman: make progressbar work properly when the width is < 70.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

8667d6c75862: pkgman: replace install/uninstall pairs with upgrade text.
  
  Signed-off-by: Augustin Cavalier <waddlesplash@xxxxxxxxx>
  I fixed some bugs and removed some code duplication.

                         [ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ]

c771066bd221: pkgman: cleanup output.
  
  This makes the progressbars disappear after the download is complete,
  as well as reducing the number of lines for most actions to 1 instead
  of 3-4.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 55 insertions(+), 11 deletions(-)
src/bin/pkgman/PackageManager.cpp | 66 +++++++++++++++++++++++++++++------

############################################################################

Commit:      e22040efac37667c67da13b304ec3c80d1db497e
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e22040efac37
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Mar 27 17:26:48 2015 UTC

pkgman: make progressbar work properly when the width is < 70.

----------------------------------------------------------------------------

diff --git a/src/bin/pkgman/PackageManager.cpp 
b/src/bin/pkgman/PackageManager.cpp
index 1d6ef42..c351ba7 100644
--- a/src/bin/pkgman/PackageManager.cpp
+++ b/src/bin/pkgman/PackageManager.cpp
@@ -10,6 +10,9 @@
 
 #include "PackageManager.h"
 
+#include <sys/ioctl.h>
+#include <unistd.h>
+
 #include <package/CommitTransactionResult.h>
 #include <package/DownloadFileRequest.h>
 #include <package/RefreshRepositoryRequest.h>
@@ -189,7 +192,10 @@ PackageManager::ProgressPackageDownloadActive(const char* 
packageName,
                "\xE2\x96\x88",
        };
 
-       const int width = 70;
+       struct winsize w;
+       ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
+       const int width = (w.ws_col > 77)
+               ? 70 : (w.ws_col - 7); // we need 70 chars for the bar + 7 for 
%.
 
        int position;
        int ipart = (int)(completionPercentage * width);

############################################################################

Commit:      8667d6c75862803e19ccc88b36abd2b4e87fe38f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8667d6c75862
Author:      Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>
Date:        Thu Feb  5 06:24:22 2015 UTC
Committer:   Augustin Cavalier <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Mar 27 20:16:11 2015 UTC

pkgman: replace install/uninstall pairs with upgrade text.

Signed-off-by: Augustin Cavalier <waddlesplash@xxxxxxxxx>
I fixed some bugs and removed some code duplication.

----------------------------------------------------------------------------

diff --git a/src/bin/pkgman/PackageManager.cpp 
b/src/bin/pkgman/PackageManager.cpp
index c351ba7..17ec895 100644
--- a/src/bin/pkgman/PackageManager.cpp
+++ b/src/bin/pkgman/PackageManager.cpp
@@ -295,20 +295,45 @@ PackageManager::_PrintResult(InstalledRepository& 
installationRepository)
        PackageList& packagesToDeactivate
                = installationRepository.PackagesToDeactivate();
 
+       BStringList upgradedPackages;
+       for (int32 i = 0;
+               BSolverPackage* installPackage = packagesToActivate.ItemAt(i);
+               i++) {
+               for (int32 j = 0;
+                       BSolverPackage* uninstallPackage = 
packagesToDeactivate.ItemAt(j);
+                       j++) {
+                       if (installPackage->Info().Name() == 
uninstallPackage->Info().Name()) {
+                               
upgradedPackages.Add(installPackage->Info().Name());
+                               break;
+                       }
+               }
+       }
+
        for (int32 i = 0; BSolverPackage* package = 
packagesToActivate.ItemAt(i);
                i++) {
-               if (dynamic_cast<MiscLocalRepository*>(package->Repository()) 
== NULL) {
-                       printf("    install package %s from repository %s\n",
-                               package->Info().FileName().String(),
-                               package->Repository()->Name().String());
+               BString repository;
+               if (dynamic_cast<MiscLocalRepository*>(package->Repository()) 
!= NULL)
+                       repository = "local file";
+               else
+                       repository.SetToFormat("repository %s", 
package->Repository()->Name().String());
+
+               if (upgradedPackages.HasString(package->Info().Name())) {
+                       printf("    upgrade package %s to %s from %s\n",
+                               package->Info().Name().String(),
+                               package->Info().Version().ToString().String(),
+                               repository.String());
                } else {
-                       printf("    install package %s from local file\n",
-                               package->Info().FileName().String());
+                       printf("    install package %s-%s from %s\n",
+                               package->Info().Name().String(),
+                               package->Info().Version().ToString().String(),
+                               repository.String());
                }
        }
 
        for (int32 i = 0; BSolverPackage* package = 
packagesToDeactivate.ItemAt(i);
                i++) {
+               if (upgradedPackages.HasString(package->Info().Name()))
+                       continue;
                printf("    uninstall package %s\n", 
package->VersionedName().String());
        }
 // TODO: Print file/download sizes. Unfortunately our package infos don't

############################################################################

Revision:    hrev48937
Commit:      c771066bd2216500496b5e5ca360e06db74bf819
URL:         http://cgit.haiku-os.org/haiku/commit/?id=c771066bd221
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Mar 27 20:08:15 2015 UTC

pkgman: cleanup output.

This makes the progressbars disappear after the download is complete,
as well as reducing the number of lines for most actions to 1 instead
of 3-4.

----------------------------------------------------------------------------

diff --git a/src/bin/pkgman/PackageManager.cpp 
b/src/bin/pkgman/PackageManager.cpp
index 17ec895..799af30 100644
--- a/src/bin/pkgman/PackageManager.cpp
+++ b/src/bin/pkgman/PackageManager.cpp
@@ -181,6 +181,9 @@ void
 PackageManager::ProgressPackageDownloadActive(const char* packageName,
        float completionPercentage)
 {
+       if (!fInteractive)
+               return;
+
        static const char* progressChars[] = {
                "\xE2\x96\x8F",
                "\xE2\x96\x8E",
@@ -201,7 +204,7 @@ PackageManager::ProgressPackageDownloadActive(const char* 
packageName,
        int ipart = (int)(completionPercentage * width);
        int fpart = (int)(((completionPercentage * width) - ipart) * 8);
 
-       printf("\r"); // erase the line
+       printf("\r"); // return to the beginning of the line
 
        for (position = 0; position < width; position++) {
                if (position < ipart) {
@@ -226,21 +229,31 @@ PackageManager::ProgressPackageDownloadActive(const char* 
packageName,
 void
 PackageManager::ProgressPackageDownloadComplete(const char* packageName)
 {
-       printf("\nFinished downloading %s.\n", packageName);
+       if (fInteractive) {
+               // Overwrite the progress bar with whitespace
+               printf("\r");
+               struct winsize w;
+               ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
+               for (int i = 0; i < (w.ws_col); i++)
+                       printf(" ");
+               printf("\r\x1b[1A"); // Go to previous line.
+       }
+
+       printf("Downloading %s...done.\n", packageName);
 }
 
 
 void
 PackageManager::ProgressPackageChecksumStarted(const char* title)
 {
-       printf("%s...\n", title);
+       printf("%s...", title);
 }
 
 
 void
 PackageManager::ProgressPackageChecksumComplete(const char* title)
 {
-       printf("%s complete.\n", title);
+       printf("done.\n");
 }
 
 


Other related posts: