summaryrefslogtreecommitdiff
path: root/python
AgeCommit message (Collapse)AuthorFilesLines
2012-05-16Explicitly differentate internal/exported file attributesPanu Matilainen1-2/+0
- RPMFILE_EXCLUDE only exists during spec parse, and doesn't "leak" into headers only because the file is, well, excluded to start with. Unexport the internal-only bit and explicitly strip out any excess bits from data going to header. The current 16/16 split is artificial of course, RPMTAG_FILEATTRS is 32bit so there's plenty of room for growing new file attributes, with internal-only adjustments required. - Eliminate RPMFILE_UNPATCHED while at it, this is a leftover from Suse patch rpms which are no longer used anywhere.
2012-03-08Optimize python db index instances list generation and fix related leakPanu Matilainen1-2/+2
- The number of entries is well know, allocate the entire list at once and set instead of appending one by one. Also cures a leak from created tuples not being decref'ed before - list set steals the reference whereas append requires an additional decref to transfer the ownership to the list.
2012-03-08Optimize header data python conversion for array tags a bitPanu Matilainen1-4/+4
- We know the array size beforehand, allocate the entire array at once and set the elements instead of appending one by one. This is (an obvious) and well-measurable, if not a huge, win.
2012-02-21Raise exception in python on headerGet() invalid data failurePanu Matilainen1-2/+6
2012-01-28Don't assume rpmfiNew() always succeedsPanu Matilainen1-0/+5
- Add NULL checks and add/adjust comments where appropriate. - The remaining callers should handle NULL fi gracefully if not entirely correctly: rpmfiFC() returns 0 on NULL fi, so these callers just see the erronous file info set as "no files" case. Something to fine-tune later...
2012-01-10Transaction element parent is a transaction element, not an integerPanu Matilainen1-1/+5
- Ehm, this has been broken in the python bindings since the start, nobody noticed. Of course the parent value isn't particularly useful in normal usage but still...
2012-01-10Minor cleanup to rpmte_Key()Panu Matilainen1-5/+3
- Fix misleading indentation, initialize Key on declaration. No functional changes.
2012-01-05Add enum for RPMCALLBACK_INST_STOP callback eventPanu Matilainen1-0/+1
- Unused atm but we'll be adding this shortly
2012-01-03Implement scriptlet start and stop callbacks (RhBug:606239)Panu Matilainen1-0/+2
- Adds two new transaction callbacks: RPMCALLBACK_SCRIPT_START and RPMCALLBACK_SCRIPT_STOP which get issued for every scriptlet we run. - On script start, callback can optionally return an FD which will override transaction-wide script fd to make it easier to accurately collect per-scriptlet output (eg per-scriptlet temporary file). Callback is also responsible for closing the fd if it returns one. - For both callbacks, "amount" holds the script tag number. On stop callback, "total" holds the scriptlet exit status mapped into OK/NOTFOUND/FAIL for success/non-fatal/fatal errors. Abusing "notfound" for warning result is ugly but differentiating it from the other cases allows callers to ignore SCRIPT_ERROR if they choose to implement stop and start.
2012-01-02fix the signatures of the METH_NOARGS callbacksDavid Malcolm3-40/+40
Various Python method callbacks have signatures of the form: static PyObject * foo(some_object_subclass *obj) and are registered within the PyMethodDef tables with the METH_NOARGS flag [1], with a cast to (PyCFunction) due to the PyObject/subclass mismatch. However, such callbacks do receive two arguments: they are invoked with a signature of this form: static PyObject * foo(some_object_subclass *obj, PyObject *ignored) The CPython interpreter only uses METH_NOARGS to allow it to pass NULL as the second parameter: there are still two parameters. The dispatch code is in Python's Python/ceval.c:call_function: if (flags & METH_NOARGS && na == 0) { C_TRACE(x, (*meth)(self,NULL)); } The fact that this has ever worked may be a coincidence of the platform/compiler's calling conventions, and I don't think it's guaranteed to keep working. [1] http://docs.python.org/c-api/structures.html#METH_NOARGS Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2012-01-02fix use-after-free within rpmfdFromPyObject's error-handlingDavid Malcolm1-1/+1
These lines within python/rpmfd-py.c: rpmfdFromPyObject are the wrong way around: Py_DECREF(fdo); PyErr_SetString(PyExc_IOError, Fstrerror(fdo->fd)); If fdo was allocated by the call above to PyObject_CallFunctionObjArgs, it may have an ob_refcnt == 1, and thus the Py_DECREF() frees it, so fdo->fd is reading from deallocated memory. Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2011-12-22mark strings extracted from PyArg_Parse* as "const"David Malcolm6-11/+11
- Various places within the bindings use PyArg_ParseTuple[AndKeywords] to extract (char*) string arguments. These are pointers to the internal representation of a PyStringObject, and shouldn't be modified, hence it's safest to explicitly mark these values as (const char*), rather than just (char*). Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2011-12-21typo in header-py.c.Ales Kozumplik1-1/+1
2011-12-21handle errors when constructing lists in the Python bindingsDavid Malcolm4-7/+58
- Various functions in the Python bindings construct lists of objects, but assume that all calls succeed. Each of these could segfault under low-memory conditions: if the PyList_New() call fails, PyList_Append(NULL, item ) will segfault. Similarly, although Py_List_Append(list, NULL) is safe, Py_DECREF(NULL) will segfault. Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2011-12-21fix memory leaks in invocations of PyObject_CallDavid Malcolm2-8/+7
- Various functions in the Python bindings have expressions of the form: PyObject_Call(callable, Py_BuildValue(fmtstring, ...), NULL); This leaks memory for the case when Py_BuildValue succeeds (it returns a new reference, which is never freed; PyObject_Call doesn't steal the reference): the argument tuple and all of its components will not be freed (until the process exits). Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2011-11-30Update internal callers to use headerExport(), no functional changesPanu Matilainen1-3/+2
2011-11-18inverse the macro definition condition in c87ad03.Ales Kozumplik1-1/+1
- thanks zpavlas for pointing this out.
2011-11-18python: use the more modern PyCapsule over PyCObject (RhBug:623864).Ales Kozumplik3-3/+13
- rpm.header.new() will still keep accepting PyCObject for now in case a client library depends on this. - involves macro trickery to make rpm buildable against python 2.6 still.
2011-10-11build: Update .gitignore rulesMukund Sivaraman1-0/+1
2011-09-01Oops, RPMSENSE_PRETRANS and _POSTTRANS missing from python bindingsPanu Matilainen1-0/+2
2011-09-01Oops, missing include for rpmFreeMacros() in python modulePanu Matilainen1-0/+1
- This should've been in commit f07ab5c1afa9b0b7105082a8617ec6a7657fc27e
2011-09-01Avoid SystemError on inserting an empty list insert to header from pythonPanu Matilainen1-0/+2
2011-09-01Add method to reset + reload rpm configuration to python bindingsPanu Matilainen1-0/+18
2011-08-29Add a new pseudo index for actually installed filesPanu Matilainen1-0/+1
- RPMDBI_BASENAMES (ugh) returns all headers with matching filenames, whether the files are actually installed or not, which can be rather misleading when dealing with file dependencies. The new RPMDBI_INSTFILENAMES only returns headers with matching filenames whose state indicates they are actually present on the system.
2011-08-25Export rpmtsEmpty() to python as ts.clear()Panu Matilainen1-0/+11
- Why the heck hasn't this been exported before, duh? - Method name clear() chosen as this appears to be emerging as a standard of sorts for this kind of operation: dictionaries and sets have it and list will get it in some python 3.x version. Additionally foo.empty() could easily be mistaken for "test whether container foo is empty or not" (especially those with c++ background...)
2011-07-07Take advantage of Fdescr() in rpmReadPackageFile()Panu Matilainen1-1/+1
- If fn to rpmReadPackageFile() is NULL, use Fdescr() value to give more meaningful errors - Change a couple of places where we haven't got a clue of the file name to take advantage of the above
2011-07-07Teach python rpmio bindings about Fdescr()Panu Matilainen1-0/+7
- 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
2011-07-06Fix the broken python header __getattr__() behavior, take 13 (or so)Panu Matilainen1-1/+9
- Tags as header attributes seemed like a nice idea at the time... but has been a PITA due to side-effects it causes, such as breaking getattr() use for "capability testing", eg: >>> h2 = copy.deepcopy(h) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.7/copy.py", line 172, in deepcopy copier = getattr(x, "__deepcopy__", None) ValueError: unknown header tag - Since we can't really go removing the brainded feature (somebody might actually be using it) try harder to fix it: if its not an actual attribute, save the exception we got from PyObject_GenericGetAttr() and if its not a valid tag either, restore the original exception. This allows cases like the above __deepcopy__ to work properly.
2011-07-06Add __reduce__() method to python header objectPanu Matilainen1-15/+32
- This allows header objects to be pickled and also copied correctly with python's copy.copy() - Split the header to string-conversion into a separate helper function, used by the now largely unnecessary unload() method and __reduce__().
2011-07-06Revert the ds, ts, fi and spec python object creation commitsPanu Matilainen6-47/+77
- Hasty push-finger syndrom, while its not exactly plain wrong to do things this way, it doesn't really make sense for these types either. Python's own file object permits reinitialization though, so leaving rpm.fd() the way it is now. - This reverts the following commits: d056df28c38e602d82b4f9b527c686037074e660 3f77c3146da46a49f44b17fa66139fbe2dd9e45c 7214b2e0a271b7a7b3df312c58593878cbf56504 dc50fb2863c81159fb4cc8b25ce3862720c0cce5
2011-07-01Fix/sanitize rpm.ds python object creation a bitPanu Matilainen1-13/+11
- Move all actual initialization work into tp_init, permit reinitialization without leaking and use PyType_GenericNew for tp_new.
2011-07-01Fix/sanitize rpm.ts python object creation a bitPanu Matilainen1-13/+11
- Move all actual initialization work into tp_init, permit reinitialization without leaking and use PyType_GenericNew for tp_new.
2011-07-01Fix/sanitize rpm.fi python object creation a bitPanu Matilainen2-22/+7
- Move all actual initialization work into tp_init, permit reinitialization without leaking and use PyType_GenericNew for tp_new, eliminate internal rpmfi_Wrap() use. There's one user for rpmfi_Wrap() in rpmte-py.c which needs fixing later... - Remove unused fiFromFi() helper function
2011-07-01Fix/sanitize rpm.spec python object creationPanu Matilainen2-29/+18
- Specs are not really immutable, move the initialization work into tp_init and use PyType_GenericNew for tp_new since we're not doing anything special there. - Eliminate the stupid spec_Wrap() thing and hide specPkg_Wrap() out of side (TODO later...)
2011-07-01Fix/sanitize rpm.fd python object creationPanu Matilainen1-22/+14
- FD's are not really immutable, move the initialization work into tp_init and use PyType_GenericNew for tp_new since we're not doing anything special there. - Remove half a dozen different unnecessary exit points
2011-07-01Fix the totally broken rpm.fd() read methodPanu Matilainen1-20/+25
2011-06-16Export rpmteFailed() to python bindingsPanu Matilainen1-0/+7
- Kinda related to RhBug:661962, yum relies on callbacks to catch install/erase errors but this is not accurate: on erase the element can be ambiguous as the callback only gives a name (sigh). In addition, elements can be skipped entirely if "parent" element fails, in which case no callbacks are issued so these cases would go completely unnoticed when relying on callbacks alone. te.Failed() gives users such as yum a chance to have a look at the real status of elements (after the transaction).
2011-06-09Eww, python ds.Instance() doesn't take any argumentsPanu Matilainen1-1/+1
- ...means its been broken all along, sigh
2011-03-10Fix whitespace in Python doc stringFlorian Festi1-1/+1
2011-03-09Fix the PyBytes vs PyString compatibility definesPanu Matilainen1-5/+5
- Oops. Quite obviously nobody has even tried to build this with python < 2.6. Whether it'd actually work is another question...
2011-03-09Python 3 fixupsPanu Matilainen2-1/+3
- PyString is gone, use PyBytes instead - Add compatibility defines to paper over PyInt/PyLong_JustHowLongFunctionNamesYouCanComeUpWith()
2011-03-09Preliminary distutils support for the python bindingsPanu Matilainen2-0/+56
- Steps towards separating rpm-python from the main rpm tarball even though developed within the rpm repository. - Having the bindings in a separate tarball makes it simpler to build them for different python versions, notably python 3 (RhBug:531543)
2011-03-09Cut the remaining ties python bindings have to main rpm sourcesPanu Matilainen3-4/+3
- Include what little we need from standard headers instead of relying on rpm source tree system.h for anything. - Remove non-public includes from python binding include paths
2011-03-09Don't bother with the callback die-die-die error translationPanu Matilainen1-1/+1
2011-03-09Eliminate unnecessary _free() usages in pythonPanu Matilainen1-2/+2
2011-03-09Python bindings dont need our debug.h for anythingPanu Matilainen12-26/+0
2011-03-04Throw an exception from Fseek() errors in python rpmfd.seek()Panu Matilainen1-1/+1
2011-03-04Remove unused return code variablePanu Matilainen1-2/+1
- rpmdsRpmlib() can return errors but not really applicaple here
2011-02-20Allow both string + unicode in python addInstall() / addErase()Panu Matilainen1-2/+2
2011-02-15Import the C-level ts python object as TransactionSetCorePanu Matilainen1-8/+8
- The previous _rpmts name suggests its some scary internal stuff that shouldn't be used when that's not the case, it's just a lower level interface to the same thing.