[Aptitude-svn-commit] r4349 - in branches/aptitude-0.3/aptitude: .
src/generic/apt
Daniel Burrows
dburrows at costa.debian.org
Thu Sep 29 23:50:37 UTC 2005
Author: dburrows
Date: Thu Sep 29 23:50:34 2005
New Revision: 4349
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc
branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h
Log:
Switch the changelog downloader to use a download manager.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Sep 29 23:50:34 2005
@@ -1,5 +1,10 @@
2005-09-29 Daniel Burrows <dburrows at debian.org>
+ * src/generic/apt/pkg_changelog.cc, src/generic/apt/pkg_changelog.h:
+
+ Base the package changelog downloader on the download_manager
+ class.
+
* src/Makefile.am, src/download.cc, src/download.h:
Remove the old download code.
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc Thu Sep 29 23:50:34 2005
@@ -18,13 +18,14 @@
// Boston, MA 02111-1307, USA.
#include "pkg_changelog.h"
+
+#include "apt.h"
+#include "download_manager.h"
#include "pkg_acqfile.h"
#include <aptitude.h>
#include <config.h>
-#include "apt.h"
-
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
@@ -41,36 +42,140 @@
using namespace std;
-pkg_changelog::pkg_changelog(const temp::name &_filename)
- :filename(_filename)
+class download_changelog_manager : public download_manager
{
-}
+ string srcpkg;
+ string ver;
+ string section;
+ string name;
+ string uri;
+
+ sigc::slot1<void, temp::name> k;
+
+ download_signal_log *log;
+
+ /** The name of the file into which the changelog is downloaded. */
+ temp::name tempname;
+
+ bool failed;
+
+
+ /** HACK: This just overrides the failure method to catch 404s. */
+ class AcqWithFail:public pkgAcqFileSane
+ {
+ bool &failed;
+ public:
+ AcqWithFail(pkgAcquire *Owner, string URI,
+ string Description, string ShortDesc, string filename,
+ bool &_failed):
+ pkgAcqFileSane(Owner, URI, Description, ShortDesc, filename),
+ failed(_failed)
+ {
+ failed=false;
+ }
+
+ void Failed(string Message, pkgAcquire::MethodConfig *Cnf)
+ {
+ failed=true;
+ }
+
+ void get_failed();
+ };
-/** HACK: This just overrides the failure method to catch 404s. */
-class AcqWithFail:public pkgAcqFileSane
-{
- bool &failed;
public:
- AcqWithFail(pkgAcquire *Owner, string URI,
- string Description, string ShortDesc, string filename,
- bool &_failed):
- pkgAcqFileSane(Owner, URI, Description, ShortDesc, filename),
- failed(_failed)
+ download_changelog_manager(const string &_srcpkg,
+ const string &_ver,
+ const string &_section,
+ const string &_name,
+ const sigc::slot1<void, temp::name> &_k)
+ : srcpkg(_srcpkg), ver(_ver), section(_section), name(_name),
+ k(_k), log(NULL), failed(false)
{
- failed=false;
}
- void Failed(string Message, pkgAcquire::MethodConfig *Cnf)
+ bool prepare(OpProgress &progress,
+ pkgAcquireStatus &acqlog,
+ download_signal_log *signallog)
{
- failed=true;
+ log = signallog;
+
+ temp::dir tempdir;
+
+ try
+ {
+ tempdir = temp::dir("aptitude");
+ tempname = temp::name(tempdir, "changelog");
+ }
+ catch(temp::TemporaryCreationFailure e)
+ {
+ _error->Error("%s", e.errmsg().c_str());
+ return false;
+ }
+
+ string realsection;
+
+ if(section.find('/') != section.npos)
+ realsection.assign(section, 0, section.find('/'));
+ else
+ realsection.assign("main");
+
+ string prefix;
+
+ if(srcpkg.size() > 3 &&
+ srcpkg[0] == 'l' && srcpkg[1] == 'i' && srcpkg[2] == 'b')
+ prefix = std::string("lib") + srcpkg[3];
+ else
+ prefix = srcpkg[0];
+
+ string realver;
+
+ if(ver.find(':') != ver.npos)
+ realver.assign(ver, ver.find(':')+1, ver.npos);
+ else
+ realver = ver;
+
+ uri = ssprintf("http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog",
+ realsection.c_str(),
+ prefix.c_str(),
+ srcpkg.c_str(),
+ srcpkg.c_str(),
+ realver.c_str());
+
+ fetcher = new pkgAcquire(&acqlog);
+
+ string title = ssprintf(_("ChangeLog of %s"), name.c_str());
+
+ failed = false;
+ new AcqWithFail(fetcher,
+ uri,
+ title,
+ title,
+ tempname.get_name().c_str(),
+ failed);
+
+ return true;
}
- void get_failed();
+ result finish(pkgAcquire::RunResult res,
+ OpProgress &progress)
+ {
+ if(res != pkgAcquire::Continue || failed)
+ {
+ _error->Error("Couldn't fetch URL %s", uri.c_str());
+
+ return failure;
+ }
+ else
+ {
+ k(tempname);
+
+ return success;
+ }
+ }
};
-pkg_changelog *get_changelog(pkgCache::VerIterator ver,
- pkgAcquireStatus *status,
- int PulseInterval)
+download_manager *get_changelog(pkgCache::VerIterator ver,
+ const sigc::slot1<void, temp::name> &k)
{
if(ver.end())
return NULL;
@@ -79,94 +184,22 @@
return NULL;
// Look up the source package.
- pkgRecords::Parser &rec=apt_package_records->Lookup(ver.FileList());
- string srcpkg=rec.SourcePkg().empty()?ver.ParentPkg().Name():rec.SourcePkg();
-
- return get_changelog_from_source(srcpkg, ver.VerStr(), ver.Section(),
- status,
- PulseInterval,
- ver.ParentPkg().Name());
+ pkgRecords::Parser &rec =
+ apt_package_records->Lookup(ver.FileList());
+ string srcpkg =
+ rec.SourcePkg().empty() ? ver.ParentPkg().Name() : rec.SourcePkg();
+
+ return get_changelog_from_source(srcpkg, ver.VerStr(),
+ ver.Section(),
+ ver.ParentPkg().Name(),
+ k);
}
-pkg_changelog *get_changelog_from_source(const string &srcpkg,
- const string &ver,
- const string §ion,
- pkgAcquireStatus *status,
- int PulseInterval,
- const string &name)
+download_manager *get_changelog_from_source(const string &srcpkg,
+ const string &ver,
+ const string §ion,
+ const string &name,
+ const sigc::slot1<void, temp::name> &k)
{
- temp::dir tempdir;
- temp::name tempname;
-
- try
- {
- tempdir = temp::dir("aptitude");
- tempname = temp::name(tempdir, "changelog");
- }
- catch(temp::TemporaryCreationFailure e)
- {
- _error->Error("%s", e.errmsg().c_str());
- return NULL;
- }
-
- char uribuf[1024];
-
- string realsection;
-
- if(section.find('/')!=section.npos)
- realsection.assign(section, 0, section.find('/'));
- else
- realsection.assign("main");
-
- string prefix;
-
- if(srcpkg.size()>3 && srcpkg[0]=='l' && srcpkg[1]=='i' && srcpkg[2]=='b')
- prefix = std::string("lib")+srcpkg[3];
- else
- prefix = srcpkg[0];
-
- string realver;
-
- if(ver.find(':')!=ver.npos)
- realver.assign(ver, ver.find(':')+1, ver.npos);
- else
- realver=ver;
-
- snprintf(uribuf,
- sizeof(uribuf),
- "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog",
- realsection.c_str(),
- prefix.c_str(),
- srcpkg.c_str(),
- srcpkg.c_str(),
- realver.c_str());
-
- pkgAcquire fetcher(status);
-
- char buf[512];
- snprintf(buf, 512, _("ChangeLog of %s"), name.c_str());
-
- bool failed=false;
- new AcqWithFail(&fetcher,
- uribuf,
- buf,
- buf,
- tempname.get_name().c_str(),
- failed);
-
- sigset_t signals,oldsigs;
- sigemptyset(&signals);
- sigaddset(&signals, SIGWINCH);
- sigprocmask(SIG_UNBLOCK, &signals, &oldsigs);
-
- if(fetcher.Run(PulseInterval) != pkgAcquire::Continue || failed)
- {
- _error->Error("Couldn't fetch URL %s", uribuf);
-
- sigprocmask(SIG_SETMASK, &oldsigs, &signals);
- return NULL;
- }
-
- sigprocmask(SIG_SETMASK, &oldsigs, &signals);
- return new pkg_changelog(tempname);
+ return new download_changelog_manager(srcpkg, ver, section, name, k);
}
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h Thu Sep 29 23:50:34 2005
@@ -26,44 +26,34 @@
#include <generic/util/temp.h>
-#include <apt-pkg/acquire.h>
#include <apt-pkg/pkgcache.h>
-class pkg_changelog
-{
- temp::name filename;
-
- pkg_changelog::pkg_changelog(const temp::name &_filename);
- friend pkg_changelog *get_changelog_from_source(const std::string &,
- const std::string &,
- const std::string &,
- pkgAcquireStatus *,
- int,
- const std::string &);
-public:
- std::string get_filename() { return filename.get_name(); }
-};
-
-pkg_changelog *get_changelog(pkgCache::VerIterator ver,
- pkgAcquireStatus *status,
- int PulseInterval);
+#include <sigc++/slot.h>
-/** Return a changelog object for the given source package.
+class download_manager;
+
+/** Generate a download process object that retrieves the given
+ * package version's changelog. When the download is complete, the
+ * given slot will be invoked with the file to which the changelog
+ * was downloaded as an argument.
+ */
+download_manager *get_changelog(pkgCache::VerIterator ver,
+ const sigc::slot1<void, temp::name> &k);
+
+/** Generate a download process object that retrieves a changelog for
+ * the given source package.
*
* \param srcpkg the source package name
* \param ver the version of the source package
- * \param status the object to which the download status should be reported
- * \param PulseInterval the interval at which to update the display
- * and poll for input
+ * \param section the section of the source package
* \param name the name of the package that the user provided
* (e.g., the binary package that the changelog command
* was executed on)
*/
-pkg_changelog *get_changelog_from_source(const std::string &srcpkg,
- const std::string &ver,
- const std::string §ion,
- pkgAcquireStatus *status,
- int PulseInterval,
- const std::string &name);
+download_manager *get_changelog_from_source(const std::string &srcpkg,
+ const std::string &ver,
+ const std::string §ion,
+ const std::string &name,
+ const sigc::slot1<void, temp::name> &k);
#endif
More information about the Aptitude-svn-commit
mailing list