- implement package filelist and changelog handling for package records
authorPanu Matilainen <pmatilai@laiskiainen.org>
Mon, 19 Feb 2007 17:46:29 +0000 (19:46 +0200)
committerPanu Matilainen <pmatilai@laiskiainen.org>
Mon, 19 Feb 2007 17:46:29 +0000 (19:46 +0200)
- add commands for accessing them to apt-cache and apt-shell

apt-pkg/pkgrecords.h
apt-pkg/rpm/rpmhandler.cc
apt-pkg/rpm/rpmhandler.h
apt-pkg/rpm/rpmrecords.cc
apt-pkg/rpm/rpmrecords.h
apt-pkg/rpm/rpmshowprogress.cc
apt-pkg/rpm/rpmshowprogress.h
cmdline/apt-cache.cc
cmdline/apt-shell.cc
cmdline/cmdline.cc
cmdline/cmdline.h

index 7591e24..206e096 100644 (file)
 
 #include <vector>
 
+struct ChangeLogEntry 
+{
+   time_t Time; 
+   string Author;
+   string Text;
+};
+
 class pkgRecords
 {
    public:
@@ -66,6 +73,10 @@ class pkgRecords::Parser
    virtual string ShortDesc() {return string();};
    virtual string LongDesc() {return string();};
    virtual string Name() {return string();};
+
+   // These are not supported by all repository types and can fail
+   virtual bool ChangeLog(std::vector<ChangeLogEntry *> &ChangeLogs) { return false;};
+   virtual bool FileList(std::vector<string> &Files) { return false;};
    
    // The record in binary form
    virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
@@ -77,3 +88,4 @@ class pkgRecords::Parser
 };
 
 #endif
+// vim:sts=3:sw=3
index d7172e8..e149b9e 100644 (file)
@@ -422,6 +422,33 @@ bool RPMHandler::FileList(vector<string> &FileList)
 }
 #endif
 
+bool RPMHandler::ChangeLog(vector<ChangeLogEntry *> &ChangeLogs)
+{
+   int *timel = NULL;
+   char **authorl = NULL;
+   char **entryl = NULL;
+   void *timeval, *authorval, *entryval;
+   int res, type, count;
+
+   res = headerGetEntry(HeaderP, RPMTAG_CHANGELOGTIME, &type, (void **)&timeval, &count);
+   res = headerGetEntry(HeaderP, RPMTAG_CHANGELOGNAME, &type, (void **)&authorval, &count);
+   res = headerGetEntry(HeaderP, RPMTAG_CHANGELOGTEXT, &type, (void **)&entryval, &count);
+
+   timel = (int*)timeval;
+   authorl = (char**)authorval;
+   entryl = (char**)entryval;
+
+   for (int i = 0; i < count; i++) {
+      ChangeLogEntry *Entry = new ChangeLogEntry;
+      Entry->Time = timel[i];
+      Entry->Author = authorl[i];
+      Entry->Text = entryl[i];
+      ChangeLogs.push_back(Entry);
+   }
+      
+   return true;
+}
+
 RPMFileHandler::RPMFileHandler(string File)
 {
    ID = File;
@@ -1345,10 +1372,16 @@ RPMSqliteHandler::RPMSqliteHandler(string File) :
    ID = File;
    DBPath = File; 
    // ugh, pass this in to the constructor or something..
-   FilesDBPath = File.substr(0, File.size() - 14) + "filelists.sqlite";
+   string DBBase = File.substr(0, File.size() - 14);
+   FilesDBPath = DBBase + "filelists.sqlite";
+   OtherDBPath = DBBase + "other.sqlite";
 
    Primary = new SqliteDB(DBPath);
+   // XXX open these only if needed? 
    Filelists = new SqliteDB(FilesDBPath);
+   if (FileExists(OtherDBPath)) {
+      Other = new SqliteDB(OtherDBPath);
+   }
 
    Packages = Primary->Query();
 
@@ -1366,6 +1399,7 @@ RPMSqliteHandler::~RPMSqliteHandler()
 {
    if (Primary) delete Primary;
    if (Filelists) delete Filelists;
+   if (Other) delete Other;
 }
 
 
@@ -1572,6 +1606,27 @@ bool RPMSqliteHandler::FileList(vector<string> &FileList)
    return true;
 }
 
