[Python-checkins] r63888 - in python/trunk: Doc/library/msilib.rst Misc/NEWS PC/_msi.c

martin.v.loewis python-checkins at python.org
Tue Jun 3 20:57:06 CEST 2008


Author: martin.v.loewis
Date: Mon Jun  2 10:40:06 2008
New Revision: 63888

Log:
Patch #2125: Add GetInteger and GetString methods for 
msilib.Record objects.

Modified:
   python/trunk/Doc/library/msilib.rst
   python/trunk/Misc/NEWS
   python/trunk/PC/_msi.c

Modified: python/trunk/Doc/library/msilib.rst
==============================================================================
--- python/trunk/Doc/library/msilib.rst	(original)
+++ python/trunk/Doc/library/msilib.rst	Mon Jun  2 10:40:06 2008
@@ -264,6 +264,18 @@
    :cfunc:`MsiRecordGetFieldCount`.
 
 
+.. method:: Record.GetInteger(field)
+
+   Return the value of *field* as an integer where possible.  *field* must
+   be an integer.
+
+
+.. method:: Record.GetString(field)
+
+   Return the value of *field* as a string where possible.  *field* must
+   be an integer.
+
+
 .. method:: Record.SetString(field, value)
 
    Set *field* to *value* through :cfunc:`MsiRecordSetString`. *field* must be an
@@ -543,3 +555,4 @@
    This module contains definitions for the UIText and ActionText tables, for the
    standard installer actions.
 
+

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Jun  2 10:40:06 2008
@@ -72,6 +72,9 @@
 Library
 -------
 
+- Patch #2125: Add GetInteger and GetString methods for 
+  msilib.Record objects.
+
 - Issue #2782: The datetime module's strftime methods now accept
   unicode format strings just as time.strftime always has.
 

Modified: python/trunk/PC/_msi.c
==============================================================================
--- python/trunk/PC/_msi.c	(original)
+++ python/trunk/PC/_msi.c	Mon Jun  2 10:40:06 2008
@@ -339,6 +339,49 @@
 }
 
 static PyObject*
+record_getinteger(msiobj* record, PyObject* args)
+{
+    unsigned int field;
+    int status;
+    
+    if (!PyArg_ParseTuple(args, "I:GetInteger", &field))
+        return NULL;
+    status = MsiRecordGetInteger(record->h, field);
+    if (status == MSI_NULL_INTEGER){
+        PyErr_SetString(MSIError, "could not convert record field to integer");
+        return NULL;
+    }
+    return PyInt_FromLong((long) status);
+}
+
+static PyObject*
+record_getstring(msiobj* record, PyObject* args)
+{
+    unsigned int field;
+    unsigned int status;
+    char buf[2000];
+    char *res = buf;
+    DWORD size = sizeof(buf);
+    PyObject* string;
+    
+    if (!PyArg_ParseTuple(args, "I:GetString", &field))
+        return NULL;
+    status = MsiRecordGetString(record->h, field, res, &size);
+    if (status == ERROR_MORE_DATA) {
+        res = (char*) malloc(size + 1);
+        if (res == NULL)
+            return PyErr_NoMemory();
+        status = MsiRecordGetString(record->h, field, res, &size);
+    }
+    if (status != ERROR_SUCCESS)
+        return msierror((int) status);
+    string = PyString_FromString(res);
+    if (buf != res)
+        free(res);
+    return string;
+}
+
+static PyObject*
 record_cleardata(msiobj* record, PyObject *args)
 {
     int status = MsiRecordClearData(record->h);
@@ -405,6 +448,10 @@
 static PyMethodDef record_methods[] = {
     { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, 
 	PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
+    { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS,
+    PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")},
+    { "GetString", (PyCFunction)record_getstring, METH_VARARGS,
+    PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")},
     { "SetString", (PyCFunction)record_setstring, METH_VARARGS, 
 	PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
     { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, 


More information about the Python-checkins mailing list