forked from ros2/rosbag2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcel Zeilinger
committed
Mar 1, 2020
1 parent
fafbe76
commit d4e13aa
Showing
8 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime | ||
import os | ||
|
||
from ros2bag.verb import VerbExtension | ||
|
||
|
||
class ConvertVerb(VerbExtension): | ||
"""ros2 bag convert.""" | ||
|
||
def add_arguments(self, parser, cli_name): # noqa: D102 | ||
parser.add_argument( | ||
'bag_file', help='bag file to convert') | ||
parser.add_argument( | ||
'-o', '--output', | ||
help='destination of the bagfile to create, \ | ||
defaults to a timestamped folder in the current directory') | ||
parser.add_argument( | ||
'-s', '--storage', default='sqlite3', | ||
help='storage identifier to be used for the input bag, defaults to "sqlite3"') | ||
parser.add_argument( | ||
'--out-storage', default='sqlite3', | ||
help='storage identifier to be used for the output bag, defaults to "sqlite3"') | ||
parser.add_argument( | ||
'-f', '--serialization-format', default='', | ||
help='rmw serialization format in which the messages are saved, defaults to the' | ||
' rmw currently in use') | ||
|
||
def create_bag_directory(self, uri): | ||
try: | ||
os.makedirs(uri) | ||
except OSError: | ||
return "[ERROR] [ros2bag]: Could not create bag folder '{}'.".format(uri) | ||
|
||
def main(self, *, args): # noqa: D102 | ||
bag_file = args.bag_file | ||
if not os.path.exists(bag_file): | ||
return "[ERROR] [ros2bag] bag file '{}' does not exist!".format(bag_file) | ||
|
||
uri = args.output or datetime.datetime.now().strftime('rosbag2_%Y_%m_%d-%H_%M_%S') | ||
self.create_bag_directory(uri) | ||
|
||
# NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups | ||
# combined with constrained environments (as imposed by colcon test) | ||
# may result in DLL loading failures when attempting to import a C | ||
# extension. Therefore, do not import rosbag2_transport at the module | ||
# level but on demand, right before first use. | ||
from rosbag2_transport import rosbag2_transport_py | ||
|
||
rosbag2_transport_py.convert( | ||
in_uri=bag_file, | ||
in_storage_id=args.storage, | ||
out_uri=uri, | ||
out_storage_id=args.out_storage, | ||
serialization_format=args.serialization_format) | ||
|
||
if os.path.isdir(uri) and not os.listdir(uri): | ||
os.rmdir(uri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "converter.hpp" | ||
|
||
#include "rosbag2_cpp/reader.hpp" | ||
#include "rosbag2_cpp/writer.hpp" | ||
#include "rosbag2_transport/logging.hpp" | ||
|
||
namespace rosbag2_transport | ||
{ | ||
Converter::Converter( | ||
std::shared_ptr<rosbag2_cpp::Reader> reader, | ||
std::shared_ptr<rosbag2_cpp::Writer> writer) | ||
: reader_(std::move(reader)), writer_(std::move(writer)) {} | ||
|
||
void Converter::convert(std::string serialization_format) | ||
{ | ||
for (auto topic : reader_->get_all_topics_and_types()) { | ||
topic.serialization_format = serialization_format; | ||
writer_->create_topic(topic); | ||
} | ||
while (reader_->has_next()) { | ||
auto msg = reader_->read_next(); | ||
writer_->write(msg); | ||
} | ||
} | ||
|
||
} // namespace rosbag2_transport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2018 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef ROSBAG2_TRANSPORT__CONVERTER_HPP_ | ||
#define ROSBAG2_TRANSPORT__CONVERTER_HPP_ | ||
|
||
#include <future> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "rosbag2_cpp/types.hpp" | ||
#include "rosbag2_cpp/reader.hpp" | ||
#include "rosbag2_cpp/writer.hpp" | ||
#include "rosbag2_transport/storage_options.hpp" | ||
|
||
namespace rosbag2 | ||
{ | ||
class Writer; | ||
class Reader; | ||
} | ||
|
||
namespace rosbag2_transport | ||
{ | ||
|
||
class Converter | ||
{ | ||
public: | ||
explicit Converter( | ||
std::shared_ptr<rosbag2_cpp::Reader> reader, | ||
std::shared_ptr<rosbag2_cpp::Writer> writer); | ||
|
||
void convert(std::string serialization_format); | ||
|
||
private: | ||
std::shared_ptr<rosbag2_cpp::Reader> reader_; | ||
std::shared_ptr<rosbag2_cpp::Writer> writer_; | ||
}; | ||
|
||
} // namespace rosbag2_transport | ||
|
||
#endif // ROSBAG2_TRANSPORT__CONVERTER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters