Permalink
Browse files

delete existing files with ros2gams

  • Loading branch information...
auerj committed Aug 20, 2018
1 parent e6dd44e commit 76b61a8c72438844b1ea270ddd2c226918a0895b
Showing with 53 additions and 4 deletions.
  1. +1 −1 gams.mpc
  2. +32 −3 src/gams/programs/ros2gams.cpp
  3. +20 −0 using_filesystem.mpb
@@ -213,7 +213,7 @@ project (gams_controller) : using_gams, using_madara, using_vrep {
}
}
project (ros2gams) : using_madara, using_ros, using_gams, using_capnp, using_simtime {
project (ros2gams) : using_madara, using_ros, using_gams, using_capnp, using_simtime, using_boost, using_filesystem {
exeout = $(GAMS_ROOT)/bin
exename = ros2gams
libpaths += $(ROS_ROOT)/../../lib
@@ -9,6 +9,10 @@
#include <string>
#include <fstream>
#include "boost/filesystem.hpp"
#include "yaml-cpp/yaml.h"
#include "madara/logger/GlobalLogger.h"
#include "madara/knowledge/KnowledgeBase.h"
#include "madara/knowledge/CheckpointStreamer.h"
@@ -56,7 +60,6 @@
#include <tf2_msgs/TFMessage.h>
#include <std_msgs/String.h>
#include "yaml-cpp/yaml.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
@@ -105,9 +108,12 @@ int checkpoint_frequency = 0;
bool differential_checkpoints = false;
bool same_file = false;
// Delete existing files
bool delete_existing = false;
//Function definitions
void delete_existing_file(std::string path, bool delete_existing);
int save_checkpoint (knowledge::KnowledgeBase *knowledge,
knowledge::CheckpointSettings *settings, std::string meta_prefix="meta");
std::string get_agent_var_prefix (std::string ros_topic_name);
@@ -174,6 +180,10 @@ void handle_arguments (int argc, char ** argv)
differential_checkpoints = true;
same_file = true;
}
else if (arg1 == "-de" || arg1 == "--delete-existing")
{
delete_existing = true;
}
else if (arg1 == "-y" || arg1 == "--frequency")
{
checkpoint_frequency = std::stoi(argv[i + 1]);
@@ -214,7 +224,8 @@ void handle_arguments (int argc, char ** argv)
" continuously stored in the same \n" \
" file - only for binary checkpoints\n" \
" [-ss|--save-size bytes] size of buffer needed for file saves\n" \
" [-stk|--stream file] stream checkpoints to file\n";
" [-stk|--stream file] stream checkpoints to file\n"\
" [-de|--delete-existing] delete existing output files\n";
exit (0);
}
}
@@ -386,6 +397,8 @@ int main (int argc, char ** argv)
{
madara::knowledge::CheckpointSettings stream_settings;
stream_settings.filename = stream_file + ".stk";
delete_existing_file(stream_settings.filename, delete_existing);
//kb.attach_streamer(std::move(stream_settings), kb, 100);
//Todo: above is from the doc - below is from the tests
kb.attach_streamer(madara::utility::mk_unique<
@@ -509,18 +522,22 @@ int save_checkpoint (knowledge::KnowledgeBase * knowledge,
if ( save_as_karl )
{
settings->filename = filename + ".mf";
delete_existing_file(settings->filename, delete_existing);
ret = knowledge->save_as_karl (*settings);
}
if ( save_as_json )
{
settings->filename = filename + ".json";
delete_existing_file(settings->filename, delete_existing);
ret = knowledge->save_as_json (*settings);
}
if ( save_as_binary )
{
settings->filename = filename + ".kb";
delete_existing_file(settings->filename, delete_existing);
if ( differential_checkpoints == true)
{
ret = knowledge->save_checkpoint (*settings);
@@ -560,3 +577,15 @@ std::string get_agent_var_prefix (std::string ros_topic_name)
}
void delete_existing_file(std::string path, bool delete_existing)
{
if (!delete_existing)
{
return;
}
if (boost::filesystem::is_regular_file(path))
{
boost::filesystem::remove(path);
}
}
@@ -0,0 +1,20 @@
project : using_boost {
expand(BOOST_FILESYSTEM_DEBUG) {
$BOOST_FILESYSTEM_DEBUG
$(BOOST_STATIC_LIB_PREFIX)boost_filesystem-$(BOOST_TOOLSET)-mt-gd-$(BOOST_ARCH)-$(BOOST_VERSION)
}
expand(BOOST_FILESYSTEM_RELEASE) {
$BOOST_FILESYSTEM_RELEASE
$(BOOST_STATIC_LIB_PREFIX)boost_filesystem-$(BOOST_TOOLSET)-mt-$(BOOST_ARCH)-$(BOOST_VERSION)
}
specific(prop:windows) {
Debug::lit_libs += $(BOOST_FILESYSTEM_DEBUG)
Release::lit_libs += $(BOOST_FILESYSTEM_RELEASE)
// end if windows build
} else {
lit_libs += $(BOOST_STATIC_LIB_PREFIX)boost_filesystem$(BOOST_CFG)
}
}

0 comments on commit 76b61a8

Please sign in to comment.