Skip to content

Commit 18ac98b

Browse files
authored
CLI Tools: openpmd-ls (#574)
Start adding command line interface (CLI) tools. The first tool is `openpmd-ls`, which has the same function as `ls` but specific for querying an openPMD data series. CLI argument parsing and tool functionality will be improved in the future.
1 parent 6edcfd1 commit 18ac98b

File tree

17 files changed

+438
-13
lines changed

17 files changed

+438
-13
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Features
2626
- ``Series::setSoftware()`` add second argument for version #657
2727
- free standing functions to query the API version and feature variants at runtime #665
2828
- expose ``determineFormat`` and ``suffix`` functions #684
29+
- CLI: add ``openpmd-ls`` tool #574
2930

3031
Bug Fixes
3132
"""""""""

CMakeLists.txt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ mark_as_advanced(BUILD_SHARED_LIBS)
9191
include(CTest)
9292
# automatically defines: BUILD_TESTING, default is ON
9393

94-
option(BUILD_EXAMPLES "Build the examples" ON)
94+
option(BUILD_CLI_TOOLS "Build the command line tools" ON)
95+
option(BUILD_EXAMPLES "Build the examples" ON)
9596

9697

9798
# Dependencies ################################################################
@@ -312,7 +313,8 @@ set(CORE_SOURCE
312313
src/backend/PatchRecord.cpp
313314
src/backend/PatchRecordComponent.cpp
314315
src/backend/Writable.cpp
315-
src/benchmark/mpi/OneDimensionalBlockSlicer.cpp)
316+
src/benchmark/mpi/OneDimensionalBlockSlicer.cpp
317+
src/helper/list_series.cpp)
316318
set(IO_SOURCE
317319
src/IO/AbstractIOHandlerHelper.cpp
318320
src/IO/DummyIOHandler.cpp
@@ -525,6 +527,7 @@ if(openPMD_HAVE_PYTHON)
525527
src/binding/python/Container.cpp
526528
src/binding/python/Dataset.cpp
527529
src/binding/python/Datatype.cpp
530+
src/binding/python/Helper.cpp
528531
src/binding/python/Iteration.cpp
529532
src/binding/python/IterationEncoding.cpp
530533
src/binding/python/Mesh.cpp
@@ -588,6 +591,10 @@ set(openPMD_TEST_NAMES
588591
SerialIO
589592
ParallelIO
590593
)
594+
# command line tools
595+
set(openPMD_CLI_TOOL_NAMES
596+
ls
597+
)
591598
# examples
592599
set(openPMD_EXAMPLE_NAMES
593600
1_structure
@@ -653,6 +660,13 @@ if(BUILD_TESTING)
653660
endforeach()
654661
endif()
655662

663+
if(BUILD_CLI_TOOLS)
664+
foreach(toolname ${openPMD_CLI_TOOL_NAMES})
665+
add_executable(openpmd-${toolname} src/cli/${toolname}.cpp)
666+
target_link_libraries(openpmd-${toolname} PRIVATE openPMD)
667+
endforeach()
668+
endif()
669+
656670
if(BUILD_EXAMPLES)
657671
foreach(examplename ${openPMD_EXAMPLE_NAMES})
658672
if(${examplename} MATCHES ".+parallel$")
@@ -761,6 +775,12 @@ if(openPMD_HAVE_ADIOS1)
761775
openPMD.ADIOS1.Serial openPMD.ADIOS1.Parallel)
762776
endif()
763777

778+
if(BUILD_CLI_TOOLS)
779+
foreach(toolname ${openPMD_CLI_TOOL_NAMES})
780+
list(APPEND openPMD_INSTALL_TARGET_NAMES openpmd-${toolname})
781+
endforeach()
782+
endif()
783+
764784
install(TARGETS ${openPMD_INSTALL_TARGET_NAMES}
765785
EXPORT openPMDTargets
766786
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -919,6 +939,25 @@ if(BUILD_EXAMPLES)
919939
endif()
920940
endif()
921941

942+
# Command Line Tools ##################################################
943+
#
944+
if(BUILD_CLI_TOOLS)
945+
# all tools must provide a "--help"
946+
foreach(toolname ${openPMD_CLI_TOOL_NAMES})
947+
list(APPEND openPMD_INSTALL_TARGET_NAMES openpmd-${toolname})
948+
add_test(NAME CLI.help.${toolname}
949+
COMMAND openpmd-${toolname} --help
950+
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
951+
)
952+
endforeach()
953+
if(openPMD_HAVE_HDF5 AND EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")
954+
add_test(NAME CLI.ls
955+
COMMAND openpmd-ls ../samples/git-sample/data%08T.h5
956+
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
957+
)
958+
endif()
959+
endif()
960+
922961
# Python Examples
923962
# Current examples all use HDF5, elaborate if other backends are used
924963
if(openPMD_HAVE_PYTHON AND openPMD_HAVE_HDF5)

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ RUN ls -hal /usr/local/lib/python3.7/dist-packages/
139139
# RUN objdump -x /usr/local/lib/python3.7/dist-packages/openpmd_api.cpython-37m-x86_64-linux-gnu.so | grep RPATH
140140
RUN ldd /usr/local/lib/python3.7/dist-packages/openpmd_api.cpython-37m-x86_64-linux-gnu.so
141141
RUN python3 -c "import openpmd_api as api; print(api.__version__); print(api.variants)"
142+
#RUN openpmd-ls --help
142143
#RUN echo "* soft core 100000" >> /etc/security/limits.conf && \
143144
# python3 -c "import openpmd_api as api;"; \
144145
# gdb -ex bt -c core
@@ -167,6 +168,7 @@ RUN python3 --version \
167168
&& python3 -m pip install -U pip \
168169
&& python3 -m pip install openPMD_api-*-cp36-cp36m-manylinux2010_x86_64.whl
169170
RUN python3 -c "import openpmd_api as api; print(api.__version__); print(api.variants)"
171+
#RUN openpmd-ls --help
170172

171173
# test in fresh env: Debian:Stretch + Python 3.5
172174
FROM debian:stretch
@@ -179,6 +181,7 @@ RUN python3 --version \
179181
&& python3 -m pip install -U pip \
180182
&& python3 -m pip install openPMD_api-*-cp35-cp35m-manylinux2010_x86_64.whl
181183
RUN python3 -c "import openpmd_api as api; print(api.__version__); print(api.variants)"
184+
#RUN openpmd-ls --help
182185

183186

184187
# copy binary artifacts (wheels)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ You can only build a static or a shared library at a time.
248248
By default, the `Release` version is built.
249249
In order to build with debug symbols, pass `-DCMAKE_BUILD_TYPE=Debug` to your `cmake` command.
250250

251-
By default, tests and examples are built.
252-
In order to skip building those, pass `-DBUILD_TESTING=OFF` or `-DBUILD_EXAMPLES=OFF` to your `cmake` command.
251+
By default, tests, examples and command line tools are built.
252+
In order to skip building those, pass `-DBUILD_TESTING=OFF`, `-DBUILD_EXAMPLES=OFF`, or `-DBUILD_CLI_TOOLS=OFF` to your `cmake` command.
253253

254254
## Linking to your project
255255

docs/source/dev/buildoptions.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ CMake Option Values Installs Library Version
7575
================================= =========== ======== ============= ========
7676

7777

78-
Tests
79-
-----
78+
Tests, Examples and Command Line Tools
79+
--------------------------------------
8080

81-
By default, tests and examples are built.
82-
In order to skip building those, pass ``-DBUILD_TESTING=OFF`` or ``-DBUILD_EXAMPLES=OFF`` to your ``cmake`` command.
81+
By default, tests, examples and command line tools are built.
82+
In order to skip building those, pass ``-DBUILD_TESTING=OFF``, ``-DBUILD_EXAMPLES=OFF``, or ``-DBUILD_CLI_TOOLS=OFF`` to your ``cmake`` command.

docs/source/dev/repostructure.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,22 @@ Directory Structure
1919
* set ``-I`` here
2020
* prefixed with project name
2121

22+
* ``auxiliary/``
23+
24+
* internal auxiliary functionality
25+
26+
* ``helper/``, ``benchmark/``
27+
28+
* user-facing helper functionality
29+
2230
* ``src/``
2331

2432
* C++ source files
2533

34+
* ``cli/``
35+
36+
* user-facing command line tools
37+
2638
* ``lib/``
2739

2840
* ``python/``

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ Utilities
9292
:maxdepth: 1
9393
:hidden:
9494

95-
utilities/benchmark.rst
95+
utilities/cli
96+
utilities/benchmark
9697

9798
Backends
9899
--------

docs/source/utilities/cli.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. _utilities-cli:
2+
3+
Command Line Tools
4+
==================
5+
6+
openPMD-api installs command line tools alongside the main library.
7+
These terminal-focused tools help to quickly explore, manage or manipulate openPMD data series.
8+
9+
``openpmd-ls``
10+
--------------
11+
12+
List information about an openPMD data series.
13+
See ``openpmd-ls --help`` for help.
14+

include/openPMD/Series.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,23 @@ class Series : public Attributable
227227
Series& setIterationFormat(std::string const& iterationFormat);
228228

229229
/**
230-
* @return String of a pattern for file names.
230+
* @return String of a pattern for file names.
231231
*/
232232
std::string name() const;
233+
233234
/** Set the pattern for file names.
234235
*
235236
* @param name String of the pattern for file names. Must include iteration regex <CODE>\%T</CODE> for fileBased data.
236237
* @return Reference to modified series.
237238
*/
238239
Series& setName(std::string const& name);
239240

240-
/** The currently used backend */
241+
/** The currently used backend
242+
*
243+
* @see AbstractIOHandler::backendName()
244+
*
245+
* @return String of a pattern for data backend.
246+
*/
241247
std::string backend() const;
242248

243249
/** Execute all required remaining IO operations to write or read data.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright 2019-2020 Axel Huebl
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
#pragma once
22+
23+
#include "openPMD/Series.hpp"
24+
25+
#include <ostream>
26+
#include <iostream>
27+
28+
29+
namespace openPMD
30+
{
31+
namespace helper
32+
{
33+
/** List information about an openPMD data series
34+
*
35+
* @param series a openPMD data path as in Series::Series
36+
* @param longer write more information
37+
* @param out an output stream to write textual information to
38+
* @return reference to out as output stream, e.g. to pass the stream on via `operator<<`
39+
*/
40+
std::ostream &
41+
listSeries(
42+
Series const & series,
43+
bool const longer = false,
44+
std::ostream & out = std::cout
45+
);
46+
} // helper
47+
} // openPMD

0 commit comments

Comments
 (0)