[Aptitude-svn-commit] r4329 - in branches/aptitude-0.3/aptitude: .
src/generic/apt
Daniel Burrows
dburrows at costa.debian.org
Thu Sep 29 20:46:26 UTC 2005
Author: dburrows
Date: Thu Sep 29 20:46:23 2005
New Revision: 4329
Added:
branches/aptitude-0.3/aptitude/src/generic/apt/log.cc
branches/aptitude-0.3/aptitude/src/generic/apt/log.h
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am
branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc
branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h
Log:
Split the log code from the download code.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Sep 29 20:46:23 2005
@@ -1,5 +1,9 @@
2005-09-29 Daniel Burrows <dburrows at debian.org>
+ * src/generic/apt/download_install_manager.cc, src/generic/apt/download_install_manager.h, src/generic/apt/log.cc, src/generic/apt/log.h:
+
+ Split the log code from the download code.
+
* po/POTFILES.in, src/generic/apt/download_install_manager.cc, src/generic/apt/download_install_manager.h, src/generic/apt/download_manager.cc, src/generic/apt/download_manager.h, src/generic/apt/download_update_manager.cc, src/generic/apt/download_update_manager.h, src/generic/apt/Makefile.am:
Write a generic interface to manage operations that involve
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am Thu Sep 29 20:46:23 2005
@@ -39,6 +39,8 @@
download_signal_log.h \
infer_reason.cc \
infer_reason.h \
+ log.cc \
+ log.h \
matchers.cc \
matchers.h \
pkg_acqfile.cc \
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc Thu Sep 29 20:46:23 2005
@@ -19,7 +19,9 @@
#include "download_install_manager.h"
+#include "config_signal.h"
#include "download_signal_log.h"
+#include "log.h"
#include <aptitude.h>
@@ -27,13 +29,6 @@
#include <apt-pkg/dpkgpm.h>
#include <apt-pkg/error.h>
#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/strutl.h>
-
-#include <generic/apt/config_signal.h>
-
-#include <generic/util/util.h>
-
-#include <errno.h>
using namespace std;
@@ -47,163 +42,6 @@
delete pm;
}
-bool download_install_manager::do_log(const string &log,
- const loglist &changed_packages)
-{
- FILE *f = NULL;
-
- if(log[0] == '|')
- f = popen(log.c_str()+1, "w");
- else
- f = fopen(log.c_str(), "a");
-
- if(!f)
- {
- _error->Errno(_("Unable to open %s to log actions"), log.c_str());
-
- return false;
- }
-
- time_t curtime = time(NULL);
- tm ltime;
- string timestr;
-
- if(localtime_r(&curtime, <ime) != NULL)
- timestr = sstrftime("%a, %b %e %Y %T %z", <ime);
- else
- timestr = ssprintf(_("Error generating local time (%s)"),
- sstrerror(errno).c_str());
-
- fprintf(f, "Aptitude " VERSION ": %s\n%s\n\n",
- _("log report"), timestr.c_str());
- fprintf(f, _("IMPORTANT: this log only lists intended actions; actions which fail due to\ndpkg problems may not be completed.\n\n"));
- fprintf(f, _("Will install %li packages, and remove %li packages.\n"),
- (*apt_cache_file)->InstCount(), (*apt_cache_file)->DelCount());
-
- if((*apt_cache_file)->UsrSize() > 0)
- fprintf(f, _("%sB of disk space will be used\n"),
- SizeToStr((*apt_cache_file)->UsrSize()).c_str());
- else if((*apt_cache_file)->UsrSize() < 0)
- fprintf(f, _("%sB of disk space will be freed\n"),
- SizeToStr((*apt_cache_file)->UsrSize()).c_str());
-
- fprintf(f, "===============================================================================\n");
-
-
- for(loglist::const_iterator i = changed_packages.begin();
- i != changed_packages.end(); ++i)
- {
- if(i->second == pkg_upgrade)
- fprintf(f, _("[UPGRADE] %s %s -> %s\n"), i->first.Name(),
- i->first.CurrentVer().VerStr(),
- (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
- else if(i->second == pkg_downgrade)
- fprintf(f, _("[DOWNGRADE] %s %s -> %s\n"), i->first.Name(),
- i->first.CurrentVer().VerStr(),
- (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
- else
- if(i->second != pkg_unchanged)
- {
- const char *tag = NULL;
- switch(i->second)
- {
- case pkg_remove:
- tag = _("REMOVE");
- break;
- //case pkg_upgrade:
- //tag=_("UPGRADE");
- //break;
- case pkg_install:
- tag = _("INSTALL");
- break;
- case pkg_reinstall:
- tag = _("REINSTALL");
- break;
- case pkg_hold:
- tag = _("HOLD");
- break;
- case pkg_broken:
- tag = _("BROKEN");
- break;
- case pkg_unused_remove:
- tag = _("REMOVE, NOT USED");
- break;
- case pkg_auto_remove:
- tag = _("REMOVE, DEPENDENCIES");
- break;
- case pkg_auto_install:
- tag = _("INSTALL, DEPENDENCIES");
- break;
- case pkg_auto_hold:
- tag = _("HOLD, DEPENDENCIES");
- default:
- tag = _("????????");
- break;
- }
-
- fprintf(f, _("[%s] %s\n"), tag, i->first.Name());
- }
- }
- fprintf(f, _("===============================================================================\n\nLog complete.\n"));
-
- if(log[0] == '|')
- pclose(f);
- else
- fclose(f);
-
- return true;
-}
-struct download_install_manager::log_sorter
-{
-public:
- inline bool operator()(const download_install_manager::logitem &a, const download_install_manager::logitem &b)
- {
- if(a.second<b.second)
- return true;
- else if(a.second>b.second)
- return false;
- else return strcmp(a.first.Name(), b.first.Name())<0;
- }
-};
-
-void download_install_manager::log_changes()
-{
- vector<string> logs;
-
- string main_log = aptcfg->Find(PACKAGE "::Log", "/var/log/" PACKAGE);
-
- if(!main_log.empty())
- logs.push_back(main_log);
-
- const Configuration::Item *parent = aptcfg->Tree(PACKAGE "::Log");
-
- if(parent != NULL)
- for(const Configuration::Item *curr = parent->Child;
- curr != NULL; curr = curr->Next)
- {
- if(!curr->Value.empty())
- logs.push_back(curr->Value);
- }
-
- if(!logs.empty())
- {
- loglist changed_packages;
- for(pkgCache::PkgIterator i
- = (*apt_cache_file)->PkgBegin(); !i.end(); i++)
- {
- pkg_action_state s = find_pkg_state(i);
- if(s != pkg_unchanged)
- changed_packages.push_back(logitem(i, s));
- }
-
- sort(changed_packages.begin(), changed_packages.end(), log_sorter());
-
- for(vector<string>::iterator i
- = logs.begin(); i != logs.end(); ++i)
- do_log(*i, changed_packages);
- }
-}
-
bool download_install_manager::prepare(OpProgress &progress,
bool download_only,
pkgAcquireStatus *acqlog,
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h Thu Sep 29 20:46:23 2005
@@ -46,19 +46,6 @@
/** The package manager object used when installing packages */
pkgPackageManager *pm;
- // Stuff for logging; should split out of this class and file:
- struct log_sorter;
- friend struct log_sorter;
- typedef std::pair<pkgCache::PkgIterator, pkg_action_state> logitem;
- typedef std::vector<logitem> loglist;
-
- /** Perform the actual logging. */
- static bool do_log(const std::string &log,
- const loglist &changed_packages);
-
- /** Write out any changes to the log file. */
- static void log_changes();
-
/** Actually perform the installation/removal of packages and tell
* the caller what happened.
*/
Added: branches/aptitude-0.3/aptitude/src/generic/apt/log.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/log.cc Thu Sep 29 20:46:23 2005
@@ -0,0 +1,196 @@
+// log.cc
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#include "log.h"
+
+#include "apt.h"
+#include "config_signal.h"
+
+#include <aptitude.h>
+
+#include <generic/util/util.h>
+
+#include <apt-pkg/error.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/strutl.h>
+
+#include <errno.h>
+
+using namespace std;
+
+typedef std::pair<pkgCache::PkgIterator, pkg_action_state> logitem;
+typedef std::vector<logitem> loglist;
+
+bool do_log(const string &log,
+ const loglist &changed_packages)
+{
+ FILE *f = NULL;
+
+ if(log[0] == '|')
+ f = popen(log.c_str()+1, "w");
+ else
+ f = fopen(log.c_str(), "a");
+
+ if(!f)
+ {
+ _error->Errno(_("Unable to open %s to log actions"), log.c_str());
+
+ return false;
+ }
+
+ time_t curtime = time(NULL);
+ tm ltime;
+ string timestr;
+
+ if(localtime_r(&curtime, <ime) != NULL)
+ timestr = sstrftime("%a, %b %e %Y %T %z", <ime);
+ else
+ timestr = ssprintf(_("Error generating local time (%s)"),
+ sstrerror(errno).c_str());
+
+ fprintf(f, "Aptitude " VERSION ": %s\n%s\n\n",
+ _("log report"), timestr.c_str());
+ fprintf(f, _("IMPORTANT: this log only lists intended actions; actions which fail due to\ndpkg problems may not be completed.\n\n"));
+ fprintf(f, _("Will install %li packages, and remove %li packages.\n"),
+ (*apt_cache_file)->InstCount(), (*apt_cache_file)->DelCount());
+
+ if((*apt_cache_file)->UsrSize() > 0)
+ fprintf(f, _("%sB of disk space will be used\n"),
+ SizeToStr((*apt_cache_file)->UsrSize()).c_str());
+ else if((*apt_cache_file)->UsrSize() < 0)
+ fprintf(f, _("%sB of disk space will be freed\n"),
+ SizeToStr((*apt_cache_file)->UsrSize()).c_str());
+
+ fprintf(f, "===============================================================================\n");
+
+
+ for(loglist::const_iterator i = changed_packages.begin();
+ i != changed_packages.end(); ++i)
+ {
+ if(i->second == pkg_upgrade)
+ fprintf(f, _("[UPGRADE] %s %s -> %s\n"), i->first.Name(),
+ i->first.CurrentVer().VerStr(),
+ (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
+ else if(i->second == pkg_downgrade)
+ fprintf(f, _("[DOWNGRADE] %s %s -> %s\n"), i->first.Name(),
+ i->first.CurrentVer().VerStr(),
+ (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
+ else
+ if(i->second != pkg_unchanged)
+ {
+ const char *tag = NULL;
+ switch(i->second)
+ {
+ case pkg_remove:
+ tag = _("REMOVE");
+ break;
+ //case pkg_upgrade:
+ //tag=_("UPGRADE");
+ //break;
+ case pkg_install:
+ tag = _("INSTALL");
+ break;
+ case pkg_reinstall:
+ tag = _("REINSTALL");
+ break;
+ case pkg_hold:
+ tag = _("HOLD");
+ break;
+ case pkg_broken:
+ tag = _("BROKEN");
+ break;
+ case pkg_unused_remove:
+ tag = _("REMOVE, NOT USED");
+ break;
+ case pkg_auto_remove:
+ tag = _("REMOVE, DEPENDENCIES");
+ break;
+ case pkg_auto_install:
+ tag = _("INSTALL, DEPENDENCIES");
+ break;
+ case pkg_auto_hold:
+ tag = _("HOLD, DEPENDENCIES");
+ default:
+ tag = _("????????");
+ break;
+ }
+
+ fprintf(f, _("[%s] %s\n"), tag, i->first.Name());
+ }
+ }
+ fprintf(f, _("===============================================================================\n\nLog complete.\n"));
+
+ if(log[0] == '|')
+ pclose(f);
+ else
+ fclose(f);
+
+ return true;
+}
+
+struct log_sorter
+{
+public:
+ inline bool operator()(const logitem &a, const logitem &b)
+ {
+ if(a.second<b.second)
+ return true;
+ else if(a.second>b.second)
+ return false;
+ else return strcmp(a.first.Name(), b.first.Name())<0;
+ }
+};
+
+void log_changes()
+{
+ vector<string> logs;
+
+ string main_log = aptcfg->Find(PACKAGE "::Log", "/var/log/" PACKAGE);
+
+ if(!main_log.empty())
+ logs.push_back(main_log);
+
+ const Configuration::Item *parent = aptcfg->Tree(PACKAGE "::Log");
+
+ if(parent != NULL)
+ for(const Configuration::Item *curr = parent->Child;
+ curr != NULL; curr = curr->Next)
+ {
+ if(!curr->Value.empty())
+ logs.push_back(curr->Value);
+ }
+
+ if(!logs.empty())
+ {
+ loglist changed_packages;
+ for(pkgCache::PkgIterator i
+ = (*apt_cache_file)->PkgBegin(); !i.end(); i++)
+ {
+ pkg_action_state s = find_pkg_state(i);
+ if(s != pkg_unchanged)
+ changed_packages.push_back(logitem(i, s));
+ }
+
+ sort(changed_packages.begin(), changed_packages.end(), log_sorter());
+
+ for(vector<string>::iterator i
+ = logs.begin(); i != logs.end(); ++i)
+ do_log(*i, changed_packages);
+ }
+}
Added: branches/aptitude-0.3/aptitude/src/generic/apt/log.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/log.h Thu Sep 29 20:46:23 2005
@@ -0,0 +1,30 @@
+// log.h -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+//
+// A routine to write aptitude's automatic installation log.
+
+#ifndef LOG_H
+#define LOG_H
+
+/** Look up the log file's location in the apt configuration, and
+ * write a log stanza to it.
+ */
+void log_changes();
+
+#endif
More information about the Aptitude-svn-commit
mailing list