+bool RPMSqliteHandler::ChangeLog(vector<ChangeLogEntry* > &ChangeLogs)
+{
+   ostringstream sql;
+   unsigned long pkgKey = Packages->GetColI("pkgKey");
+   sql  << "select * from changelog where pkgKey=" << pkgKey << endl;
+   SqliteQuery *Changes = Other->Query();
+   if (!Changes->Exec(sql.str())) {
+      return false;
+   }
+
+   while (Changes->Step()) {
+      ChangeLogEntry *Entry = new ChangeLogEntry;
+      Entry->Time = Changes->GetColI("date");
+      Entry->Author = Changes->GetCol("author");
+      Entry->Text = Changes->GetCol("changelog");
+      ChangeLogs.push_back(Entry);
+   }
+   return true;
+}
+
+
 #endif /* APT_WITH_REPOMD */
 
 
index 41553b4..ee574a2 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <apt-pkg/aptconf.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/pkgrecords.h>
 
 #ifdef APT_WITH_REPOMD
 #include <libxml/parser.h>
@@ -104,6 +105,7 @@ class RPMHandler
 
    virtual bool PRCO(unsigned int Type, vector<Dependency*> &Deps);
    virtual bool FileList(vector<string> &FileList);
+   virtual bool ChangeLog(vector<ChangeLogEntry* > &ChangeLogs);
 
    virtual bool HasFile(const char *File);
 
@@ -317,6 +319,7 @@ class RPMSqliteHandler : public RPMHandler
 
    SqliteDB *Primary;
    SqliteDB *Filelists;
+   SqliteDB *Other;
    
    SqliteQuery *Packages;
   
@@ -353,6 +356,7 @@ class RPMSqliteHandler : public RPMHandler
 
    virtual bool PRCO(unsigned int Type, vector<Dependency*> &Deps);
    virtual bool FileList(vector<string> &FileList);
+   virtual bool ChangeLog(vector<ChangeLogEntry* > &ChangeLogs);
 
    RPMSqliteHandler(string File);
    virtual ~RPMSqliteHandler();
index 2c26a9b..d00790c 100644 (file)
@@ -352,6 +352,15 @@ void rpmRecordParser::GetRec(const char *&Start,const char *&Stop)
    Stop = Buffer + BufUsed;
 }
                                                                        /*}}}*/
