From facea693b2078327b59502e663c238c50118e96a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 18 Sep 2013 17:55:44 +0200 Subject: improve the API for Upgrade() --- apt-private/private-upgrade.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 9a5286b57..6ea7c19d6 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -39,7 +39,7 @@ bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL) return false; // Do the upgrade - if (pkgAllUpgradeNoDelete(Cache) == false) + if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::ALLOW_NEW_INSTALLS) == false) { ShowBroken(c1out,Cache,false); return _error->Error(_("Internal error, AllUpgrade broke stuff")); -- cgit v1.2.3 From 5ca0cf51194422fb0f094bbf5e61e9f5eb57f013 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 5 Oct 2013 11:54:08 +0200 Subject: cleanup upgrade API some more (thanks for the feedback from David) --- apt-private/private-upgrade.cc | 55 +++++++++++++++++++++++------------------- apt-private/private-upgrade.h | 1 + 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 6ea7c19d6..00608866f 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -1,54 +1,59 @@ // Includes /*{{{*/ #include - +#include #include "private-install.h" #include "private-cachefile.h" #include "private-upgrade.h" #include "private-output.h" /*}}}*/ -// DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/ -// --------------------------------------------------------------------- -/* Upgrade all packages without installing new packages or erasing old - packages */ -bool DoUpgradeNoNewPackages(CommandLine &CmdL) +// this is actually performing the various upgrade operations +static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) { CacheFile Cache; if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; - // Do the upgrade - if (pkgAllUpgrade(Cache) == false) + //c0out << _("Calculating upgrade... ") << std::flush; + if (APT::Upgrade::Upgrade(Cache, UpgradeFlags) == false) { + c0out << _("Failed") << std::endl; ShowBroken(c1out,Cache,false); - return _error->Error(_("Internal error, AllUpgrade broke stuff")); + return _error->Error(_("Internal error, Upgrade broke stuff")); } // parse additional cmdline pkg manipulation switches if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) return false; + + //c0out << _("Done") << std::endl; return InstallPackages(Cache,true); } + +// DoDistUpgrade - Automatic smart upgrader /*{{{*/ +// --------------------------------------------------------------------- +/* Intelligent upgrader that will install and remove packages at will */ +bool DoDistUpgrade(CommandLine &CmdL) +{ + return UpgradeHelper(CmdL, 0); +} + /*}}}*/ +// DoUpgradeNoNewPackages - Upgrade all packages /*{{{*/ +// --------------------------------------------------------------------- +/* Upgrade all packages without installing new packages or erasing old + packages */ +bool DoUpgradeNoNewPackages(CommandLine &CmdL) +{ + // Do the upgrade + return UpgradeHelper(CmdL, + APT::Upgrade::FORBID_REMOVE_PACKAGES| + APT::Upgrade::FORBID_NEW_INSTALL_PACKAGES); +} /*}}}*/ // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/ bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL) { - CacheFile Cache; - if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) - return false; - - // Do the upgrade - if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::ALLOW_NEW_INSTALLS) == false) - { - ShowBroken(c1out,Cache,false); - return _error->Error(_("Internal error, AllUpgrade broke stuff")); - } - - // parse additional cmdline pkg manipulation switches - if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) - return false; - - return InstallPackages(Cache,true); + return UpgradeHelper(CmdL, APT::Upgrade::FORBID_REMOVE_PACKAGES); } /*}}}*/ diff --git a/apt-private/private-upgrade.h b/apt-private/private-upgrade.h index 6ede6f96c..050d3a668 100644 --- a/apt-private/private-upgrade.h +++ b/apt-private/private-upgrade.h @@ -4,6 +4,7 @@ #include +bool DoDistUpgrade(CommandLine &CmdL); bool DoUpgradeNoNewPackages(CommandLine &CmdL); bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL); -- cgit v1.2.3 From 7cf45682e5fcac541e495242bdc4885bbb8b2ef7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 5 Oct 2013 11:55:08 +0200 Subject: re-add "Calculating upgrade..." message --- apt-private/private-upgrade.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 00608866f..df8fe8686 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -14,19 +14,18 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; - //c0out << _("Calculating upgrade... ") << std::flush; + c0out << _("Calculating upgrade... ") << std::flush; if (APT::Upgrade::Upgrade(Cache, UpgradeFlags) == false) { c0out << _("Failed") << std::endl; ShowBroken(c1out,Cache,false); return _error->Error(_("Internal error, Upgrade broke stuff")); } + c0out << _("Done") << std::endl; // parse additional cmdline pkg manipulation switches if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) return false; - - //c0out << _("Done") << std::endl; return InstallPackages(Cache,true); } -- cgit v1.2.3 From 82e369c4b93b5b81db7988ab377a3c5bd388268e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 5 Oct 2013 12:15:03 +0200 Subject: * move upgrade releated code into upgrade.{cc,h} The upgrade releated code is moved into upgrade.{cc,h} and all pkg*Upgrade* prototypes are included in algorihms.h to avoid breaking API (unless build with APT_9_CLEANER_HEADERS). --- apt-private/private-cachefile.cc | 1 + apt-private/private-upgrade.cc | 1 + 2 files changed, 2 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc index 25f65ef09..c822b9bad 100644 --- a/apt-private/private-cachefile.cc +++ b/apt-private/private-cachefile.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index df8fe8686..456cbc0fa 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -1,5 +1,6 @@ // Includes /*{{{*/ #include +#include #include #include "private-install.h" #include "private-cachefile.h" -- cgit v1.2.3 From d428d131a29a08fa7c1d95b98b684fb2ebb554c0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 5 Oct 2013 12:22:55 +0200 Subject: Move ListUpdate/AquireUpdate into update.{cc,h} This moves the ListUpdate/AquireUpdate out of the "catch-all" algorithm.{cc,h} file into its own update.{cc,h} --- apt-private/private-update.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 61259748d..f6c12c26a 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include -- cgit v1.2.3 From e6ad8031b774af9bdd5d460d9983450bb5a03d0d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 13 Oct 2013 15:05:04 +0200 Subject: move the status-fd progress reporting out of the pkgDPkgPM class, at this point, breaks ABI/API, lets see what we can do about this --- apt-private/private-install.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 643a6b370..d1066c869 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -104,7 +105,11 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) { pkgSimulate PM(Cache); int status_fd = _config->FindI("APT::Status-Fd",-1); - pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd); + APT::Progress::PackageManager *progress = NULL; + if (status_fd > 0) + progress = new APT::Progress::PackageManagerProgressFd(status_fd); + pkgPackageManager::OrderResult Res = PM.DoInstall(progress); + delete progress; if (Res == pkgPackageManager::Failed) return false; if (Res != pkgPackageManager::Completed) @@ -332,8 +337,23 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) } _system->UnLock(); + + // FIXME: make this a factory + // select the right progress int status_fd = _config->FindI("APT::Status-Fd",-1); - pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd); + APT::Progress::PackageManager *progress = NULL; + 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(); + else if (_config->FindB("Dpkg::Progress", + _config->FindB("DpkgPM::Progress", false)) == true) + progress = new APT::Progress::PackageManagerText(); + else + progress = new APT::Progress::PackageManager(); + pkgPackageManager::OrderResult Res = PM->DoInstall(progress); + delete progress; + if (Res == pkgPackageManager::Failed || _error->PendingError() == true) return false; if (Res == pkgPackageManager::Completed) -- cgit v1.2.3 From 5e9458e285af11c7fa4308add10d250e3546c8bf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 14 Oct 2013 08:42:48 +0200 Subject: re-add APT::Keep-Fds:: for the dpkg status-fd in dpkgpm.cc as we always need this --- apt-private/private-install.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index d1066c869..8d72faecc 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -104,12 +104,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) if (_config->FindB("APT::Get::Simulate") == true) { pkgSimulate PM(Cache); + int status_fd = _config->FindI("APT::Status-Fd",-1); APT::Progress::PackageManager *progress = NULL; if (status_fd > 0) progress = new APT::Progress::PackageManagerProgressFd(status_fd); pkgPackageManager::OrderResult Res = PM.DoInstall(progress); delete progress; + if (Res == pkgPackageManager::Failed) return false; if (Res != pkgPackageManager::Completed) @@ -341,6 +343,7 @@ 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); + APT::Progress::PackageManager *progress = NULL; if (status_fd > 0) progress = new APT::Progress::PackageManagerProgressFd(status_fd); -- cgit v1.2.3 From 1c6cedc489b5eaeed1b7fdb845eca06bc1fccd4f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 21 Oct 2013 21:23:07 +0200 Subject: move iprogress.{cc,h} to private-progress.{cc,h} until its fully stable --- apt-private/makefile | 2 +- apt-private/private-progress.cc | 221 ++++++++++++++++++++++++++++++++++++++++ apt-private/private-progress.h | 109 ++++++++++++++++++++ 3 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 apt-private/private-progress.cc create mode 100644 apt-private/private-progress.h (limited to 'apt-private') diff --git a/apt-private/makefile b/apt-private/makefile index 1d179f0b2..9b074f189 100644 --- a/apt-private/makefile +++ b/apt-private/makefile @@ -17,7 +17,7 @@ MAJOR=0.0 MINOR=0 SLIBS=$(PTHREADLIB) -lapt-pkg -PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main +PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main progress SOURCE += $(foreach private, $(PRIVATES), private-$(private).cc) HEADERS += $(foreach private, $(PRIVATES), private-$(private).h) diff --git a/apt-private/private-progress.cc b/apt-private/private-progress.cc new file mode 100644 index 000000000..daa7695e2 --- /dev/null +++ b/apt-private/private-progress.cc @@ -0,0 +1,221 @@ +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace APT { +namespace Progress { + +bool PackageManager::StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string HumanReadableAction) +{ + int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); + percentage = StepsDone/(float)TotalSteps * 100.0; + strprintf(progress_str, _("Progress: [%3i%%]"), (int)percentage); + + if(percentage < (last_reported_progress + reporting_steps)) + return false; + + return true; +} + +PackageManagerProgressFd::PackageManagerProgressFd(int progress_fd) + : StepsDone(0), StepsTotal(1) +{ + OutStatusFd = progress_fd; +} + +void PackageManagerProgressFd::WriteToStatusFd(std::string s) +{ + if(OutStatusFd <= 0) + return; + FileFd::Write(OutStatusFd, s.c_str(), s.size()); +} + +void PackageManagerProgressFd::Start() +{ + if(OutStatusFd <= 0) + return; + + // 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 << "pmstatus:dpkg-exec:" + << (StepsDone/float(StepsTotal)*100.0) + << ":" << _("Running dpkg") + << std::endl; + WriteToStatusFd(status.str()); +} + +void PackageManagerProgressFd::Stop() +{ + // clear the Keep-Fd again + _config->Clear("APT::Keep-Fds", OutStatusFd); +} + +void PackageManagerProgressFd::Error(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string ErrorMessage) +{ + std::ostringstream status; + status << "pmerror:" << PackageName + << ":" << (StepsDone/float(TotalSteps)*100.0) + << ":" << ErrorMessage + << std::endl; + WriteToStatusFd(status.str()); +} + +void PackageManagerProgressFd::ConffilePrompt(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string ConfMessage) +{ + std::ostringstream status; + status << "pmconffile:" << PackageName + << ":" << (StepsDone/float(TotalSteps)*100.0) + << ":" << ConfMessage + << std::endl; + WriteToStatusFd(status.str()); +} + + +bool PackageManagerProgressFd::StatusChanged(std::string PackageName, + unsigned int xStepsDone, + unsigned int xTotalSteps, + std::string pkg_action) +{ + StepsDone = xStepsDone; + StepsTotal = xTotalSteps; + + // build the status str + std::ostringstream status; + status << "pmstatus:" << StringSplit(PackageName, ":")[0] + << ":" << (StepsDone/float(StepsTotal)*100.0) + << ":" << pkg_action + << std::endl; + WriteToStatusFd(status.str()); + + if(_config->FindB("Debug::APT::Progress::PackageManagerFd", false) == true) + std::cerr << "progress: " << PackageName << " " << xStepsDone + << " " << xTotalSteps << " " << pkg_action + << std::endl; + + + return true; +} + +void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows) +{ + // scroll down a bit to avoid visual glitch when the screen + // area shrinks by one row + std::cout << "\n"; + + // save cursor + std::cout << "\033[s"; + + // set scroll region (this will place the cursor in the top left) + std::cout << "\033[1;" << nr_rows - 1 << "r"; + + // restore cursor but ensure its inside the scrolling area + std::cout << "\033[u"; + static const char *move_cursor_up = "\033[1A"; + std::cout << move_cursor_up; + + std::flush(std::cout); +} + +PackageManagerFancy::PackageManagerFancy() + : nr_terminal_rows(-1) +{ + struct winsize win; + if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) == 0) + { + nr_terminal_rows = win.ws_row; + } +} + +void PackageManagerFancy::Start() +{ + if (nr_terminal_rows > 0) + SetupTerminalScrollArea(nr_terminal_rows); +} + +void PackageManagerFancy::Stop() +{ + if (nr_terminal_rows > 0) + { + SetupTerminalScrollArea(nr_terminal_rows + 1); + + // override the progress line (sledgehammer) + static const char* clear_screen_below_cursor = "\033[J"; + std::cout << clear_screen_below_cursor; + } +} + +bool PackageManagerFancy::StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string HumanReadableAction) +{ + if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps, + HumanReadableAction)) + return false; + + int row = nr_terminal_rows; + + static string save_cursor = "\033[s"; + static string restore_cursor = "\033[u"; + + static string set_bg_color = "\033[42m"; // green + static string set_fg_color = "\033[30m"; // black + + static string restore_bg = "\033[49m"; + static string restore_fg = "\033[39m"; + + std::cout << save_cursor + // move cursor position to last row + << "\033[" << row << ";0f" + << set_bg_color + << set_fg_color + << progress_str + << restore_cursor + << restore_bg + << restore_fg; + std::flush(std::cout); + last_reported_progress = percentage; + + return true; +} + +bool PackageManagerText::StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string HumanReadableAction) +{ + if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps, HumanReadableAction)) + return false; + + std::cout << progress_str << "\r\n"; + std::flush(std::cout); + + last_reported_progress = percentage; + + return true; +} + + +}; // namespace progress +}; // namespace apt diff --git a/apt-private/private-progress.h b/apt-private/private-progress.h new file mode 100644 index 000000000..42fa89be4 --- /dev/null +++ b/apt-private/private-progress.h @@ -0,0 +1,109 @@ +#ifndef PKGLIB_IPROGRESS_H +#define PKGLIB_IPROGRESS_H + +#include +#include + + +namespace APT { +namespace Progress { + + class PackageManager + { + private: + /** \brief dpointer placeholder */ + void *d; + + protected: + std::string progress_str; + float percentage; + int last_reported_progress; + + public: + PackageManager() + : percentage(0.0), last_reported_progress(-1) {}; + virtual ~PackageManager() {}; + + virtual void Start() {}; + virtual void Stop() {}; + + virtual pid_t fork() {return fork(); }; + + virtual void Pulse() {}; + virtual long GetPulseInterval() { + return 500000; + }; + + 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 PackageManagerProgressFd : public PackageManager + { + protected: + int OutStatusFd; + int StepsDone; + int StepsTotal; + void WriteToStatusFd(std::string msg); + + public: + PackageManagerProgressFd(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: + int nr_terminal_rows; + void SetupTerminalScrollArea(int nr_rows); + + public: + PackageManagerFancy(); + virtual void Start(); + virtual void Stop(); + virtual bool StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string HumanReadableAction); + }; + + class PackageManagerText : public PackageManager + { + public: + virtual bool StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps, + std::string HumanReadableAction); + }; + + +}; // namespace Progress +}; // namespace APT + +#endif -- cgit v1.2.3 From c7ea1ebaef0edebfe41353f93a81ee2ada5870a8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 21 Oct 2013 22:11:40 +0200 Subject: add APT::Status-deb822-Fd --- apt-private/private-install.cc | 11 ++++-- apt-private/private-progress.cc | 87 ++++++++++++++++++++++++++++++++++++++++- apt-private/private-progress.h | 28 +++++++++++++ 3 files changed, 122 insertions(+), 4 deletions(-) (limited to 'apt-private') 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 #include #include -#include + +#include #include #include @@ -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 #include -#include #include +#include + #include #include @@ -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: -- cgit v1.2.3 From 8336ae355b8a22877cd233063c715688155aa617 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Oct 2013 18:44:14 +0200 Subject: move install-progress.{cc,h} to apt-pkg --- apt-private/makefile | 2 +- apt-private/private-progress.cc | 306 ---------------------------------------- apt-private/private-progress.h | 137 ------------------ 3 files changed, 1 insertion(+), 444 deletions(-) delete mode 100644 apt-private/private-progress.cc delete mode 100644 apt-private/private-progress.h (limited to 'apt-private') diff --git a/apt-private/makefile b/apt-private/makefile index 9b074f189..1d179f0b2 100644 --- a/apt-private/makefile +++ b/apt-private/makefile @@ -17,7 +17,7 @@ MAJOR=0.0 MINOR=0 SLIBS=$(PTHREADLIB) -lapt-pkg -PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main progress +PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main SOURCE += $(foreach private, $(PRIVATES), private-$(private).cc) HEADERS += $(foreach private, $(PRIVATES), private-$(private).h) diff --git a/apt-private/private-progress.cc b/apt-private/private-progress.cc deleted file mode 100644 index 1d15228c2..000000000 --- a/apt-private/private-progress.cc +++ /dev/null @@ -1,306 +0,0 @@ -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include - -namespace APT { -namespace Progress { - -bool PackageManager::StatusChanged(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string HumanReadableAction) -{ - int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); - percentage = StepsDone/(float)TotalSteps * 100.0; - strprintf(progress_str, _("Progress: [%3i%%]"), (int)percentage); - - if(percentage < (last_reported_progress + reporting_steps)) - return false; - - return true; -} - -PackageManagerProgressFd::PackageManagerProgressFd(int progress_fd) - : StepsDone(0), StepsTotal(1) -{ - OutStatusFd = progress_fd; -} - -void PackageManagerProgressFd::WriteToStatusFd(std::string s) -{ - if(OutStatusFd <= 0) - return; - FileFd::Write(OutStatusFd, s.c_str(), s.size()); -} - -void PackageManagerProgressFd::Start() -{ - if(OutStatusFd <= 0) - return; - - // 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 << "pmstatus:dpkg-exec:" - << (StepsDone/float(StepsTotal)*100.0) - << ":" << _("Running dpkg") - << std::endl; - WriteToStatusFd(status.str()); -} - -void PackageManagerProgressFd::Stop() -{ - // clear the Keep-Fd again - _config->Clear("APT::Keep-Fds", OutStatusFd); -} - -void PackageManagerProgressFd::Error(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string ErrorMessage) -{ - std::ostringstream status; - status << "pmerror:" << PackageName - << ":" << (StepsDone/float(TotalSteps)*100.0) - << ":" << ErrorMessage - << std::endl; - WriteToStatusFd(status.str()); -} - -void PackageManagerProgressFd::ConffilePrompt(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string ConfMessage) -{ - std::ostringstream status; - status << "pmconffile:" << PackageName - << ":" << (StepsDone/float(TotalSteps)*100.0) - << ":" << ConfMessage - << std::endl; - WriteToStatusFd(status.str()); -} - - -bool PackageManagerProgressFd::StatusChanged(std::string PackageName, - unsigned int xStepsDone, - unsigned int xTotalSteps, - std::string pkg_action) -{ - StepsDone = xStepsDone; - StepsTotal = xTotalSteps; - - // build the status str - std::ostringstream status; - status << "pmstatus:" << StringSplit(PackageName, ":")[0] - << ":" << (StepsDone/float(StepsTotal)*100.0) - << ":" << pkg_action - << std::endl; - WriteToStatusFd(status.str()); - - if(_config->FindB("Debug::APT::Progress::PackageManagerFd", false) == true) - std::cerr << "progress: " << PackageName << " " << xStepsDone - << " " << xTotalSteps << " " << pkg_action - << std::endl; - - - 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 - // area shrinks by one row - std::cout << "\n"; - - // save cursor - std::cout << "\033[s"; - - // set scroll region (this will place the cursor in the top left) - std::cout << "\033[1;" << nr_rows - 1 << "r"; - - // restore cursor but ensure its inside the scrolling area - std::cout << "\033[u"; - static const char *move_cursor_up = "\033[1A"; - std::cout << move_cursor_up; - - std::flush(std::cout); -} - -PackageManagerFancy::PackageManagerFancy() - : nr_terminal_rows(-1) -{ - struct winsize win; - if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) == 0) - { - nr_terminal_rows = win.ws_row; - } -} - -void PackageManagerFancy::Start() -{ - if (nr_terminal_rows > 0) - SetupTerminalScrollArea(nr_terminal_rows); -} - -void PackageManagerFancy::Stop() -{ - if (nr_terminal_rows > 0) - { - SetupTerminalScrollArea(nr_terminal_rows + 1); - - // override the progress line (sledgehammer) - static const char* clear_screen_below_cursor = "\033[J"; - std::cout << clear_screen_below_cursor; - } -} - -bool PackageManagerFancy::StatusChanged(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string HumanReadableAction) -{ - if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps, - HumanReadableAction)) - return false; - - int row = nr_terminal_rows; - - static string save_cursor = "\033[s"; - static string restore_cursor = "\033[u"; - - static string set_bg_color = "\033[42m"; // green - static string set_fg_color = "\033[30m"; // black - - static string restore_bg = "\033[49m"; - static string restore_fg = "\033[39m"; - - std::cout << save_cursor - // move cursor position to last row - << "\033[" << row << ";0f" - << set_bg_color - << set_fg_color - << progress_str - << restore_cursor - << restore_bg - << restore_fg; - std::flush(std::cout); - last_reported_progress = percentage; - - return true; -} - -bool PackageManagerText::StatusChanged(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string HumanReadableAction) -{ - if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps, HumanReadableAction)) - return false; - - std::cout << progress_str << "\r\n"; - std::flush(std::cout); - - last_reported_progress = percentage; - - return true; -} - - - -}; // namespace progress -}; // namespace apt diff --git a/apt-private/private-progress.h b/apt-private/private-progress.h deleted file mode 100644 index 9c31eac92..000000000 --- a/apt-private/private-progress.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef PKGLIB_IPROGRESS_H -#define PKGLIB_IPROGRESS_H - -#include -#include - - -namespace APT { -namespace Progress { - - class PackageManager - { - private: - /** \brief dpointer placeholder */ - void *d; - - protected: - std::string progress_str; - float percentage; - int last_reported_progress; - - public: - PackageManager() - : percentage(0.0), last_reported_progress(-1) {}; - virtual ~PackageManager() {}; - - virtual void Start() {}; - virtual void Stop() {}; - - virtual pid_t fork() {return fork(); }; - - virtual void Pulse() {}; - virtual long GetPulseInterval() { - return 500000; - }; - - 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 PackageManagerProgressFd : public PackageManager - { - protected: - int OutStatusFd; - int StepsDone; - int StepsTotal; - void WriteToStatusFd(std::string msg); - - public: - PackageManagerProgressFd(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 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: - int nr_terminal_rows; - void SetupTerminalScrollArea(int nr_rows); - - public: - PackageManagerFancy(); - virtual void Start(); - virtual void Stop(); - virtual bool StatusChanged(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string HumanReadableAction); - }; - - class PackageManagerText : public PackageManager - { - public: - virtual bool StatusChanged(std::string PackageName, - unsigned int StepsDone, - unsigned int TotalSteps, - std::string HumanReadableAction); - }; - - -}; // namespace Progress -}; // namespace APT - -#endif -- cgit v1.2.3 From af36becc889122909d677c267bc5325fb73b6151 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Oct 2013 19:02:01 +0200 Subject: fix install-progress location --- apt-private/private-install.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 1d2acee6c..d9d46dba0 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -23,8 +23,7 @@ #include #include #include - -#include +#include #include #include -- cgit v1.2.3 From bd5f39b34cc0e8cebbe9103f569d4d903e75bd2b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Oct 2013 08:23:12 +0100 Subject: restore ABI and prepare next ABI via #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) --- apt-private/private-install.cc | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index d9d46dba0..3adb00b23 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -105,12 +106,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) { pkgSimulate PM(Cache); - int status_fd = _config->FindI("APT::Status-Fd",-1); - APT::Progress::PackageManager *progress = NULL; - if (status_fd > 0) - progress = new APT::Progress::PackageManagerProgressFd(status_fd); +#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) + APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM.DoInstall(progress); delete progress; +#else + int status_fd = _config->FindI("APT::Status-Fd",-1); + pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd); +#endif if (Res == pkgPackageManager::Failed) return false; @@ -340,26 +343,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) _system->UnLock(); - // FIXME: make this a factory - // select the right progress - 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_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(); - else if (_config->FindB("Dpkg::Progress", - _config->FindB("DpkgPM::Progress", false)) == true) - progress = new APT::Progress::PackageManagerText(); - else - progress = new APT::Progress::PackageManager(); +#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) + APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM->DoInstall(progress); delete progress; +#else + int status_fd = _config->FindI("APT::Status-Fd", -1); + pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd); +#endif if (Res == pkgPackageManager::Failed || _error->PendingError() == true) return false; -- cgit v1.2.3