[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Patch] Function for getting the value of an arbitrary control field



Hello,

I was wondering if there was any interest for a patch to allow an application to get the value of an arbitrary debian/control field via a pkgRecords::Parser object. The usecase would be for obtaining the values of nonstandard fields such as the "Supported" field of Ubuntu packages in main, or any of the several metadata fields that the GStreamer packages have. ("Gstreamer-Decoders", "Gstreamer-Elements", etc)

In the Package class for my Qt APT library, LibQApt, I'm currently using something like the following to get the value of arbitrary control fields:

    pkgRecords::Parser &rec = d->records->Lookup(ver.FileList());
    const char *start, *stop;
    rec.GetRec(start, stop);
    QString record(start);

    QStringList lines = record.split('\n');

    Q_FOREACH (const QString &line, lines) {
        if (line.startsWith(name)) {
            field = line.split(": ").at(1);
            break;
        }
    }

I could replace this all with one call to the new function I have added in the patch, making things much more convenient. (I have attached the patch to this email)

Please CC me in replies, since I am not subscribed to this list.

Thanks,
Jonathan Thomas
--- apt-0.8.10ubuntu1/apt-pkg/deb/debrecords.cc 2010-08-02 05:49:53.000000000 -0400
+++ apt-0.8.10ubuntu2/apt-pkg/deb/debrecords.cc 2011-01-05 19:50:01.000000000 -0500
@@ -92,6 +92,15 @@
 {
    return Section.FindS("Maintainer");
 }
+
+// RecordParser::RecordField - Return the value of an arbitrary field       /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string debRecordParser::RecordField(const char *fieldName)
+{
+   return Section.FindS(fieldName);
+}
+
                                                                        /*}}}*/
 // RecordParser::ShortDesc - Return a 1 line description               /*{{{*/
 // ---------------------------------------------------------------------
diff -Nru apt-0.8.10ubuntu1/apt-pkg/deb/debrecords.h apt-0.8.10ubuntu2/apt-pkg/deb/debrecords.h
--- apt-0.8.10ubuntu1/apt-pkg/deb/debrecords.h  2010-08-02 05:49:53.000000000 -0400
+++ apt-0.8.10ubuntu2/apt-pkg/deb/debrecords.h  2011-01-05 19:52:42.000000000 -0500
@@ -46,6 +46,9 @@
    virtual string Name();
    virtual string Homepage();

+   // An arbitrary custom field
+   virtual string RecordField(const char *fieldName);
+
    virtual void GetRec(const char *&Start,const char *&Stop);

    debRecordParser(string FileName,pkgCache &Cache);
diff -Nru apt-0.8.10ubuntu1/apt-pkg/pkgrecords.h apt-0.8.10ubuntu2/apt-pkg/pkgrecords.h
--- apt-0.8.10ubuntu1/apt-pkg/pkgrecords.h      2010-08-02 05:49:53.000000000 -0400
+++ apt-0.8.10ubuntu2/apt-pkg/pkgrecords.h      2011-01-05 19:48:32.000000000 -0500
@@ -67,7 +67,10 @@
    virtual string LongDesc() {return string();};
    virtual string Name() {return string();};
    virtual string Homepage() {return string();}
-
+
+   // An arbitrary custom field
+   virtual string RecordField(const char *fieldName) { return string();};
+
    // The record in binary form
    virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};

Reply to: