summaryrefslogtreecommitdiffstats
path: root/src/xmlpythonizer.c
Commit message (Collapse)AuthorAgeFilesLines
* Port to Python 3 while maintaining compatibility with Python >= 2.6Slavek Kabrda2015-02-031-3/+4
| | | | Signed-off-by: David Sommerseth <davids@redhat.com>
* Removed not needed \n from log_append() entriesDavid Sommerseth2010-02-051-5/+5
|
* Added logging flag to log_append() to change log behaviourDavid Sommerseth2010-02-051-6/+6
| | | | | | | | | | | | | | Valid flags are: * LOGFL_NORMAL Log all messages to the log context, and send log message to stderr on errors * LOGFL_NODUPS Log only unique messages. Duplicated messages will be removed * LOGFL_NOSTDERR Don't write to stderr, even if errors occur
* Ported fprintf() -> log_append() on XML functionsDavid Sommerseth2010-01-081-49/+59
|
* Spelling fixesNima Talebi2009-12-141-1/+1
| | | | Thanks Lintian! You're a champ!
* Fixed incorrectly Py_DECREC() on Py_None valuesDavid Sommerseth2009-06-191-3/+5
|
* Fixed missing check which caused SEGV on Python2.3David Sommerseth2009-06-191-1/+1
| | | | | Could also be related to an older libxml2 version as well, as this behaviour was found on RHEL4u4
* Added new function: dmixml_FindNodeByAttr_NoCase(...)David Sommerseth2009-06-151-1/+1
| | | | | | | | | | This function will ignore the case of the string of the value to be found. This improves the behaviour mentioned in commit 20030e42b4d3f7283f6143641cb009a8dbf1da24. At the moment, the immediate advantage is that the pymap.xml is not strictly bound to if the type IDs in hex are in upper and/or lower case. Both cases and mixed cases will now work.
* Fixed wrong behavivour in pythonizeXMLnode() when no key value is foundDavid Sommerseth2009-06-151-23/+22
| | | | | | | | | | | | | | | | | | | | | If the XPath expression for the key value points on a non-existing XML node, it would earlier abort pythonizing the XML data. Even though this could look like the correct behaviour, it will not work out well in reality. For sections like 'bios', it might be that the DMI/SMBIOS data do not describe or provide the BIOSLanguage section (type id 0x0D). Which means calling dmidecode.bios() would fail completely instead of reporting what it could find. This patch fixes this issue and it will normally ignore not found key values and just continue pythonizing the XML data and return what it managed to translate into a Python dictionary. If DEBUG is defined when compiling python-dmidecode, a warning message will be printed directly to stderr when a key value is not found. A warning is printed if dmidecode is compiled with DEBUG defined.
* Fixed wrong int->hex string conversionDavid Sommerseth2009-06-151-1/+1
| | | | | Upper case hex string values is used in the pymap.xml file. This should be improved so that type id is case insensitive.
* Pick the version info from version.hDavid Sommerseth2009-06-111-1/+2
|
* Don't set exceptions when it should already be setDavid Sommerseth2009-06-091-4/+16
|
* Moved xmlpythonizer.c over to new error functionsDavid Sommerseth2009-06-091-59/+48
|
* Pass typeid as int internally to the dmiMAP_ParseMappingXML_TypeID(...)David Sommerseth2009-06-091-3/+7
| | | | | This function will then convert the value to proper hex value for further processing.
* Renamed _dmiMAP_GetRootElement(...) to dmiMAP_GetRootElement(...) and ↵David Sommerseth2009-06-091-3/+3
| | | | exported the function
* Updated comments for all functions in xmlpythonizer.c in Doxygen formatDavid Sommerseth2009-06-021-27/+171
|
* Replaced all 'for' iterations on xmlNodes with 'foreach_xmlnode'David Sommerseth2009-06-021-9/+9
|
* Rewrote the dmiMAP_ParseMappingXML(...) function and split it upDavid Sommerseth2009-06-021-77/+122
| | | | | | | | | | | | | | | | Removed the automagic in the dmiMAP_ParseMappingXML(...) function from automatically decide what to parse (TypeMapping or GroupMapping). Introduced two new functions instead: - dmiMAP_ParseMappingXML_GroupName(xmlDoc *xmlmap, const char *name) Parses the XML mapping document, using the GroupMapping tags and building up a proper ptzMAP structure for all TypeMap defined in that group. - dmiMAP_ParseMappingXML_TypeID(xmlDoc *xmlmap, const char *typeid) Parses the XML mapping document, using only the TypeMapping section in th mapping document. Rewrote a lot of internal parts to reuse as much of the existing code as possible.
* Fixed WIP from last night (with notes)Nima Talebi2009-05-271-12/+16
| | | | | | | | | | Note that this will not work as expected for `group mappings' that have unimplemented `type maps', and this is because the linked-list chain will ne broken at the first unimplemented `type map' There is no reason to code a workaround for this as the type do have to be implemented eventually, and hence added code will merely be noise.
* WIP commitNima Talebi2009-05-271-36/+34
| | | | | | | | Merged the two XML files into one, and amended relevant code. I still want to modify the XML tag names, but not yet. The calls to dmidecode.type() not function as expected, but the others are broken - this is next.
* AutoheaderedNima Talebi2009-05-241-42/+113
|
* Broken commit - change in XML mapping designNima Talebi2009-05-241-8/+17
| | | | | | | | | | | Rather than hardcoding the data by function name (e.g. system, bios, connector, slot, etc), create each `type' as an individual XML tree, then group them under user-friendly names (as per the function names). Here the `pythonmap.xml' groups (but does not define) the various types (0..255), the types themselves are however defined in `typemap.xml'. This commit is broken, and a WIP.
* Completed preliminary reimplementation of type()Nima Talebi2009-05-241-14/+21
| | | | | | | Updated test unit to match. Throw an exception instead of returning None/False in some functions.
* Reimplementing the type() function - WIPNima Talebi2009-05-231-6/+15
|
* Completed test caseNima Talebi2009-05-231-2/+2
| | | | | | | Removed trailing spaces from xml data file. Commented out fprintf()s for now (Perhapse should add them to the debug build at least).
* More cleanupNima Talebi2009-05-231-1/+1
| | | | | | | | | Don't write to stdout unless in debug mode (with respect to writing to memory devices. Added the xml datafile to setup (distutils). Updated test case (incorporating color and cleaning up tests).
* Reversioned, relicensed, and rejiggedNima Talebi2009-05-221-0/+1
| | | | | | | | | | | The version is of now, v3.10.6. The version major field has been upped due to the newly added XML functionality. The version has been reverted to GPLv2. Some headers have been cleaned up, copyright notices added etc. Credits given where due.
* Added support for value type 'list:dict' for field mappingDavid Sommerseth2009-05-201-12/+78
| | | | | | | | | | | | | | This builds up a list of dicts. Syntax is: <Map keytype="constant" key="TestData" valuetype="list:dict" value="/xml/XPath/to/nodes"> <Map keytype="constant" key="field" valuetype="string" key="ValueNode"/> </Map> The parser will iterate all nodes defined in the @value attribute and the root path will of the nested mapping will be using the path in @value as the root path for further parsing.
* Added 'emptyValue' attribute in the Map tagDavid Sommerseth2009-05-151-14/+32
| | | | | This attribute defines a default value when XML source data is empty
* Added new Map attribute - emptyIsNoneDavid Sommerseth2009-05-141-14/+57
| | | | | | | | If the emptyIsNone attribute is set to "1", the Python result will be forced to Py_None if the referenced XML value is empty. When checking if the value is empty, the XML value is right trimmed to remove trailing spaces. Only spaces are are removed.
* Support fixed size listsDavid Sommerseth2009-05-141-3/+67
| | | | | | | | | When using one of the list types as valuetype, the Map tag now also supports fixedsize and index_attr attributes. - fixedsize : Defines a fixed size of the list - index_attr : Defines an attribute name of the input XML data which contains the list index for the value
* Fixed another parser issueDavid Sommerseth2009-05-141-111/+122
| | | | | When using rootpath, it did not parse all elements as expected. Also restricted the rootpath to only work when valuetype="dict".
* Big rewrite of xmlpythonizerDavid Sommerseth2009-05-131-76/+155
| | | | | | | | - Supports relative XPaths now by using the rootpath attribute in the Map tag. This path is then set for all elements inside this Map tag. - Rewrote the parser to recurse correctly. The former version did not recurse well on the very outer (first) Map level.
* Improved error handling when parsing mapping XMLDavid Sommerseth2009-05-041-4/+6
|
* Rewritten dmixml_GetXPathContent(...) and _get_key_value(...)David Sommerseth2009-04-301-26/+43
| | | | | This rewrite was to handle XPATH_NUMBER more correctly. Now these functions needs an preallocated memory buffer for the result.
* Reimplemented the XPath integrationDavid Sommerseth2009-04-291-27/+43
| | | | | | | Now the XPath expressions can include XPath functions as well. The previous implementation only supported XPATH_NODESET results from XPath queries. Now XPATH_STRING and XPATH_NUMBER results are supported as well. XPATH_BOOLEAN might be needed later on.
* Revert "Added filter and filtervalue attributes to xmlpythonizer's <Map> tags"David Sommerseth2009-04-291-74/+12
| | | | | | | This reverts commit 4b925a1433b65c217e787804df3cf349d6b387aa. Discovered that XPath got the needed power for filtering, no need for this extra feature
* Exported ptzmap_Free()David Sommerseth2009-04-291-1/+0
|
* Added filter and filtervalue attributes to xmlpythonizer's <Map> tagsDavid Sommerseth2009-04-291-12/+74
| | | | | | Using these attributes, only XML data (from the given XPath in 'filter') which matches the value in 'filtervalue' will be added to the Python data.
* Updated xmlpythonizer to support boolean type and dynamic XPath keysDavid Sommerseth2009-04-291-35/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Added support boolean and list:boolean value types * Traversing child nodes and having dynamic keys Now it is possible to do the following: ** test.xml ** <?xml version="1.0" encoding="UTF-8"?> <testdata> <list> <value enabled="1">Option 1</value> <value enabled="0">Option 2</value> <value enabled="1">Option 3</value> </list> </testdata> ** mapping.xml ** <?xml version="1.0" encoding="UTF-8"?> <dmidecode_fieldmap version="1"> <Mapping name="example"> <Map keytype="string" key="/testdata/list/value" valuetype="boolean" value="/testdata/list/value/@enabled"/> </Mapping> </dmidecode_fieldmap> Which should result in: {'Option 1': True, 'Option 2': False, 'Option 3': True'}
* Added generic XML -> Python parserDavid Sommerseth2009-04-291-0/+522
The xmlpythonizer module will convert any XML data (xmlNode or xmlDoc) and format it as a Python object. The formatting is defined in it's own XML file. Basic format: <dmidecode_fieldmap version="1"> <Mapping name="{name of mapping table}"> <Map keytype="{key type}" key="{key value}" valuetype="{value type} value="{value}"/> </Mapping> </dmidecode_fieldmap> The keytype and key attributes defines the key in the Python Dict. The root element will always be a Python Dict structure. The valid key types are: * constant Uses the value in {key} as the key value * string, integer, float Uses a string value from the data XML to be converted to Python. The value set in the key attribute defines an XPath value which points to the data to be used as a Python dict key. Since Python only supports C strings in the C interface for Python dict keys, integer and float will be treated as strings. The valuetype and value attributes are similar to the keys, but with some more features. Valid valuetypes are: * constant The value given in the value attribute will be used in the value in the Python result. * string, integer, float The value given in the value attribute defines the XPath to the data XML, of where to retrieve the value for the given key. The valuetype defines if the data should be understood as a string, integer or float in the Python result. * list:string, list:integer, list:float This does the same as the string, integer or float type, with a tweak. The data will be put into a list. If the XPath given returns multiple nodes, all of them will be added to this list. * dict The dict valuetype is more special. It should not contain any value attribute. On the other hand, it should contain a sub-level of <Map> tags. In this way, you can build up a multi dimensional Python dict. Example: ** pythonmap.xml ** <?xml version="1.0" encoding="UTF-8"?> <dmidecode_fieldmap version="1"> <Mapping name="example_map"> <Map keytype="constant" key="DemoCase" valuetype="constant" value="XML Pythonizing"/> <Map keytype="constant" key="String1" valuetype="string" value="/example/string1"/> <Map keytype="constant" key="AttribString1" valuetype="integer" value="/example/string1/@int_value"/> <Map keytype="string" key="/example/keyset/@value" valuetype="dict"> <Map keytype="constant" key="Value1" valuetype="string" value="/example/keyset/value1"/> <Map keytype="constant" key="ValueList" valuetype="list:string" value="/example/keyset/valuelist"/> </Map> </Mapping> </dmidecode_fieldmap> ** exampledata.xml ** <?xml version="1.0" encoding="UTF-8"?> <example> <string1 int_value="1234">String value #1</string1> <keyset value="TestData"> <value1>More test data</value1> <valuelist>Value1 in list</valuelist> <valuelist>Value2 in list</valuelist> <valuelist>Value3 in list</valuelist> </keyset> </example> ** C code snippet ** void xmlpythonizer() { xmlDoc *xmlmap = NULL; xmlDoc *xmldata = NULL; ptzMAP *mapping = NULL; PyObject *pythondata = NULL; // Read XML files xmlmap = xmlReadFile("pythonmap.xml", NULL, 0); xmldata = xmlReadFile("exampledata.xml", NULL, 0); // Parse the mapping XML mapping = dmiMAP_ParseMappingXML(xmlmap, "example_map"); // Parse the xmldata into a Python object pythondata = pythonizeXMLdoc(mapping, xmldata); // ..... the program continues to do something useful } The result stored inside the pythondata object should now be something similar to: {'DemoCase': 'XML Pythonizing', 'String1': 'String value #1', 'AttribString1: 1234, 'TestData': {'Value1': 'More test data', 'ValueList': ['Value1 in list','Value2 in list','Value3 in list']} }