From 178eaadfc82dadffce1cf90ae4265fdba18bc91e Mon Sep 17 00:00:00 2001 From: marioalexis Date: Thu, 9 Jun 2022 17:19:32 -0300 Subject: [PATCH] App: Improve docstrings in MetadataPy.xml and fix memory leak --- src/App/MetadataPy.xml | 150 ++++++++++++++++++++++---------------- src/App/MetadataPyImp.cpp | 17 +++-- 2 files changed, 98 insertions(+), 69 deletions(-) diff --git a/src/App/MetadataPy.xml b/src/App/MetadataPy.xml index c5202c56e0..2f7f0e02a3 100644 --- a/src/App/MetadataPy.xml +++ b/src/App/MetadataPy.xml @@ -16,181 +16,207 @@ - - Metadata - A Metadata object reads an XML-formatted package metadata file and provides read-only access to its contents. - - A single constructor is supported: - Metadata(file) -- Reads the XML file and provides access to the metadata it specifies. - + App.Metadata class.\n +A Metadata object reads an XML-formatted package metadata file and provides +read-only access to its contents.\n +The following constructors are supported:\n +Metadata() +Empty constructor.\n +Metadata(metadata) +Copy constructor. +metadata : App.Metadata\n +Metadata(file) +Reads the XML file and provides access to the metadata it specifies. +file : str\n XML file name. Metadata - String: the name of this item + String representing the name of this item. - String: the version of this item in semantic triplet format + String representing the version of this item in semantic triplet format. - String: the description of this item (text only, no markup allowed) + String representing the description of this item (text only, no markup allowed). - List of maintainer objects with 'name' and 'email' string attributes + List of maintainer objects with 'name' and 'email' string attributes. - List of applicable licenses as objects with 'name' and 'file' string attributes + List of applicable licenses as objects with 'name' and 'file' string attributes. - - List of URLs as objects with 'location' and 'type' string attributes, where type is one of: - * website - * repository - * bugtracker - * readme - * documentation - + List of URLs as objects with 'location' and 'type' string attributes, where type +is one of: +* website +* repository +* bugtracker +* readme +* documentation - List of author objects, each with a 'name' and a (potentially empty) 'email' string attribute + List of author objects, each with a 'name' and a (potentially empty) 'email' +string attribute. - - List of dependencies, as objects with the following attributes: - * package -- Required: must exactly match the contents of the 'name' element in the referenced package's package.xml file - * version_lt -- Optional: The dependency to the package is restricted to versions less than the stated version number - * version_lte -- Optional: The dependency to the package is restricted to versions less or equal than the stated version number - * version_eq -- Optional: The dependency to the package is restricted to a version equal than the stated version number - * version_gte -- Optional: The dependency to the package is restricted to versions greater or equal than the stated version number - * version_gt -- Optional: The dependency to the package is restricted to versions greater than the stated version number - * condition -- Optional: Conditional expression as documented in REP149 - + List of dependencies, as objects with the following attributes: +* package + Required. Must exactly match the contents of the 'name' element in the + referenced package's package.xml file. +* version_lt + Optional. The dependency to the package is restricted to versions less than + the stated version number. +* version_lte + Optional. The dependency to the package is restricted to versions less or + equal than the stated version number. +* version_eq + Optional. The dependency to the package is restricted to a version equal + than the stated version number. +* version_gte + Optional. The dependency to the package is restricted to versions greater + or equal than the stated version number. +* version_gt + Optional. The dependency to the package is restricted to versions greater + than the stated version number. +* condition + Optional. Conditional expression as documented in REP149. - List of conflicts, format identical to dependencies + List of conflicts, format identical to dependencies. - List of things this item is considered by its author to replace: format identical to dependencies + List of things this item is considered by its author to replace. The format is +identical to dependencies. - List of strings + List of strings. - Relative path to an icon file + Relative path to an icon file. - String: the name of the main Python class this item creates/represents + String representing the name of the main Python class this item +creates/represents. - String: the name of the subdirectory this content item is located in. If empty, the item is in a directory named the same as the content item. + String representing the name of the subdirectory this content item is located in. +If empty, the item is in a directory named the same as the content item. - A list of files associated with this item -- the meaning of each file is implementation-defined + List of files associated with this item. +The meaning of each file is implementation-defined. - A dictionary of lists of content items: defined recursively, each item is itself a Metadata object -- see package.xml file format documentation for details + Dictionary of lists of content items: defined recursively, each item is itself +a Metadata object. +See package.xml file format documentation for details. - A string representing the minimum version of FreeCAD needed for this item. If unset it will be 0.0.0. + String representing the minimum version of FreeCAD needed for this item. +If unset it will be 0.0.0. - A string representing the maximum version of FreeCAD needed for this item. If unset it will be 0.0.0. + String representing the maximum version of FreeCAD needed for this item. +If unset it will be 0.0.0. - getLastSupportedFreeCADVersion() -Search through all content package items, and determine if a maximum supported version of FreeCAD -is set. Returns None if no maximum version is set, or if *any* content item fails to provide a -maximum version (implying that that content item will work with all known versions). - + getLastSupportedFreeCADVersion() -> str or None\n +Search through all content package items, and determine if a maximum supported +version of FreeCAD is set. +Returns None if no maximum version is set, or if *any* content item fails to +provide a maximum version (implying that that content item will work with all +known versions). - getFirstSupportedFreeCADVersion() -Search through all content package items, and determine if a minimum supported version of FreeCAD -is set. Returns 0.0 if no minimum version is set, or if *any* content item fails to provide a -minimum version (implying that that content item will work with all known versions -- technically -limited to 0.20 as the lowest known version since the metadata standard was added then). - + getFirstSupportedFreeCADVersion() -> str or None\n +Search through all content package items, and determine if a minimum supported +version of FreeCAD is set. +Returns 0.0 if no minimum version is set, or if *any* content item fails to +provide a minimum version (implying that that content item will work with all +known versions. Technically limited to 0.20 as the lowest known version since +the metadata standard was added then). - supportsCurrentFreeCAD() -Returns false if this metadata object directly indicates that it does not support the current -version of FreeCAD, or true if it makes no indication, or specifically indicates that it does -support the current version. Does not recurse into Content items. - + supportsCurrentFreeCAD() -> bool\n +Returns False if this metadata object directly indicates that it does not +support the current version of FreeCAD, or True if it makes no indication, or +specifically indicates that it does support the current version. Does not +recurse into Content items. - getGenericMetadata(name) -Get the list of GenericMetadata objects with key 'name'. Generic metadata objects are Python objects with -a string 'contents' and a dictionary of strings, 'attributes'. They represent unrecognized simple XML tags -in the metadata file. - + getGenericMetadata(name) -> list\n +Get the list of GenericMetadata objects with key 'name'. +Generic metadata objects are Python objects with a string 'contents' and a +dictionary of strings, 'attributes'. They represent unrecognized simple XML tags +in the metadata file. diff --git a/src/App/MetadataPyImp.cpp b/src/App/MetadataPyImp.cpp index e04582fc9c..17913909cb 100644 --- a/src/App/MetadataPyImp.cpp +++ b/src/App/MetadataPyImp.cpp @@ -34,7 +34,7 @@ XERCES_CPP_NAMESPACE_USE // Returns a string which represents the object e.g. when printed in Python std::string MetadataPy::representation(void) const { - MetadataPy::PointerType ptr = reinterpret_cast(_pcTwinPointer); + MetadataPy::PointerType ptr = getMetadataPtr(); std::stringstream str; str << "Metadata [Name=("; str << ptr->name(); @@ -288,10 +288,11 @@ Py::Object MetadataPy::getContent(void) const PyObject* MetadataPy::getGenericMetadata(PyObject* args) { const char* name; - if (!PyArg_ParseTuple(args, "s!", &name)) + if (!PyArg_ParseTuple(args, "s", &name)) return nullptr; + auto gm = (*getMetadataPtr())[name]; - auto pyGenericMetadata = new Py::List; + Py::List pyGenericMetadata; for (const auto& item : gm) { Py::Dict pyItem; pyItem["contents"] = Py::String(item.contents); @@ -300,12 +301,12 @@ PyObject* MetadataPy::getGenericMetadata(PyObject* args) pyAttributes[attribute.first] = Py::String(attribute.second); } pyItem["attributes"] = pyAttributes; - pyGenericMetadata->append(pyItem); + pyGenericMetadata.append(pyItem); } - return pyGenericMetadata->ptr(); + return Py::new_reference_to(pyGenericMetadata); } -Py::Object MetadataPy::getFreeCADMin() const +Py::Object MetadataPy::getFreeCADMin() const { return Py::String(getMetadataPtr()->freecadmin().str()); } @@ -316,10 +317,11 @@ void MetadataPy::setFreeCADMin(Py::Object args) PyObject* p = args.ptr(); if (!PyArg_ParseTuple(p, "s", &version)) return; + getMetadataPtr()->setFreeCADMin(App::Meta::Version(version)); } -Py::Object MetadataPy::getFreeCADMax() const +Py::Object MetadataPy::getFreeCADMax() const { return Py::String(getMetadataPtr()->freecadmax().str()); } @@ -330,6 +332,7 @@ void MetadataPy::setFreeCADMax(Py::Object args) PyObject* p = args.ptr(); if (!PyArg_ParseTuple(p, "s", &version)) return; + getMetadataPtr()->setFreeCADMax(App::Meta::Version(version)); }