Skip to content
Snippets Groups Projects
Commit cded1173 authored by Lars Bilke's avatar Lars Bilke Committed by Dmitri Naumov
Browse files

[ogs] Implemented xml patch functionality.

Added new argument --xml-patch (-p).
parent 86c74363
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,7 @@ target_link_libraries( ...@@ -62,6 +62,7 @@ target_link_libraries(
$<$<TARGET_EXISTS:MPI::MPI_CXX>:MPI::MPI_CXX> $<$<TARGET_EXISTS:MPI::MPI_CXX>:MPI::MPI_CXX>
$<$<TARGET_EXISTS:InSituLib>:InSituLib> $<$<TARGET_EXISTS:InSituLib>:InSituLib>
tclap tclap
xmlpatch
) )
target_compile_definitions( target_compile_definitions(
......
...@@ -10,8 +10,11 @@ ...@@ -10,8 +10,11 @@
* *
*/ */
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <tclap/CmdLine.h> #include <tclap/CmdLine.h>
#include <xml_patch.h>
#include <chrono> #include <chrono>
...@@ -78,6 +81,12 @@ int main(int argc, char* argv[]) ...@@ -78,6 +81,12 @@ int main(int argc, char* argv[])
"PROJECT_FILE"); "PROJECT_FILE");
cmd.add(project_arg); cmd.add(project_arg);
TCLAP::ValueArg<std::string> xml_patch_file(
"p", "xml-patch",
"the xml patch file which is applied to the PROJECT_FILE", false, "",
"XML_PATCH_FILE");
cmd.add(xml_patch_file);
TCLAP::ValueArg<std::string> outdir_arg("o", "output-directory", TCLAP::ValueArg<std::string> outdir_arg("o", "output-directory",
"the output directory to write to", "the output directory to write to",
false, "", "PATH"); false, "", "PATH");
...@@ -177,11 +186,74 @@ int main(int argc, char* argv[]) ...@@ -177,11 +186,74 @@ int main(int argc, char* argv[])
spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank)); spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank));
} }
#endif #endif
run_time.start(); run_time.start();
std::string prj_file;
// read diff
if (xml_patch_file.getValue() != "")
{
auto patch = xmlParseFile(xml_patch_file.getValue().c_str());
if (patch == NULL)
{
OGS_FATAL("Error reading XML diff file {:s}.",
xml_patch_file.getValue());
}
auto doc = xmlParseFile(project_arg.getValue().c_str());
if (doc == NULL)
{
OGS_FATAL("Error reading project file {:s}.",
project_arg.getValue());
}
auto node = xmlDocGetRootElement(patch);
int rc = 0;
for (node = node ? node->children : NULL; node;
node = node->next)
{
if (node->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((char*)node->name, "add"))
rc = xml_patch_add(doc, node);
else if (!strcmp((char*)node->name, "replace"))
rc = xml_patch_replace(doc, node);
else if (!strcmp((char*)node->name, "remove"))
rc = xml_patch_remove(doc, node);
else
rc = -1;
if (rc)
break;
}
if (rc != 0)
{
OGS_FATAL(
"Error while patching prj file {:s} with patch file "
"{:}.",
project_arg.getValue(), xml_patch_file.getValue());
}
prj_file =
BaseLib::joinPaths(outdir_arg.getValue(),
BaseLib::extractBaseNameWithoutExtension(
xml_patch_file.getValue()) +
".prj");
xmlSaveFile(prj_file.c_str(), doc);
xmlFreeDoc(doc);
xmlFreeDoc(patch);
xmlCleanupParser();
}
else
{
prj_file = project_arg.getValue();
}
auto project_config = BaseLib::makeConfigTree( auto project_config = BaseLib::makeConfigTree(
project_arg.getValue(), !nonfatal_arg.getValue(), prj_file, !nonfatal_arg.getValue(), "OpenGeoSysProject");
"OpenGeoSysProject");
BaseLib::setProjectDirectory( BaseLib::setProjectDirectory(
BaseLib::extractPath(project_arg.getValue())); BaseLib::extractPath(project_arg.getValue()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment