diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-11-15 12:12:56 +0100 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-11-15 12:12:56 +0100 |
commit | a4c404301df135bea81f23b944dc6e1967f9ca85 (patch) | |
tree | e4e9beea56855f6f10e30bb3a269aacbc0e9848d /cmdline/apt-get.cc | |
parent | fd8bb61d2945d2e2f19f0e0a753129235717a9f3 (diff) |
initial apt-get changelog implementation, not quite ready yet (need to get rid of tmpnam
Diffstat (limited to 'cmdline/apt-get.cc')
-rw-r--r-- | cmdline/apt-get.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 8efcd0e2e..72c1ef0b0 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2733,6 +2733,104 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ +// DownloadChangelog - Download the changelog /*{{{*/ +// --------------------------------------------------------------------- +string DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V) +{ + string uri; + string srcpkg; + string prefix; + string descr; + string src_section; + string verstr; + + // data structures we need + pkgRecords Recs(CacheFile); + pkgCache::PkgIterator Pkg = V.ParentPkg(); + pkgRecords::Parser &rec=Recs.Lookup(V.FileList()); + + // build uri + srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); + strprintf(descr, _("Changelog for %s"), srcpkg.c_str()); + // FIXME: we actually need the source section here + src_section= Pkg.Section(); + if(src_section.find('/')!=src_section.npos) + src_section=string(src_section, 0, src_section.find('/')); + else + src_section="main"; + + prefix+=srcpkg[0]; + if(srcpkg.size()>3 && srcpkg[0]=='l' && srcpkg[1]=='i' && srcpkg[2]=='b') + prefix=std::string("lib")+srcpkg[3]; + + verstr = V.VerStr(); + if(verstr.find(':')!=verstr.npos) + verstr=string(verstr, verstr.find(':')+1); + + strprintf(uri, "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); + + AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); + Fetcher.Setup(&Stat); + + // temp file + string targetfile = tmpnam(strdup("apt-changelog-XXXXXX")); + new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignore", targetfile); + + // get it + int res = Fetcher.Run(); + if (FileExists(targetfile)) + return targetfile; + + // error + return ""; +} + /*}}}*/ +// DisplayFileInPager - Display File with pager /*{{{*/ +void DisplayFileInPager(string filename) +{ + pid_t Process = ExecFork(); + if (Process == 0) + { + const char *Args[3]; + Args[0] = "/usr/bin/sensible-pager"; + Args[1] = filename.c_str(); + Args[2] = 0; + execvp(Args[0],(char **)Args); + exit(100); + } + + // Wait for the subprocess + ExecWait(Process, "sensible-pager", false); +} + /*}}}*/ +// DoChangelog - Get changelog from the command line /*{{{*/ +// --------------------------------------------------------------------- +bool DoChangelog(CommandLine &CmdL) +{ + CacheFile Cache; + if (Cache.ReadOnlyOpen() == false) + return false; + + APT::CacheSetHelper helper(c0out); + APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, + CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + pkgAcquire Fetcher; + + if (verset.empty() == true) + return false; + for (APT::VersionSet::const_iterator Ver = verset.begin(); + Ver != verset.end(); + ++Ver) + { + string changelogfile = DownloadChangelog(Cache, Fetcher, Ver); + if (changelogfile.size() > 0) + { + DisplayFileInPager(changelogfile); + unlink(changelogfile.c_str()); + } + } +} + /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -2923,6 +3021,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {"autoclean",&DoAutoClean}, {"check",&DoCheck}, {"source",&DoSource}, + {"changelog",&DoChangelog}, {"moo",&DoMoo}, {"help",&ShowHelp}, {0,0}}; |