[Rpm-maint] PATCH: Accessing file and policy lists from python (and C)

Alec Leamas leamas.alec at gmail.com
Sun Sep 16 05:19:53 UTC 2012


OK, I'm not allowed to create a ticket and not allowed to send a patch 
attachment. Pasting  patch inline:

--------------------------------------------------------------------------------

Add the three attributes fileFile, fileList and policyList
to specPackage. Also updates docstring.

diff --git a/build/rpmspec.h b/build/rpmspec.h
index 195fc72..a18b813 100644
--- a/build/rpmspec.h
+++ b/build/rpmspec.h
@@ -54,6 +54,9 @@ rpmSpecPkgIter rpmSpecPkgIterFree(rpmSpecPkgIter iter);

  /* Getters for spec package attributes */
  Header rpmSpecPkgHeader(rpmSpecPkg pkg);
+ARGV_const_t rpmSpecPkgFileFile(rpmSpecPkg pkg);
+ARGV_const_t rpmSpecPkgFileList(rpmSpecPkg pkg);
+ARGV_const_t rpmSpecPkgPolicyList(rpmSpecPkg pkg);

  /* Iterator for spec sources */
  rpmSpecSrcIter rpmSpecSrcIterInit(rpmSpec spec);
diff --git a/build/spec.c b/build/spec.c
index d82f725..b218159 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -349,6 +349,21 @@ Header rpmSpecPkgHeader(rpmSpecPkg pkg)
      return (pkg != NULL) ? pkg->header : NULL;
  }

+ARGV_const_t rpmSpecPkgFileFile(rpmSpecPkg pkg)
+{
+    return (pkg != NULL) ? pkg->fileFile : NULL;
+}
+
+ARGV_const_t rpmSpecPkgFileList(rpmSpecPkg pkg)
+{
+    return (pkg != NULL) ? pkg->fileList : NULL;
+}
+
+ARGV_const_t rpmSpecPkgPolicyList(rpmSpecPkg pkg)
+{
+    return (pkg != NULL) ? pkg->policyList : NULL;
+}
+
  rpmSpecSrcIter rpmSpecSrcIterInit(rpmSpec spec)
  {
      SPEC_LISTITER_INIT(rpmSpecSrcIter, sources);
diff --git a/python/spec-py.c b/python/spec-py.c
index 284f52b..bc28c65 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -47,16 +47,51 @@ struct specPkgObject_s {
      rpmSpecPkg pkg;
  };

+static PyObject *argv2list(ARGV_const_t argv)
+{
+    int size;
+    const char **s;
+    PyObject *py_list;
+    int ix;
+
+    if (argv == NULL)
+         return PyList_New(0);
+
+    size = argvCount(argv);
+    py_list = PyList_New(size);
+    for (ix = 0, s = argvData((ARGV_t)argv); ix < size; ix++, s++)
+        PyList_SetItem(py_list, ix, PyString_FromString(*s));
+    return py_list;
+}
+
  static char specPkg_doc[] =
-"";
+    "Package data parsed from spec file.";

  static PyObject * specpkg_get_header(specPkgObject *s, void *closure)
  {
      return makeHeader(rpmSpecPkgHeader(s->pkg));
  }

+static PyObject * specpkg_get_fileFile(specPkgObject *s, void *closure)
+{
+    return  argv2list(rpmSpecPkgFileFile(s->pkg));
+}
+
+static PyObject * specpkg_get_fileList(specPkgObject *s, void *closure)
+{
+    return  argv2list(rpmSpecPkgFileList(s->pkg));
+}
+
+static PyObject * specpkg_get_policyList(specPkgObject *s, void *closure)
+{
+    return  argv2list(rpmSpecPkgPolicyList(s->pkg));
+}
+
  static PyGetSetDef specpkg_getseters[] = {
-    { "header",    (getter) specpkg_get_header, NULL, NULL },
+    { "header",     (getter) specpkg_get_header,     NULL, NULL },
+    { "fileFile",   (getter) specpkg_get_fileFile,   NULL, NULL },
+    { "fileList",   (getter) specpkg_get_fileList,   NULL, NULL },
+    { "policyList", (getter) specpkg_get_policyList, NULL, NULL },
      { NULL }     /* sentinel */
  };

diff --git a/python/spec-py.h b/python/spec-py.h
index 558fbf2..a1ad78a 100644
--- a/python/spec-py.h
+++ b/python/spec-py.h
@@ -14,5 +14,6 @@ extern PyTypeObject specPkg_Type;

  PyObject * spec_Wrap(PyTypeObject *subtype, rpmSpec spec);
  PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg);
+static PyObject *argv2list(ARGV_const_t argv);

  #endif /* RPMPYTHON_SPEC */


More information about the Rpm-maint mailing list