+bool rpmRecordParser::FileList(vector<string> &Files)
+{
+   return Handler->FileList(Files);
+}
+
+bool rpmRecordParser::ChangeLog(vector<ChangeLogEntry *> &ChangeLogs)
+{
+   return Handler->ChangeLog(ChangeLogs);
+}
 
 bool rpmRecordParser::HasFile(const char *File)
 {
index 4f4df01..89661e5 100644 (file)
@@ -57,6 +57,10 @@ class rpmRecordParser : public pkgRecords::Parser
    virtual string ShortDesc();
    virtual string LongDesc();
    virtual string Name();
+
+   virtual bool ChangeLog(vector<ChangeLogEntry *> &ChangeLogs);
+   virtual bool FileList(vector<string> &Files);
+
    
    // The record in raw text, in standard Debian format
    virtual void GetRec(const char *&Start,const char *&Stop);
index 7240a87..d3d61eb 100644 (file)
@@ -61,9 +61,15 @@ void * rpmpmShowProgress(const Header h,
 void * rpmpmShowProgress(const void * arg, 
 #endif
                        const rpmCallbackType what,
+#if RPM_VERSION >= 0x040405
+                       const unsigned long long amount,
+                       const unsigned long long total,
+#else
                        const unsigned long amount,
                        const unsigned long total,
+#endif
                        const void * pkgKey, void * data)
+
 {
 #if RPM_VERSION >= 0x040000
     Header h = (Header) arg;
index 3cf6526..9c33f96 100644 (file)
@@ -7,6 +7,11 @@ void * rpmpmShowProgress(const Header h,
 void * rpmpmShowProgress(const void * arg, 
 #endif
                        const rpmCallbackType what,
-                       const unsigned long amount,
-                       const unsigned long total,
+#if RPM_VERSION >= 0x040405
+                        const unsigned long long amount,
+                        const unsigned long long total,
+#else
+                        const unsigned long amount,
+                        const unsigned long total,
+#endif
                        const void * pkgKey, void * data);
index 0401010..c341dc8 100644 (file)
@@ -916,7 +916,17 @@ bool ShowPackage(CommandLine &CmdL)
 {   
    return cmdShowPackage(CmdL, *GCache);
 }
+
+bool FileList(CommandLine &CmdL)
+{
+   return cmdFileList(CmdL, *GCache);
+}
                                                                        /*}}}*/
+bool ChangeLog(CommandLine &CmdL)
+{
+   return cmdChangeLog(CmdL, *GCache);
+}
+
 // ShowPkgNames - Show package names                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* This does a prefix match on the first argument */
@@ -1110,6 +1120,7 @@ bool GenCaches(CommandLine &Cmd)
       return false;   
    return pkgMakeStatusCache(List,Progress);
 }
+
                                                                        /*}}}*/
 // ShowHelp - Show a help screen                                       /*{{{*/
 // ---------------------------------------------------------------------
@@ -1142,6 +1153,8 @@ bool ShowHelp(CommandLine &Cmd)
       "   unmet - Show unmet dependencies\n"
       "   search - Search the package list for a regex pattern\n"
       "   searchfile - Search the packages for a file\n"
+      "   files - Show file list of the package(s)\n"
+      "   changelog - Show changelog entries of the package(s)\n"
       "   show - Show a readable record for the package\n"
       "   depends - Show raw dependency information for a package\n"
       "   whatdepends - Show packages depending on given capabilities\n"
@@ -1215,6 +1228,8 @@ int main(int argc,const char *argv[])
                                     {"whatdepends",&WhatDepends},
                                     {"rdepends",&RDepends},
                                     {"whatprovides",&WhatProvides},
+                                    {"files",&FileList},
+                                    {"changelog",&ChangeLog},
                                     {"dotty",&Dotty},
                                     {"xvcg",&XVcg},
                                     {"show",&ShowPackage},
index aedd7ca..dfcdb2d 100644 (file)
@@ -1908,6 +1908,22 @@ bool SearchFile(CommandLine &CmdL)
    return cmdSearchFile(CmdL, *GCache);
 }
 
+bool FileList(CommandLine &CmdL)
+{
+   if (CheckHelp(CmdL) == true)
+      return true;
+
+   return cmdFileList(CmdL, *GCache);
+}
+
+bool ChangeLog(CommandLine &CmdL)
+{
+   if (CheckHelp(CmdL) == true)
+      return true;
+
+   return cmdChangeLog(CmdL, *GCache);
+}
+
 // DoList - List packages.                                             /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1918,6 +1934,7 @@ bool DoList(CommandLine &CmdL)
 
    return cmdDoList(CmdL, *GCache);
 }
+
                                                                        /*}}}*/
 // ShowPackage - Dump the package record to the screen                 /*{{{*/
 // ---------------------------------------------------------------------
@@ -2011,6 +2028,8 @@ bool ShowHelp(CommandLine &CmdL)
       "   list/ls - List packages\n"
       "   search - Search the package list for a regex pattern\n"
       "   searchfile - Search the packages for a file\n"
+      "   files - Show file list of the package(s)\n"
+      "   changelog - Show changelog entries of the package(s)\n"
       "   script - Run scripts.\n"
       "   depends - Show raw dependency information for a package\n"
       "   whatdepends - Show packages depending on given capabilities\n"
@@ -2303,7 +2322,7 @@ char *ReadLineCompCommands(const char *Text, int State)
         "keep", "dist-upgrade", "dselect-upgrade", "build-dep", "clean",
         "autoclean", "check", "help", "commit", "exit", "quit", "status",
         "showpkg", "unmet", "search", "depends", "whatdepends", "rdepends",
-        "show", "script", 0};
+        "show", "script", "searchfile", "files", "changelog", 0};
    static int Last;
    static size_t Len;
    if (State == 0) {
@@ -2602,6 +2621,8 @@ int main(int argc,const char *argv[])
                                    {"unmet",&UnMet},
                                    {"search",&Search},
                                    {"search",&SearchFile},
+                                   {"files",&FileList},
+                                   {"changelog",&ChangeLog},
                                    {"list",&DoList},
                                    {"ls",&DoList},
                                    {"depends",&Depends},
index 2723025..260f512 100644 (file)
@@ -1868,4 +1868,65 @@ bool cmdSearchFile(CommandLine &CmdL, pkgCache &Cache)
    return true;
 }
 
+bool cmdFileList(CommandLine &CmdL, pkgCache &Cache)
+{
+   pkgDepCache::Policy Plcy;
+
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   {
+      pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
+      if (Pkg.end() == true)
+      {
+         _error->Warning(_("Unable to locate package %s"),*I);
+         continue;
+      }
+
+      pkgCache::VerIterator Ver = Plcy.GetCandidateVer(Pkg);
+      pkgRecords Recs(Cache);
+      if (Ver.end() == false) {
+         pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
+         vector<string> Files;
+         Parse.FileList(Files);
+         for (vector<string>::iterator F = Files.begin(); F != Files.end(); F++) {
+            cout << (*F) << endl;
+         }
+      }
+   }
+
+   return true;
+}
+
+bool cmdChangeLog(CommandLine &CmdL, pkgCache &Cache)
+{
+   pkgDepCache::Policy Plcy;
+
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   {
+      pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
+      if (Pkg.end() == true)
+      {
+         _error->Warning(_("Unable to locate package %s"),*I);
+         continue;
+      }
+
+      pkgCache::VerIterator Ver = Plcy.GetCandidateVer(Pkg);
+      pkgRecords Recs(Cache);
+      if (Ver.end() == false) {
+         pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
+         vector<ChangeLogEntry *> ChangeLog;
+         Parse.ChangeLog(ChangeLog);
+        cout << Pkg.Name() << "-" << Ver.VerStr() << ":" << endl;
+        tm *ptm;
+        char buf[512];
+         for (vector<ChangeLogEntry *>::iterator F = ChangeLog.begin(); F != ChangeLog.end(); F++) {
+           ptm = localtime(&(*F)->Time);
+           strftime(buf, sizeof(buf), "%a %b %d %Y", ptm);
+            cout << "* " << buf << " " << (*F)->Author << endl;
+           cout << (*F)->Text << endl << endl;
+         }
+      }
+   }
+
+   return true;
+}
 // vim:sts=3:sw=3
index cf0bc5b..a7e2d3c 100644 (file)
@@ -85,6 +85,8 @@ bool cmdShowPackage(CommandLine &CmdL, pkgCache &Cache);
 
 bool cmdSearch(CommandLine &CmdL, pkgCache &Cache);
 bool cmdSearchFile(CommandLine &CmdL, pkgCache &Cache);
+bool cmdFileList(CommandLine &CmdL, pkgCache &Cache);
+bool cmdChangeLog(CommandLine &CmdL, pkgCache &Cache);
 
 
 // vim:sts=3:sw=3