Skip to content

Commit

Permalink
Merge branch 'wheel-create-output-dir' into 'master'
Browse files Browse the repository at this point in the history
Wheel create output dir

See merge request ogs/ogs!5118
  • Loading branch information
bilke committed Sep 26, 2024
2 parents 4aa2fc4 + 431fc2b commit b07c464
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
19 changes: 3 additions & 16 deletions Applications/CLI/ogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
*
*/

#include <algorithm>
#include <pybind11/pybind11.h>
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>

#include <algorithm>
#include <chrono>
#include <filesystem>
#include <sstream>

#include "CommandLineArgumentParser.h"
Expand All @@ -36,6 +35,7 @@
#include "Applications/ApplicationsLib/TestDefinition.h"
#include "BaseLib/DateTools.h"
#include "BaseLib/Error.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/RunTime.h"
#include "InfoLib/GitInfo.h"
Expand Down Expand Up @@ -67,20 +67,7 @@ int main(int argc, char* argv[])
INFO("This is OpenGeoSys-6 version {:s}.",
GitInfoLib::GitInfo::ogs_version);

if (cli_arg.outdir.length() > 0)
{
std::error_code mkdir_err;
if (std::filesystem::create_directories(cli_arg.outdir, mkdir_err))
{
INFO("Output directory {:s} created.", cli_arg.outdir);
}
else if (mkdir_err.value() != 0)
{
WARN(
"Could not create output directory {:s}. Error code {:d}, {:s}",
cli_arg.outdir, mkdir_err.value(), mkdir_err.message());
}
}
BaseLib::createOutputDirectory(cli_arg.outdir);

{
auto const start_time = std::chrono::system_clock::now();
Expand Down
5 changes: 4 additions & 1 deletion Applications/Python/ogs.simulator/ogs_python_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
*
*/

#include <algorithm>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>

#include <algorithm>

#include "../ogs.mesh/OGSMesh.h"
#include "Applications/ApplicationsLib/Simulation.h"
#include "Applications/ApplicationsLib/TestDefinition.h"
Expand Down Expand Up @@ -72,6 +73,8 @@ int initOGS(std::vector<std::string>& argv_str)
INFO("This is OpenGeoSys-6 version {:s}.",
GitInfoLib::GitInfo::ogs_version);

BaseLib::createOutputDirectory(cli_args.outdir);

{
auto const start_time = std::chrono::system_clock::now();
auto const time_str = BaseLib::formatDate(start_time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>

#include <filesystem>

#ifdef USE_PETSC
#include <mpi.h>
#endif
Expand Down Expand Up @@ -118,20 +116,7 @@ int main(int argc, char* argv[])
});

const auto output_directory = output_directory_arg.getValue();
if (output_directory.length() > 0)
{
std::error_code mkdir_err;
if (std::filesystem::create_directories(output_directory, mkdir_err))
{
INFO("Output directory {:s} created.", output_directory);
}
else if (mkdir_err.value() != 0)
{
WARN(
"Could not create output directory {:s}. Error code {:d}, {:s}",
output_directory, mkdir_err.value(), mkdir_err.message());
}
}
BaseLib::createOutputDirectory(output_directory);

BaseLib::RunTime run_timer;
run_timer.start();
Expand Down
21 changes: 21 additions & 0 deletions BaseLib/FileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ void removeFiles(std::vector<std::string> const& files)
}
}

bool createOutputDirectory(std::string const& dir)
{
if (dir.empty())
{
return false;
}

std::error_code mkdir_err;
if (std::filesystem::create_directories(dir, mkdir_err))
{
INFO("Output directory {:s} created.", dir);
}
else if (mkdir_err.value() != 0)
{
WARN("Could not create output directory {:s}. Error code {:d}, {:s}",
dir, mkdir_err.value(), mkdir_err.message());
return false;
}
return true;
}

template <typename T>
T readBinaryValue(std::istream& in)
{
Expand Down
3 changes: 3 additions & 0 deletions BaseLib/FileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,7 @@ void removeFile(std::string const& filename);
/// Remove files. If a file does not exist nothing will happen, other errors
/// lead to OGS_FATAL call.
void removeFiles(std::vector<std::string> const& files);

// Creates the given directory. Returns true on success.
bool createOutputDirectory(std::string const& dir);
} // end namespace BaseLib

0 comments on commit b07c464

Please sign in to comment.