Addon Manager: DevMode content implementation

This commit is contained in:
Chris Hennes
2022-09-07 19:00:26 -05:00
parent 7a17106776
commit cb1f6bffa8
11 changed files with 1658 additions and 226 deletions

View File

@@ -207,7 +207,7 @@ std::string Metadata::classname() const
return _classname;
}
boost::filesystem::path App::Metadata::subdirectory() const
boost::filesystem::path Metadata::subdirectory() const
{
return _subdirectory;
}
@@ -217,12 +217,12 @@ std::vector<fs::path> Metadata::file() const
return _file;
}
Meta::Version App::Metadata::freecadmin() const
Meta::Version Metadata::freecadmin() const
{
return _freecadmin;
}
Meta::Version App::Metadata::freecadmax() const
Meta::Version Metadata::freecadmax() const
{
return _freecadmax;
}
@@ -315,7 +315,7 @@ void Metadata::setClassname(const std::string& name)
_classname = name;
}
void App::Metadata::setSubdirectory(const boost::filesystem::path& path)
void Metadata::setSubdirectory(const boost::filesystem::path& path)
{
_subdirectory = path;
}
@@ -330,22 +330,22 @@ void Metadata::addContentItem(const std::string& tag, const Metadata& item)
_content.insert(std::make_pair(tag, item));
}
void App::Metadata::setFreeCADMin(const Meta::Version& version)
void Metadata::setFreeCADMin(const Meta::Version& version)
{
_freecadmin = version;
}
void App::Metadata::setFreeCADMax(const Meta::Version& version)
void Metadata::setFreeCADMax(const Meta::Version& version)
{
_freecadmax = version;
}
void App::Metadata::addGenericMetadata(const std::string& tag, const Meta::GenericMetadata& genericMetadata)
void Metadata::addGenericMetadata(const std::string& tag, const Meta::GenericMetadata& genericMetadata)
{
_genericMetadata.insert(std::make_pair(tag, genericMetadata));
}
void App::Metadata::removeContentItem(const std::string& tag, const std::string& itemName)
void Metadata::removeContentItem(const std::string& tag, const std::string& itemName)
{
auto tagRange = _content.equal_range(tag);
auto foundItem = std::find_if(tagRange.first, tagRange.second, [&itemName](const auto& check) -> bool { return itemName == check.second.name(); });
@@ -353,6 +353,119 @@ void App::Metadata::removeContentItem(const std::string& tag, const std::string&
_content.erase(foundItem);
}
void Metadata::removeMaintainer(const Meta::Contact &maintainer)
{
auto new_end = std::remove(_maintainer.begin(), _maintainer.end(), maintainer);
_maintainer.erase(new_end, _maintainer.end());
}
void Metadata::removeLicense(const Meta::License &license)
{
auto new_end = std::remove(_license.begin(), _license.end(), license);
_license.erase(new_end, _license.end());
}
void Metadata::removeUrl(const Meta::Url &url)
{
auto new_end = std::remove(_url.begin(), _url.end(), url);
_url.erase(new_end, _url.end());
}
void Metadata::removeAuthor(const Meta::Contact &author)
{
auto new_end = std::remove(_author.begin(), _author.end(), author);
_author.erase(new_end, _author.end());
}
void Metadata::removeDepend(const Meta::Dependency &dep)
{
bool found = false;
for (const auto& check : _depend) {
if (dep == check)
found = true;
}
if (!found)
throw Base::RuntimeError("No match found for dependency to remove");
auto new_end = std::remove(_depend.begin(), _depend.end(), dep);
_depend.erase(new_end, _depend.end());
}
void Metadata::removeConflict(const Meta::Dependency &dep)
{
auto new_end = std::remove(_conflict.begin(), _conflict.end(), dep);
_conflict.erase(new_end, _conflict.end());
}
void Metadata::removeReplace(const Meta::Dependency &dep)
{
auto new_end = std::remove(_replace.begin(), _replace.end(), dep);
_replace.erase(new_end, _replace.end());
}
void Metadata::removeTag(const std::string &tag)
{
auto new_end = std::remove(_tag.begin(), _tag.end(), tag);
_tag.erase(new_end, _tag.end());
}
void Metadata::removeFile(const boost::filesystem::path &path)
{
auto new_end = std::remove(_file.begin(), _file.end(), path);
_file.erase(new_end, _file.end());
}
void Metadata::clearContent()
{
_content.clear();
}
void Metadata::clearMaintainer()
{
_maintainer.clear();
}
void Metadata::clearLicense()
{
_license.clear();
}
void Metadata::clearUrl()
{
_url.clear();
}
void Metadata::clearAuthor()
{
_author.clear();
}
void Metadata::clearDepend()
{
_depend.clear();
}
void Metadata::clearConflict()
{
_conflict.clear();
}
void Metadata::clearReplace()
{
_replace.clear();
}
void Metadata::clearTag()
{
_tag.clear();
}
void Metadata::clearFile()
{
_file.clear();
}
DOMElement* appendSimpleXMLNode(DOMElement* baseNode, const std::string& nodeName, const std::string& nodeContents)
{
@@ -376,6 +489,36 @@ void addAttribute(DOMElement* node, const std::string& key, const std::string& v
node->setAttribute(XUTF8Str(key.c_str()).unicodeForm(), XUTF8Str(value.c_str()).unicodeForm());
}
void addAttribute(DOMElement *node, const std::string &key, bool value)
{
if (value)
node->setAttribute(XUTF8Str(key.c_str()).unicodeForm(), XUTF8Str("True").unicodeForm());
else
node->setAttribute(XUTF8Str(key.c_str()).unicodeForm(), XUTF8Str("False").unicodeForm());
}
void addAttribute(DOMElement *node, const std::string &key, Meta::DependencyType value)
{
// Someday we should be able to change this to use reflection, but it's not yet
// available (using C++17)
std::string stringified("automatic");
switch (value) {
case Meta::DependencyType::automatic:
stringified = "automatic";
break;
case Meta::DependencyType::internal:
stringified = "internal";
break;
case Meta::DependencyType::addon:
stringified = "addon";
break;
case Meta::DependencyType::python:
stringified = "python";
break;
}
node->setAttribute(XUTF8Str(key.c_str()).unicodeForm(), XUTF8Str(stringified.c_str()).unicodeForm());
}
void addDependencyNode(DOMElement* root, const std::string& name, const Meta::Dependency& depend)
{
auto element = appendSimpleXMLNode(root, name, depend.package);
@@ -386,6 +529,8 @@ void addDependencyNode(DOMElement* root, const std::string& name, const Meta::De
addAttribute(element, "version_gte", depend.version_gte);
addAttribute(element, "version_gt", depend.version_gt);
addAttribute(element, "condition", depend.condition);
addAttribute(element, "optional", depend.optional);
addAttribute(element, "type", depend.dependencyType);
}
}
@@ -489,7 +634,7 @@ bool Metadata::satisfies(const Meta::Dependency& dep)
return true;
}
bool App::Metadata::supportsCurrentFreeCAD() const
bool Metadata::supportsCurrentFreeCAD() const
{
static auto fcVersion = Meta::Version();
if (fcVersion == Meta::Version()) {
@@ -683,6 +828,11 @@ Meta::Contact::Contact(const XERCES_CPP_NAMESPACE::DOMElement* e)
email = StrXUTF8(emailAttribute).str;
}
bool App::Meta::Contact::operator==(const Contact &rhs) const
{
return name==rhs.name && email==rhs.email;
}
Meta::License::License(const std::string& name, fs::path file) :
name(name),
file(file)
@@ -699,7 +849,16 @@ Meta::License::License(const XERCES_CPP_NAMESPACE::DOMElement* e)
name = StrXUTF8(e->getTextContent()).str;
}
Meta::Url::Url(const std::string& location, UrlType type) :
bool App::Meta::License::operator==(const License &rhs) const
{
return name==rhs.name && file==rhs.file;
}
App::Meta::Url::Url() : location(""), type(App::Meta::UrlType::website)
{
}
Meta::Url::Url(const std::string &location, UrlType type) :
location(location),
type(type)
{
@@ -728,7 +887,22 @@ Meta::Url::Url(const XERCES_CPP_NAMESPACE::DOMElement* e)
location = StrXUTF8(e->getTextContent()).str;
}
Meta::Dependency::Dependency(const XERCES_CPP_NAMESPACE::DOMElement* e)
bool App::Meta::Url::operator==(const Url &rhs) const
{
if (type == UrlType::repository && branch != rhs.branch)
return false;
return type==rhs.type && location==rhs.location;
}
App::Meta::Dependency::Dependency() : optional(false), dependencyType(App::Meta::DependencyType::automatic)
{
}
App::Meta::Dependency::Dependency(const std::string &pkg) : package(pkg), optional(false), dependencyType(App::Meta::DependencyType::automatic)
{
}
Meta::Dependency::Dependency(const XERCES_CPP_NAMESPACE::DOMElement *e)
{
version_lt = StrXUTF8(e->getAttribute(XUTF8Str("version_lt").unicodeForm())).str;
version_lte = StrXUTF8(e->getAttribute(XUTF8Str("version_lte").unicodeForm())).str;
@@ -736,10 +910,41 @@ Meta::Dependency::Dependency(const XERCES_CPP_NAMESPACE::DOMElement* e)
version_gte = StrXUTF8(e->getAttribute(XUTF8Str("version_gte").unicodeForm())).str;
version_gt = StrXUTF8(e->getAttribute(XUTF8Str("version_gt").unicodeForm())).str;
condition = StrXUTF8(e->getAttribute(XUTF8Str("condition").unicodeForm())).str;
std::string opt_string = StrXUTF8(e->getAttribute(XUTF8Str("optional").unicodeForm())).str;
if (opt_string == "true" || opt_string == "True") // Support Python capitalization in this one case...
optional = true;
else
optional = false;
std::string type_string = StrXUTF8(e->getAttribute(XUTF8Str("type").unicodeForm())).str;
if (type_string == "automatic" || type_string == "")
dependencyType = Meta::DependencyType::automatic;
else if (type_string == "addon")
dependencyType = Meta::DependencyType::addon;
else if (type_string == "internal")
dependencyType = Meta::DependencyType::internal;
else if (type_string == "python")
dependencyType = Meta::DependencyType::python;
else {
auto message = std::string("Invalid dependency type \"") + type_string + "\"";
throw Base::XMLBaseException(message);
}
package = StrXUTF8(e->getTextContent()).str;
}
bool App::Meta::Dependency::operator==(const Dependency &rhs) const
{
return package == rhs.package &&
version_lt == rhs.version_lt &&
version_lte == rhs.version_lte &&
version_eq == rhs.version_eq &&
version_gte == rhs.version_gte &&
version_gt == rhs.version_gt &&
condition == rhs.condition &&
optional == rhs.optional &&
dependencyType == rhs.dependencyType;
}
Meta::Version::Version() :
major(0),
minor(0),

View File

@@ -50,6 +50,7 @@ namespace App {
explicit Contact(const XERCES_CPP_NAMESPACE::DOMElement* e);
std::string name; //< Contact name - required
std::string email; //< Contact email - may be optional
bool operator==(const Contact &rhs) const;
};
/**
@@ -65,6 +66,7 @@ namespace App {
explicit License(const XERCES_CPP_NAMESPACE::DOMElement* e);
std::string name; //< Short name of license, e.g. "LGPL2", "MIT", "Mozilla Public License", etc.
boost::filesystem::path file; //< Optional path to the license file, relative to the XML file's location
bool operator==(const License &rhs) const;
};
enum class UrlType {
@@ -80,12 +82,13 @@ namespace App {
* \brief A URL, including type information (e.g. website, repository, or bugtracker, in package.xml)
*/
struct AppExport Url {
Url() = default;
Url();
Url(const std::string& location, UrlType type);
explicit Url(const XERCES_CPP_NAMESPACE::DOMElement* e);
std::string location; //< The actual URL, including protocol
UrlType type; //< What kind of URL this is
std::string branch; //< If it's a repository, which branch to use
bool operator==(const Url &rhs) const;
};
/**
@@ -112,12 +115,25 @@ namespace App {
bool operator!=(const Version&) const;
};
/**
* \enum DependencyType
* The type of dependency.
*/
enum class DependencyType
{
automatic,
internal,
addon,
python
};
/**
* \struct Dependency
* \brief Another package that this package depends on, conflicts with, or replaces
*/
struct AppExport Dependency {
Dependency() = default;
Dependency();
explicit Dependency(const std::string &pkg);
explicit Dependency(const XERCES_CPP_NAMESPACE::DOMElement* e);
std::string package; //< Required: must exactly match the contents of the "name" element in the referenced package's package.xml file.
std::string version_lt; //< Optional: The dependency to the package is restricted to versions less than the stated version number.
@@ -126,6 +142,9 @@ namespace App {
std::string version_gte; //< Optional: The dependency to the package is restricted to versions greater or equal than the stated version number.
std::string version_gt; //< Optional: The dependency to the package is restricted to versions greater than the stated version number.
std::string condition; //< Optional: Conditional expression as documented in REP149.
bool optional;//< Optional: Whether this dependency is considered "optional"
DependencyType dependencyType; //< Optional: defaults to "automatic"
bool operator==(const Dependency &rhs) const;
};
/**
@@ -238,25 +257,46 @@ namespace App {
void setName(const std::string& name);
void setVersion(const Meta::Version& version);
void setDescription(const std::string& description);
void addMaintainer(const Meta::Contact& maintainer);
void addLicense(const Meta::License& license);
void addUrl(const Meta::Url& url);
void addAuthor(const Meta::Contact& author);
void addDepend(const Meta::Dependency& dep);
void addConflict(const Meta::Dependency& dep);
void addReplace(const Meta::Dependency& dep);
void addTag(const std::string& tag);
void addMaintainer(const Meta::Contact &maintainer);
void addLicense(const Meta::License &license);
void addUrl(const Meta::Url &url);
void addAuthor(const Meta::Contact &author);
void addDepend(const Meta::Dependency &dep);
void addConflict(const Meta::Dependency &dep);
void addReplace(const Meta::Dependency &dep);
void addTag(const std::string &tag);
void setIcon(const boost::filesystem::path& path);
void setClassname(const std::string& name);
void setSubdirectory(const boost::filesystem::path& path);
void addFile(const boost::filesystem::path& path);
void addContentItem(const std::string& tag, const Metadata& item);
void addFile(const boost::filesystem::path &path);
void addContentItem(const std::string &tag, const Metadata &item);
void setFreeCADMin(const Meta::Version& version);
void setFreeCADMax(const Meta::Version& version);
void addGenericMetadata(const std::string& tag, const Meta::GenericMetadata& genericMetadata);
void addGenericMetadata(const std::string &tag, const Meta::GenericMetadata &genericMetadata);
// Deleters (work in progress...)
void removeContentItem(const std::string& tag, const std::string& itemName);
// Deleters
void removeContentItem(const std::string &tag, const std::string &itemName);
void removeMaintainer(const Meta::Contact &maintainer);
void removeLicense(const Meta::License &license);
void removeUrl(const Meta::Url &url);
void removeAuthor(const Meta::Contact &author);
void removeDepend(const Meta::Dependency &dep);
void removeConflict(const Meta::Dependency &dep);
void removeReplace(const Meta::Dependency &dep);
void removeTag(const std::string &tag);
void removeFile(const boost::filesystem::path &path);
// Utility functions to clear lists
void clearContent();
void clearMaintainer();
void clearLicense();
void clearUrl();
void clearAuthor();
void clearDepend();
void clearConflict();
void clearReplace();
void clearTag();
void clearFile();
/**
* Write the metadata to an XML file

View File

@@ -14,11 +14,12 @@
RichCompare="false"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="Chris Hennes" EMail="chennes@pioneerlibrarysystem.org" />
<UserDocu>App.Metadata class.\n
A Metadata object reads an XML-formatted package metadata file and provides
read-only access to its contents.\n
read and write access to its contents.\n
The following constructors are supported:\n
Metadata()
Empty constructor.\n
@@ -31,37 +32,37 @@ file : str\n XML file name.</UserDocu>
<DeveloperDocu>Metadata</DeveloperDocu>
</Documentation>
<Attribute Name="Name" ReadOnly="true">
<Attribute Name="Name">
<Documentation>
<UserDocu>String representing the name of this item.</UserDocu>
</Documentation>
<Parameter Name="Name" Type="Object" />
</Attribute>
<Attribute Name="Version" ReadOnly="true">
<Attribute Name="Version">
<Documentation>
<UserDocu>String representing the version of this item in semantic triplet format.</UserDocu>
</Documentation>
<Parameter Name="Version" Type="Object" />
</Attribute>
<Attribute Name="Description" ReadOnly="true">
<Attribute Name="Description">
<Documentation>
<UserDocu>String representing the description of this item (text only, no markup allowed).</UserDocu>
</Documentation>
<Parameter Name="Description" Type="Object" />
</Attribute>
<Attribute Name="Maintainer" ReadOnly="true">
<Attribute Name="Maintainer">
<Documentation>
<UserDocu>List of maintainer objects with 'name' and 'email' string attributes.</UserDocu>
</Documentation>
<Parameter Name="Maintainer" Type="Object" />
</Attribute>
<Attribute Name="License" ReadOnly="true">
<Attribute Name="License">
<Documentation>
<UserDocu>List of applicable licenses as objects with 'name' and 'file' string attributes.</UserDocu>
</Documentation>
<Parameter Name="License" Type="Object" />
</Attribute>
<Attribute Name="Urls" ReadOnly="true">
<Attribute Name="Urls">
<Documentation>
<UserDocu>List of URLs as objects with 'location' and 'type' string attributes, where type
is one of:
@@ -73,14 +74,14 @@ is one of:
</Documentation>
<Parameter Name="Urls" Type="Object" />
</Attribute>
<Attribute Name="Author" ReadOnly="true">
<Attribute Name="Author">
<Documentation>
<UserDocu>List of author objects, each with a 'name' and a (potentially empty) 'email'
string attribute.</UserDocu>
</Documentation>
<Parameter Name="Author" Type="Object" />
</Attribute>
<Attribute Name="Depend" ReadOnly="true">
<Attribute Name="Depend">
<Documentation>
<UserDocu>List of dependencies, as objects with the following attributes:
* package
@@ -106,53 +107,53 @@ string attribute.</UserDocu>
</Documentation>
<Parameter Name="Depend" Type="Object" />
</Attribute>
<Attribute Name="Conflict" ReadOnly="true">
<Attribute Name="Conflict">
<Documentation>
<UserDocu>List of conflicts, format identical to dependencies.</UserDocu>
</Documentation>
<Parameter Name="Conflict" Type="Object" />
</Attribute>
<Attribute Name="Replace" ReadOnly="true">
<Attribute Name="Replace">
<Documentation>
<UserDocu>List of things this item is considered by its author to replace. The format is
identical to dependencies.</UserDocu>
</Documentation>
<Parameter Name="Replace" Type="Object" />
</Attribute>
<Attribute Name="Tag" ReadOnly="true">
<Attribute Name="Tag">
<Documentation>
<UserDocu>List of strings.</UserDocu>
</Documentation>
<Parameter Name="Tag" Type="Object" />
</Attribute>
<Attribute Name="Icon" ReadOnly="true">
<Attribute Name="Icon">
<Documentation>
<UserDocu>Relative path to an icon file.</UserDocu>
</Documentation>
<Parameter Name="Icon" Type="Object" />
</Attribute>
<Attribute Name="Classname" ReadOnly="true">
<Attribute Name="Classname">
<Documentation>
<UserDocu>String representing the name of the main Python class this item
creates/represents.</UserDocu>
</Documentation>
<Parameter Name="Classname" Type="Object" />
</Attribute>
<Attribute Name="Subdirectory" ReadOnly="true">
<Attribute Name="Subdirectory">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="Subdirectory" Type="Object" />
</Attribute>
<Attribute Name="File" ReadOnly="true">
<Attribute Name="File">
<Documentation>
<UserDocu>List of files associated with this item.
The meaning of each file is implementation-defined.</UserDocu>
</Documentation>
<Parameter Name="File" Type="Object" />
</Attribute>
<Attribute Name="Content" ReadOnly="true">
<Attribute Name="Content">
<Documentation>
<UserDocu>Dictionary of lists of content items: defined recursively, each item is itself
a Metadata object.
@@ -219,6 +220,151 @@ dictionary of strings, 'attributes'. They represent unrecognized simple XML tags
in the metadata file.</UserDocu>
</Documentation>
</Methode>
<Methode Name="addContentItem">
<Documentation>
<UserDocu>addContentItem(content_type,metadata)\n
Add a new content item of type 'content_type' with metadata 'metadata'. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeContentItem">
<Documentation>
<UserDocu>removeContentItem(content_type,name)\n
Remove the content item of type 'content_type' with name 'name'. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addMaintainer">
<Documentation>
<UserDocu>addMaintainer(name, email)\n
Add a new Maintainer. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeMaintainer">
<Documentation>
<UserDocu>removeMaintainer(name, email)\n
Remove the Maintainer. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addLicense">
<Documentation>
<UserDocu>addLicense(short_code,path)\n
Add a new License. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeLicense">
<Documentation>
<UserDocu>removeLicense(short_code)\n
Remove the License. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addUrl">
<Documentation>
<UserDocu>addUrl(url_type,url,branch)\n
Add a new Url or type 'url_type' (which should be one of 'repository', 'readme',\n
'bugtracker', 'documentation', or 'webpage') If type is 'repository' you\n
must also specify the 'branch' parameter. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeUrl">
<Documentation>
<UserDocu>removeUrl(url_type,url)\n
Remove the Url. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addAuthor">
<Documentation>
<UserDocu>addAuthor(name, email)\n
Add a new Author with name 'name', and optionally email 'email'. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeAuthor">
<Documentation>
<UserDocu>removeAuthor(name, email)\n
Remove the Author. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addDepend">
<Documentation>
<UserDocu>addDepend(name, kind, optional)\n
Add a new Dependency on package 'name' of kind 'kind' (optional, one of 'auto' (the default),\n
'internal', 'addon', or 'python'). </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeDepend">
<Documentation>
<UserDocu>removeDepend(name, kind)\n
Remove the Dependency on package 'name' of kind 'kind' (optional - if unspecified any\n
matching name is removed). </UserDocu>
</Documentation>
</Methode>
<Methode Name="addConflict">
<Documentation>
<UserDocu>addConflict(name, kind)\n
Add a new Conflict. See documentation for addDepend(). </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeConflict">
<Documentation>
<UserDocu>removeConflict(name, kind)\n
Remove the Conflict. See documentation for removeDepend().</UserDocu>
</Documentation>
</Methode>
<Methode Name="addReplace">
<Documentation>
<UserDocu>addReplace(name)\n
Add a new Replace. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeReplace">
<Documentation>
<UserDocu>removeReplace(name)\n
Remove the Replace. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addTag">
<Documentation>
<UserDocu>addTag(tag)\n
Add a new Tag. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeTag">
<Documentation>
<UserDocu>removeTag(tag)\n
Remove the Tag. </UserDocu>
</Documentation>
</Methode>
<Methode Name="addFile">
<Documentation>
<UserDocu>addFile(filename)\n
Add a new File. </UserDocu>
</Documentation>
</Methode>
<Methode Name="removeFile">
<Documentation>
<UserDocu>removeFile(filename)\n
Remove the File. </UserDocu>
</Documentation>
</Methode>
<ClassDeclarations>
public:

View File

@@ -50,13 +50,13 @@ std::string MetadataPy::representation() const
return str.str();
}
PyObject* MetadataPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
PyObject *MetadataPy::PyMake(struct _typeobject *, PyObject *, PyObject *)// Python wrapper
{
return new MetadataPy(nullptr);
}
// constructor method
int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
int MetadataPy::PyInit(PyObject *args, PyObject * /*kwd*/)
{
if (PyArg_ParseTuple(args, "")) {
setTwinPointer(new Metadata());
@@ -65,7 +65,7 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
// Main class constructor -- takes a file path, loads the metadata from it
PyErr_Clear();
char* filename;
char *filename;
if (PyArg_ParseTuple(args, "et", "utf-8", &filename)) {
try {
std::string utf8Name = std::string(filename);
@@ -75,19 +75,19 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
setTwinPointer(md);
return 0;
}
catch (const Base::XMLBaseException& e) {
catch (const Base::XMLBaseException &e) {
e.setPyException();
return -1;
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
catch (const XMLException &toCatch) {
char *message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
PyErr_SetString(Base::PyExc_FC_XMLBaseException, what.c_str());
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
catch (const DOMException &toCatch) {
char *message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
PyErr_SetString(Base::PyExc_FC_XMLBaseException, what.c_str());
@@ -101,9 +101,9 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
// Copy constructor
PyErr_Clear();
PyObject* o;
PyObject *o;
if (PyArg_ParseTuple(args, "O!", &(App::MetadataPy::Type), &o)) {
App::Metadata* a = static_cast<App::MetadataPy*>(o)->getMetadataPtr();
App::Metadata *a = static_cast<App::MetadataPy *>(o)->getMetadataPtr();
setTwinPointer(new Metadata(*a));
return 0;
}
@@ -117,21 +117,52 @@ Py::Object MetadataPy::getName() const
return Py::String(getMetadataPtr()->name());
}
void MetadataPy::setName(Py::Object args)
{
const char *name = nullptr;
if (!PyArg_Parse(args.ptr(), "z", &name)) {
throw Py::Exception();
}
if (name)
getMetadataPtr()->setName(name);
else
getMetadataPtr()->setName("");
}
Py::Object MetadataPy::getVersion() const
{
return Py::String(getMetadataPtr()->version().str());
}
void MetadataPy::setVersion(Py::Object args)
{
const char *name = nullptr;
if (!PyArg_Parse(args.ptr(), "z", &name))
throw Py::Exception();
if (name)
getMetadataPtr()->setVersion(App::Meta::Version(std::string(name)));
else
getMetadataPtr()->setVersion(App::Meta::Version());
}
Py::Object MetadataPy::getDescription() const
{
return Py::String(getMetadataPtr()->description());
}
void MetadataPy::setDescription(Py::Object args)
{
const char *description = nullptr;
if (!PyArg_Parse(args.ptr(), "s", &description))
throw Py::Exception();
getMetadataPtr()->setDescription(description);
}
Py::Object MetadataPy::getMaintainer() const
{
auto maintainers = getMetadataPtr()->maintainer();
Py::List pyMaintainers;
for (const auto& m : maintainers) {
for (const auto &m : maintainers) {
Py::Dict pyMaintainer;
pyMaintainer["name"] = Py::String(m.name);
pyMaintainer["email"] = Py::String(m.email);
@@ -140,11 +171,50 @@ Py::Object MetadataPy::getMaintainer() const
return pyMaintainers;
}
void MetadataPy::setMaintainer(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearMaintainer();
Py::List maintainers(list);
for (const auto &m : maintainers) {
Py::Dict pyMaintainer(m);
std::string name = pyMaintainer["name"].str();
std::string email = pyMaintainer["email"].str();
getMetadataPtr()->addMaintainer(App::Meta::Contact(name, email));
}
}
PyObject *MetadataPy::addMaintainer(PyObject *args)
{
const char *name = nullptr;
const char *email = nullptr;
if (!PyArg_ParseTuple(args, "ss", &name, &email))
throw Py::Exception();
getMetadataPtr()->addMaintainer(App::Meta::Contact(name, email));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeMaintainer(PyObject *args)
{
const char *name = nullptr;
const char *email = nullptr;
if (!PyArg_ParseTuple(args, "ss", &name, &email))
throw Py::Exception();
getMetadataPtr()->removeMaintainer(App::Meta::Contact(name, email));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getAuthor() const
{
auto authors = getMetadataPtr()->author();
Py::List pyAuthors;
for (const auto& a : authors) {
for (const auto &a : authors) {
Py::Dict pyAuthor;
pyAuthor["name"] = Py::String(a.name);
pyAuthor["email"] = Py::String(a.email);
@@ -153,11 +223,49 @@ Py::Object MetadataPy::getAuthor() const
return pyAuthors;
}
void MetadataPy::setAuthor(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearAuthor();
Py::List authors(list);
for (const auto &a : authors) {
Py::Dict pyAuthor(a);
std::string name = pyAuthor["name"].str();
std::string email = pyAuthor["email"].str();
getMetadataPtr()->addAuthor(App::Meta::Contact(name, email));
}
}
PyObject *MetadataPy::addAuthor(PyObject *args)
{
const char *name = nullptr;
const char *email = nullptr;
if (!PyArg_ParseTuple(args, "ss", &name, &email))
throw Py::Exception();
getMetadataPtr()->addAuthor(App::Meta::Contact(name, email));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeAuthor(PyObject *args)
{
const char *name = nullptr;
const char *email = nullptr;
if (!PyArg_ParseTuple(args, "ss", &name, &email))
throw Py::Exception();
getMetadataPtr()->removeAuthor(App::Meta::Contact(name, email));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getLicense() const
{
auto licenses = getMetadataPtr()->license();
Py::List pyLicenses;
for (const auto& lic : licenses) {
for (const auto &lic : licenses) {
Py::Dict pyLicense;
pyLicense["name"] = Py::String(lic.name);
pyLicense["file"] = Py::String(lic.file.string());
@@ -166,19 +274,57 @@ Py::Object MetadataPy::getLicense() const
return pyLicenses;
}
void MetadataPy::setLicense(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearLicense();
Py::List licenses(list);
for (const auto &l : licenses) {
Py::Dict pyLicense(l);
std::string name = pyLicense["name"].str();
std::string path = pyLicense["file"].str();
getMetadataPtr()->addLicense(App::Meta::License(name, path));
}
}
PyObject *MetadataPy::addLicense(PyObject *args)
{
const char *shortCode = nullptr;
const char *path = nullptr;
if (!PyArg_ParseTuple(args, "ss", &shortCode, &path))
throw Py::Exception();
getMetadataPtr()->addLicense(App::Meta::License(shortCode, path));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeLicense(PyObject *args)
{
const char *shortCode = nullptr;
const char *path = nullptr;
if (!PyArg_ParseTuple(args, "ss", &shortCode, &path))
throw Py::Exception();
getMetadataPtr()->removeLicense(App::Meta::License(shortCode, path));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getUrls() const
{
auto urls = getMetadataPtr()->url ();
auto urls = getMetadataPtr()->url();
Py::List pyUrls;
for (const auto& url : urls) {
for (const auto &url : urls) {
Py::Dict pyUrl;
pyUrl["location"] = Py::String(url.location);
switch (url.type) {
case Meta::UrlType::website: pyUrl["type"] = Py::String("website"); break;
case Meta::UrlType::repository: pyUrl["type"] = Py::String("repository"); break;
case Meta::UrlType::bugtracker: pyUrl["type"] = Py::String("bugtracker"); break;
case Meta::UrlType::readme: pyUrl["type"] = Py::String("readme"); break;
case Meta::UrlType::documentation: pyUrl["type"] = Py::String("documentation"); break;
case Meta::UrlType::website: pyUrl["type"] = Py::String("website"); break;
case Meta::UrlType::repository: pyUrl["type"] = Py::String("repository"); break;
case Meta::UrlType::bugtracker: pyUrl["type"] = Py::String("bugtracker"); break;
case Meta::UrlType::readme: pyUrl["type"] = Py::String("readme"); break;
case Meta::UrlType::documentation: pyUrl["type"] = Py::String("documentation"); break;
}
if (url.type == Meta::UrlType::repository)
pyUrl["branch"] = Py::String(url.branch);
@@ -187,7 +333,93 @@ Py::Object MetadataPy::getUrls() const
return pyUrls;
}
Py::Object dependencyToPyObject(const Meta::Dependency& d)
void MetadataPy::setUrls(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearUrl();
Py::List urls(list);
for (const auto &url : urls) {
Py::Dict pyUrl(url);
std::string location = pyUrl["location"].str();
std::string typeAsString = pyUrl["type"].str();
std::string branch = pyUrl["branch"].str();
auto newUrl = App::Meta::Url(location, Meta::UrlType::website);
if (typeAsString == "website") {
newUrl.type = Meta::UrlType::website;
}
else if (typeAsString == "repository") {
newUrl.type = Meta::UrlType::repository;
newUrl.branch = branch;
}
else if (typeAsString == "bugtracker") {
newUrl.type = Meta::UrlType::bugtracker;
}
else if (typeAsString == "readme") {
newUrl.type = Meta::UrlType::readme;
}
else if (typeAsString == "documentation") {
newUrl.type = Meta::UrlType::documentation;
}
else {
PyErr_SetString(Base::PyExc_FC_GeneralError, "Unrecognized URL type");
return;
}
getMetadataPtr()->addUrl(newUrl);
}
}
App::Meta::Url urlFromStrings(const char* urlTypeCharStar, const char* link, const char* branch)
{
std::string urlTypeString(urlTypeCharStar);
App::Meta::UrlType urlType;
if (urlTypeString == "repository")
urlType = App::Meta::UrlType::repository;
else if (urlTypeString == "bugtracker")
urlType = App::Meta::UrlType::bugtracker;
else if (urlTypeString == "documentation")
urlType = App::Meta::UrlType::documentation;
else if (urlTypeString == "readme")
urlType = App::Meta::UrlType::readme;
else if (urlTypeString == "website")
urlType = App::Meta::UrlType::website;
App::Meta::Url url(link, urlType);
if (urlType == App::Meta::UrlType::repository)
url.branch = std::string(branch);
return url;
}
PyObject *MetadataPy::addUrl(PyObject *args)
{
const char *urlTypeCharStar = nullptr;
const char *link = nullptr;
const char *branch = nullptr;
if (!PyArg_ParseTuple(args, "ss|s", &urlTypeCharStar, &link, &branch))
throw Py::Exception();
getMetadataPtr()->addUrl(urlFromStrings(urlTypeCharStar, link, branch));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeUrl(PyObject *args)
{
const char *urlTypeCharStar = nullptr;
const char *link = nullptr;
const char *branch = nullptr;
if (!PyArg_ParseTuple(args, "ss|s", &urlTypeCharStar, &link, &branch))
throw Py::Exception();
getMetadataPtr()->removeUrl(urlFromStrings(urlTypeCharStar, link, branch));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object dependencyToPyObject(const Meta::Dependency &d)
{
Py::Dict pyDependency;
pyDependency["package"] = Py::String(d.package);
@@ -197,90 +429,338 @@ Py::Object dependencyToPyObject(const Meta::Dependency& d)
pyDependency["version_gt"] = Py::String(d.version_gt);
pyDependency["version_gte"] = Py::String(d.version_gte);
pyDependency["condition"] = Py::String(d.condition);
pyDependency["optional"] = Py::Boolean(d.optional);
switch (d.dependencyType) {
case App::Meta::DependencyType::automatic:
pyDependency["type"] = Py::String ("automatic");
break;
case App::Meta::DependencyType::addon:
pyDependency["type"] = Py::String("addon");
break;
case App::Meta::DependencyType::internal:
pyDependency["type"] = Py::String("internal");
break;
case App::Meta::DependencyType::python:
pyDependency["type"] = Py::String("python");
break;
}
return pyDependency;
}
Meta::Dependency pyObjectToDependency(const Py::Object &d)
{
Py::Dict pyDependency(d);
Meta::Dependency result;
result.package = pyDependency["package"].str();
if (pyDependency.hasKey("version_lt"))
result.version_lt = pyDependency["version_lt"].str();
if (pyDependency.hasKey("version_lte"))
result.version_lte = pyDependency["version_lte"].str();
if (pyDependency.hasKey("version_eq"))
result.version_eq = pyDependency["version_eq"].str();
if (pyDependency.hasKey("version_gt"))
result.version_gt = pyDependency["version_gt"].str();
if (pyDependency.hasKey("version_gte"))
result.version_gte = pyDependency["version_gte"].str();
if (pyDependency.hasKey("condition"))
result.condition = pyDependency["condition"].str();
if (pyDependency.hasKey("optional"))
result.optional = Py::Boolean(pyDependency["optional"]).as_bool();
if (pyDependency.hasKey("type")) {
if (pyDependency["type"].str() == Py::String("automatic"))
result.dependencyType = App::Meta::DependencyType::automatic;
else if (pyDependency["type"].str() == Py::String("internal"))
result.dependencyType = App::Meta::DependencyType::internal;
else if (pyDependency["type"].str() == Py::String("addon"))
result.dependencyType = App::Meta::DependencyType::addon;
else if (pyDependency["type"].str() == Py::String("python"))
result.dependencyType = App::Meta::DependencyType::python;
}
return result;
}
Py::Object MetadataPy::getDepend() const
{
auto dependencies = getMetadataPtr()->depend();
Py::List pyDependencies;
for (const auto& d : dependencies) {
for (const auto &d : dependencies) {
pyDependencies.append(dependencyToPyObject(d));
}
return pyDependencies;
}
void MetadataPy::setDepend(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearDepend();
Py::List deps(list);
for (const auto &dep : deps) {
Py::Dict pyDep(dep);
getMetadataPtr()->addDepend(pyObjectToDependency(pyDep));
}
}
PyObject *MetadataPy::addDepend(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->addDepend(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeDepend(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->removeDepend(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getConflict() const
{
auto dependencies = getMetadataPtr()->conflict();
Py::List pyDependencies;
for (const auto& d : dependencies) {
for (const auto &d : dependencies) {
pyDependencies.append(dependencyToPyObject(d));
}
return pyDependencies;
}
void MetadataPy::setConflict(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearConflict();
Py::List deps(list);
for (const auto &dep : deps) {
Py::Dict pyDep(dep);
getMetadataPtr()->addConflict(pyObjectToDependency(pyDep));
}
}
PyObject *MetadataPy::addConflict(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->addConflict(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeConflict(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->removeConflict(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getReplace() const
{
auto dependencies = getMetadataPtr()->replace();
Py::List pyDependencies;
for (const auto& d : dependencies) {
for (const auto &d : dependencies) {
pyDependencies.append(dependencyToPyObject(d));
}
return pyDependencies;
}
void MetadataPy::setReplace(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearReplace();
Py::List deps(list);
for (const auto &dep : deps) {
Py::Dict pyDep(dep);
getMetadataPtr()->addReplace(pyObjectToDependency(pyDep));
}
}
PyObject *MetadataPy::addReplace(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->addReplace(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeReplace(PyObject *args)
{
PyObject *dictionary = nullptr;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dictionary))
throw Py::Exception();
Py::Dict pyDep(dictionary);
getMetadataPtr()->removeReplace(pyObjectToDependency(pyDep));
Py_INCREF(Py_None);
return Py_None;
}
// Tag, icon, classname, file
Py::Object MetadataPy::getTag() const
{
auto tags = getMetadataPtr()->tag();
Py::List pyTags;
for (const auto& t : tags) {
for (const auto &t : tags) {
pyTags.append(Py::String(t));
}
return pyTags;
}
void MetadataPy::setTag(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearTag();
Py::List tags(list);
for (const auto &tag : tags) {
Py::String pyTag(tag);
getMetadataPtr()->addTag(pyTag.as_std_string());
}
}
PyObject *MetadataPy::addTag(PyObject *args)
{
const char *tag = nullptr;
if (!PyArg_ParseTuple(args, "s", &tag))
throw Py::Exception();
getMetadataPtr()->addTag(tag);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeTag(PyObject *args)
{
const char *tag = nullptr;
if (!PyArg_ParseTuple(args, "s", &tag))
throw Py::Exception();
getMetadataPtr()->removeTag(tag);
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getIcon() const
{
return Py::String(getMetadataPtr()->icon().string());
}
void MetadataPy::setIcon(Py::Object args)
{
const char *name;
if (!PyArg_Parse(args.ptr(), "s", &name))
throw Py::Exception();
getMetadataPtr()->setIcon(name);
}
Py::Object MetadataPy::getClassname() const
{
return Py::String(getMetadataPtr()->classname());
}
void MetadataPy::setClassname(Py::Object args)
{
const char *name;
if (!PyArg_Parse(args.ptr(), "s", &name))
throw Py::Exception();
getMetadataPtr()->setClassname(name);
}
Py::Object MetadataPy::getSubdirectory() const
{
return Py::String(getMetadataPtr()->subdirectory().string());
}
void MetadataPy::setSubdirectory(Py::Object args)
{
const char *name;
if (!PyArg_Parse(args.ptr(), "s", &name))
throw Py::Exception();
getMetadataPtr()->setSubdirectory(name);
}
Py::Object MetadataPy::getFile() const
{
auto files = getMetadataPtr()->file();
Py::List pyFiles;
for (const auto& f : files) {
for (const auto &f : files) {
pyFiles.append(Py::String(f.string()));
}
return pyFiles;
}
void MetadataPy::setFile(Py::Object args)
{
PyObject *list = nullptr;
if (!PyArg_Parse(args.ptr(), "O!", &PyList_Type, &list))
throw Py::Exception();
getMetadataPtr()->clearTag();
Py::List files(list);
for (const auto &file : files) {
Py::String pyFile(file);
getMetadataPtr()->addFile(pyFile.as_std_string());
}
}
PyObject *MetadataPy::addFile(PyObject *args)
{
const char *file = nullptr;
if (!PyArg_ParseTuple(args, "s", &file))
throw Py::Exception();
getMetadataPtr()->addFile(file);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeFile(PyObject *args)
{
const char *file = nullptr;
if (!PyArg_ParseTuple(args, "s", &file))
throw Py::Exception();
getMetadataPtr()->removeFile(file);
Py_INCREF(Py_None);
return Py_None;
}
Py::Object MetadataPy::getContent() const
{
auto content = getMetadataPtr()->content();
std::set<std::string> keys;
for (const auto& item : content) {
for (const auto &item : content) {
keys.insert(item.first);
}
// For the Python, we'll use a dictionary of lists to store the content components:
Py::Dict pyContent;
for (const auto& key : keys) {
for (const auto &key : keys) {
Py::List pyContentForKey;
auto elements = content.equal_range(key);
for (auto & element = elements.first; element != elements.second; ++element) {
for (auto &element = elements.first; element != elements.second; ++element) {
auto contentMetadataItem = new MetadataPy(new Metadata(element->second));
pyContentForKey.append(Py::asObject(contentMetadataItem));
}
@@ -289,19 +769,38 @@ Py::Object MetadataPy::getContent() const
return pyContent;
}
PyObject* MetadataPy::getGenericMetadata(PyObject* args)
void MetadataPy::setContent(Py::Object arg)
{
const char* name;
PyObject *obj = nullptr;
if (!PyArg_Parse(arg.ptr(), "O!", &PyList_Type, &obj))
throw Py::Exception();
getMetadataPtr()->clearContent();
Py::Dict outerDict(obj);
for (const auto &pyContentType : outerDict) {
auto contentType = Py::String(pyContentType.first).as_std_string();
auto contentList = Py::List(pyContentType.second);
for (const auto& contentItem : contentList) {
auto item = static_cast<MetadataPy *>(contentItem.ptr());
getMetadataPtr()->addContentItem(contentType, *(item->getMetadataPtr()));
}
}
}
PyObject *MetadataPy::getGenericMetadata(PyObject *args)
{
const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return nullptr;
auto gm = (*getMetadataPtr())[name];
Py::List pyGenericMetadata;
for (const auto& item : gm) {
for (const auto &item : gm) {
Py::Dict pyItem;
pyItem["contents"] = Py::String(item.contents);
Py::Dict pyAttributes;
for (const auto& attribute : item.attributes) {
for (const auto &attribute : item.attributes) {
pyAttributes[attribute.first] = Py::String(attribute.second);
}
pyItem["attributes"] = pyAttributes;
@@ -317,12 +816,14 @@ Py::Object MetadataPy::getFreeCADMin() const
void MetadataPy::setFreeCADMin(Py::Object args)
{
char* version = nullptr;
PyObject* p = args.ptr();
if (!PyArg_ParseTuple(p, "s", &version))
return;
getMetadataPtr()->setFreeCADMin(App::Meta::Version(version));
char *version = nullptr;
PyObject *p = args.ptr();
if (!PyArg_Parse(p, "z", &version))
throw Py::Exception();
if (version)
getMetadataPtr()->setFreeCADMin(App::Meta::Version(version));
else
getMetadataPtr()->setFreeCADMin(App::Meta::Version());
}
Py::Object MetadataPy::getFreeCADMax() const
@@ -332,15 +833,18 @@ Py::Object MetadataPy::getFreeCADMax() const
void MetadataPy::setFreeCADMax(Py::Object args)
{
char* version = nullptr;
PyObject* p = args.ptr();
if (!PyArg_ParseTuple(p, "s", &version))
return;
char *version = nullptr;
PyObject *p = args.ptr();
if (!PyArg_Parse(p, "z", &version))
throw Py::Exception();
getMetadataPtr()->setFreeCADMax(App::Meta::Version(version));
if (version)
getMetadataPtr()->setFreeCADMax(App::Meta::Version(version));
else
getMetadataPtr()->setFreeCADMax(App::Meta::Version());
}
PyObject* MetadataPy::getFirstSupportedFreeCADVersion(PyObject* p)
PyObject *MetadataPy::getFirstSupportedFreeCADVersion(PyObject *p)
{
if (!PyArg_ParseTuple(p, ""))
return nullptr;
@@ -351,7 +855,7 @@ PyObject* MetadataPy::getFirstSupportedFreeCADVersion(PyObject* p)
auto content = getMetadataPtr()->content();
auto result = App::Meta::Version();
for (const auto& item : content) {
for (const auto &item : content) {
auto minVersion = item.second.freecadmin();
if (minVersion != App::Meta::Version())
if (result == App::Meta::Version() || minVersion < result)
@@ -366,7 +870,7 @@ PyObject* MetadataPy::getFirstSupportedFreeCADVersion(PyObject* p)
}
}
PyObject* MetadataPy::getLastSupportedFreeCADVersion(PyObject* p)
PyObject *MetadataPy::getLastSupportedFreeCADVersion(PyObject *p)
{
if (!PyArg_ParseTuple(p, ""))
return nullptr;
@@ -377,7 +881,7 @@ PyObject* MetadataPy::getLastSupportedFreeCADVersion(PyObject* p)
auto content = getMetadataPtr()->content();
auto result = App::Meta::Version();
for (const auto& item : content) {
for (const auto &item : content) {
auto maxVersion = item.second.freecadmax();
if (maxVersion != App::Meta::Version())
if (result == App::Meta::Version() || maxVersion > result)
@@ -392,7 +896,7 @@ PyObject* MetadataPy::getLastSupportedFreeCADVersion(PyObject* p)
}
}
PyObject* MetadataPy::supportsCurrentFreeCAD(PyObject* p)
PyObject *MetadataPy::supportsCurrentFreeCAD(PyObject *p)
{
if (!PyArg_ParseTuple(p, ""))
return nullptr;
@@ -401,12 +905,41 @@ PyObject* MetadataPy::supportsCurrentFreeCAD(PyObject* p)
return Py::new_reference_to(Py::Boolean(result));
}
PyObject* MetadataPy::getCustomAttributes(const char* /*attr*/) const
PyObject* MetadataPy::addContentItem(PyObject* arg)
{
char *contentType = nullptr;
PyObject *contentItem = nullptr;
if (!PyArg_ParseTuple(arg, "sO!", &contentType, &(App::MetadataPy::Type), &contentItem))
return nullptr;
if (!contentItem || !contentType)
return nullptr;
auto item = static_cast<MetadataPy *>(contentItem);
getMetadataPtr()->addContentItem(contentType, *(item->getMetadataPtr()));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::removeContentItem(PyObject *arg)
{
char *contentType = nullptr;
char *contentName = nullptr;
if (!PyArg_ParseTuple(arg, "ss", &contentType, &contentName))
return nullptr;
if (contentType && contentName)
getMetadataPtr()->removeContentItem(contentType, contentName);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *MetadataPy::getCustomAttributes(const char * /*attr*/) const
{
return nullptr;
}
int MetadataPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
int MetadataPy::setCustomAttributes(const char * /*attr*/, PyObject * /*obj*/)
{
return 0;
}