Teach python rpmio bindings about Fdescr()
authorPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Thu, 7 Jul 2011 13:27:03 +0000 (16:27 +0300)
committerPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Thu, 7 Jul 2011 13:31:46 +0000 (16:31 +0300)
- Similarly to python file object having o.name, export Fdescr()
  as fd.name. Python uses <foo> for non-paths but [foo] seems like
  a safer choice wrt accidental redirections.
- Also add a basic testcase for fd.name

python/rpmfd-py.c
tests/rpmpython.at

index df9b641..89a70cd 100644 (file)
@@ -296,8 +296,15 @@ static PyObject *rpmfd_get_closed(rpmfdObject *s)
     return PyBool_FromLong((s->fd == NULL));
 }
 
+static PyObject *rpmfd_get_name(rpmfdObject *s)
+{
+    /* XXX: rpm returns non-paths with [mumble], python files use <mumble> */
+    return Py_BuildValue("s", Fdescr(s->fd));
+}
+
 static PyGetSetDef rpmfd_getseters[] = {
     { "closed", (getter)rpmfd_get_closed, NULL, NULL },
+    { "name", (getter)rpmfd_get_name, NULL, NULL },
     { NULL },
 };
 
index fe2faca..6275502 100644 (file)
@@ -41,6 +41,8 @@ for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]:
     fd = rpm.fd(fn, 'w', iot)
     if fd.write(data) != len(data):
         myprint('%s write fail' % iot)
+    if fn != fd.name:
+        myprint('bad file name %s' % fd.name)
     fd = rpm.fd(fn, 'r', iot)
     rdata = fd.read()
     if rdata != data:
@@ -50,6 +52,8 @@ for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]:
         fd.seek(0)
     else:
         fd = rpm.fd(fn, 'r', iot)
+    if fn != fd.name:
+        myprint('bad file name %s' % fd.name)
     rdata = fd.read(len(msg))
     if rdata != msg:
         myprint('%s sized read fail (got %d bytes)\n%s' % (iot, len(rdata), rdata))