Update to LOOT API v0.11.0

This is a breaking change:
- LanguageCode has been removed
- The SimpleMessage Python class is now "SimpleMessage", from "Message"
- DatabaseInterface::sort_plugins() has been removed
- DatabaseInterface::get_plugin_messages() has been replaced with
DatabaseInterface::get_plugin_metadata() followed by
PluginMetadata::get_simple_messages()
- set_logging_verbosity(), set_log_file() and initialise_locale() have
been added

Not everything in the v0.11 API has been wrapped, to limit the potential
for future breaking changes.

The PluginTags struct and PluginCleanliness enum and their associated
functions have been re-implemented as part of the Python wrapper as they
were removed from the API due to no longer exposing any additional
functionality but are still useful.
This commit is contained in:
Oliver Hamlet
2017-05-13 08:41:42 +01:00
parent 2823db915a
commit a94fb19bde
8 changed files with 302 additions and 55 deletions
+50 -37
View File
@@ -26,29 +26,16 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "convenience.h"
#include "wrapper_version.h"
PYBIND11_PLUGIN(loot_api) {
using loot::CreateDatabase;
using loot::DatabaseInterface;
using loot::IsCompatible;
using loot::GameType;
using loot::LanguageCode;
using loot::LootVersion;
using loot::MessageType;
using loot::MasterlistInfo;
using loot::PluginCleanliness;
using loot::SimpleMessage;
using loot::PluginTags;
using loot::WrapperVersion;
using pybind11::arg;
using pybind11::enum_;
using pybind11::class_;
using pybind11::metaclass;
pybind11::module module("loot_api", "A Python module that wraps the LOOT API, generated by pybind11.");
using pybind11::arg;
using pybind11::enum_;
using pybind11::class_;
using pybind11::metaclass;
namespace loot {
void bindEnums(pybind11::module& module) {
enum_<GameType>(module, "GameType")
.value("tes4", GameType::tes4)
.value("tes5", GameType::tes5)
@@ -57,18 +44,10 @@ PYBIND11_PLUGIN(loot_api) {
.value("fonv", GameType::fonv)
.value("fo4", GameType::fo4);
enum_<LanguageCode>(module, "LanguageCode")
.value("english", LanguageCode::english)
.value("spanish", LanguageCode::spanish)
.value("russian", LanguageCode::russian)
.value("french", LanguageCode::french)
.value("chinese", LanguageCode::chinese)
.value("polish", LanguageCode::polish)
.value("brazilian_portuguese", LanguageCode::brazilian_portuguese)
.value("finnish", LanguageCode::finnish)
.value("german", LanguageCode::german)
.value("danish", LanguageCode::danish)
.value("korean", LanguageCode::korean);
enum_<LogVerbosity>(module, "LogVerbosity")
.value("off", LogVerbosity::off)
.value("trace", LogVerbosity::trace)
.value("warning", LogVerbosity::warning);
enum_<MessageType>(module, "MessageType")
.value("say", MessageType::say)
@@ -80,13 +59,15 @@ PYBIND11_PLUGIN(loot_api) {
.value("dirty", PluginCleanliness::dirty)
.value("do_not_clean", PluginCleanliness::do_not_clean)
.value("unknown", PluginCleanliness::unknown);
}
void bindMetadataClasses(pybind11::module& module) {
class_<MasterlistInfo>(module, "MasterlistInfo")
.def_readwrite("revision_id", &MasterlistInfo::revision_id)
.def_readwrite("revision_date", &MasterlistInfo::revision_date)
.def_readwrite("is_modified", &MasterlistInfo::is_modified);
class_<SimpleMessage>(module, "Message")
class_<SimpleMessage>(module, "SimpleMessage")
.def_readwrite("type", &SimpleMessage::type)
.def_readwrite("language", &SimpleMessage::language)
.def_readwrite("text", &SimpleMessage::text);
@@ -96,6 +77,11 @@ PYBIND11_PLUGIN(loot_api) {
.def_readwrite("removed", &PluginTags::removed)
.def_readwrite("userlist_modified", &PluginTags::userlist_modified);
class_<PluginMetadata>(module, "PluginMetadata")
.def("get_simple_messages", &PluginMetadata::GetSimpleMessages);
}
void bindVersionClasses(pybind11::module& module) {
class_<LootVersion>(module, "Version", metaclass())
.def_readonly_static("major", &LootVersion::major)
.def_readonly_static("minor", &LootVersion::minor)
@@ -109,21 +95,48 @@ PYBIND11_PLUGIN(loot_api) {
.def_readonly_static("patch", &WrapperVersion::patch)
.def_readonly_static("revision", &WrapperVersion::revision)
.def_static("string", WrapperVersion::string);
}
void bindInterfaceClasses(pybind11::module& module) {
class_<DatabaseInterface, std::shared_ptr<DatabaseInterface>>(module, "DatabaseInterface")
.def("load_lists", &DatabaseInterface::LoadLists, arg("masterlist_path"), arg("userlist_path") = "")
.def("eval_lists", &DatabaseInterface::EvalLists)
.def("sort_plugins", &DatabaseInterface::SortPlugins)
.def("update_masterlist", &DatabaseInterface::UpdateMasterlist)
.def("get_masterlist_revision", &DatabaseInterface::GetMasterlistRevision)
.def("get_plugin_tags", &DatabaseInterface::GetPluginTags)
.def("get_plugin_messages", &DatabaseInterface::GetPluginMessages)
.def("get_plugin_cleanliness", &DatabaseInterface::GetPluginCleanliness)
.def("get_plugin_metadata", &DatabaseInterface::GetPluginMetadata,
arg("plugin"),
arg("includeUserMetadata") = true,
arg("evaluateConditions") = false)
.def("get_plugin_tags", &GetPluginTags)
.def("get_plugin_cleanliness", &GetPluginCleanliness)
.def("write_minimal_list", &DatabaseInterface::WriteMinimalList);
}
void bindClasses(pybind11::module& module) {
bindMetadataClasses(module);
bindVersionClasses(module);
bindInterfaceClasses(module);
}
void bindFunctions(pybind11::module& module) {
module.def("set_logging_verbosity", &SetLoggingVerbosity);
module.def("set_log_file", &SetLogFile);
module.def("is_compatible", &IsCompatible);
module.def("initialise_locale", &InitialiseLocale);
module.def("create_database", &CreateDatabase, arg("game"), arg("game_path") = "", arg("game_local_path") = "");
}
}
PYBIND11_PLUGIN(loot_api) {
pybind11::module module("loot_api", "A Python module that wraps the LOOT API, generated by pybind11.");
loot::bindEnums(module);
loot::bindClasses(module);
loot::bindFunctions(module);
return module.ptr();
}