-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convert verb #306
Add convert verb #306
Changes from 4 commits
e7c7150
1100932
541761c
c370c0a
cb86a1d
939fa34
da6c184
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# 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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not completely sure a default for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In current master, the I would rename it to |
||
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') | ||
parser.add_argument( | ||
'--compression-mode', type=str, default='none', | ||
choices=['none', 'file', 'message'], | ||
help='Determine whether to compress by file or message. Default is "none".') | ||
parser.add_argument( | ||
'--compression-format', type=str, default='', choices=['zstd'], | ||
help='Specify the compression format/algorithm. Default is none.') | ||
|
||
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) | ||
|
||
if args.compression_format and args.compression_mode == 'none': | ||
return 'Invalid choice: Cannot specify compression format without a compression mode.' | ||
args.compression_mode = args.compression_mode.upper() | ||
|
||
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, | ||
compression_mode=args.compression_mode, | ||
compression_format=args.compression_format) | ||
|
||
if os.path.isdir(uri) and not os.listdir(uri): | ||
os.rmdir(uri) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018, Bosch Software Innovations GmbH. | ||
// | ||
// 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__CONVERT_OPTIONS_HPP_ | ||
#define ROSBAG2_TRANSPORT__CONVERT_OPTIONS_HPP_ | ||
|
||
#include <chrono> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace rosbag2_transport | ||
{ | ||
struct ConvertOptions | ||
{ | ||
public: | ||
std::string rmw_serialization_format; | ||
std::string compression_mode = ""; | ||
std::string compression_format = ""; | ||
}; | ||
|
||
} // namespace rosbag2_transport | ||
|
||
#endif // ROSBAG2_TRANSPORT__CONVERT_OPTIONS_HPP_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 <memory> | ||
#include <utility> | ||
#include <string> | ||
#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 |
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_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
year 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same below