-
Notifications
You must be signed in to change notification settings - Fork 102
feat: Copy/archive input XML files into the output directory #4003
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
Closed
kdrienCG
wants to merge
20
commits into
GEOS-DEV:develop
from
kdrienCG:feature/kdrienCG/archiveInputDeck
Closed
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
20b501c
add functions to collect included XML files
kdrienCG 3db8b1a
add archiveInputDeck function
kdrienCG 8afead3
call archiveInputDeck() in ProblemManager
kdrienCG 25c325b
modify archive directory name
kdrienCG 1cf33d5
add tests for collectIncluded functions
kdrienCG a4b35d0
fix typo in archiveInputDeck documentation
kdrienCG c873915
fix typo in collectIncludedRecursive documentation
kdrienCG 6efbe14
add missing header includes
kdrienCG 140aa51
add filter on collectIncluded iteration
kdrienCG 9ed7c03
add MPI rank 0 condition for archiveInputDeck call
kdrienCG 5c30635
add output directory invariant for archiveInputDeck
kdrienCG 0c5fb2d
add tests for archiveInputDeck
kdrienCG bf1ca66
modify archive's logic to flatten inputs
kdrienCG 6b35d1b
strip metadata attributes from the archived XML
kdrienCG a61d8c7
sort XML attributes in the archived XML
kdrienCG 8738084
copy schema.xsd to the archive
kdrienCG 93e2806
uncrustify
kdrienCG dbfa0fb
relocate archiveInputDeck call to generate the XSD schema
kdrienCG 5a7c196
add command line option to trigger the archiving
kdrienCG d745bf6
add levels to archiving command line option
kdrienCG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| * | ||
| * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC | ||
| * Copyright (c) 2018-2024 TotalEnergies | ||
| * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University | ||
| * Copyright (c) 2023-2024 Chevron | ||
| * Copyright (c) 2019- GEOS/GEOSX Contributors | ||
| * All rights reserved | ||
| * | ||
| * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| */ | ||
|
|
||
| /** | ||
| * @file ArchiveInputDeck.cpp | ||
| */ | ||
|
|
||
| #include "ArchiveInputDeck.hpp" | ||
|
|
||
| #include "common/Path.hpp" | ||
| #include "dataRepository/xmlWrapper.hpp" | ||
|
|
||
| #include <chrono> | ||
| #include <filesystem> | ||
|
|
||
|
|
||
| namespace geos | ||
| { | ||
|
|
||
| using namespace dataRepository; | ||
|
|
||
| namespace archiveInputDeck | ||
| { | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| string makeTimestamp() | ||
| { | ||
| auto const now = std::chrono::system_clock::now(); | ||
| auto const time_t_now = std::chrono::system_clock::to_time_t( now ); | ||
| std::ostringstream timestampStream; | ||
| timestampStream << std::put_time( std::localtime( &time_t_now ), "%Y%m%d_%H%M%S" ); | ||
| return timestampStream.str(); | ||
|
kdrienCG marked this conversation as resolved.
|
||
| } | ||
|
|
||
| std::set< string > collectAbsFilePaths( string_array const & fileNames ) | ||
| { | ||
| std::set< string > collection; | ||
| for ( string const & fileName : fileNames ) | ||
| { | ||
| xmlWrapper::collectIncludedRecursive( fileName, collection ); | ||
| } | ||
| return collection; | ||
| } | ||
|
|
||
| /// @brief Prefixes a file path string if it is located "behind" the | ||
| /// specified directory | ||
| /// @param absFilePath The absolute path to the file | ||
| /// @param absDirPath The absolute path to the directory | ||
| /// @return A relative path of the file prefixed with "__" for every "../" | ||
| /// from the directory location | ||
| /// | ||
| /// Example: | ||
| /// @code | ||
| /// std::string foo = prefixBackwardPath( "/usr/foo/file.txt", "/usr/bar/buzz" ) | ||
| /// assert( foo == "____foo/file.txt" ) | ||
| /// @endcode | ||
| string prefixBackwardPath( string const & absFilePath, string const & absDirPath ) | ||
| { | ||
| string relPath = std::filesystem::relative( std::filesystem::path( absFilePath ), | ||
| std::filesystem::path( absDirPath ) ); | ||
|
|
||
| string prefix; | ||
| while( relPath.size() >= 3 && relPath.substr( 0, 3 ) == "../" ) | ||
| { | ||
| prefix += "__"; | ||
| relPath = relPath.substr( 3 ); | ||
| } | ||
|
|
||
| return prefix + relPath; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| void archiveInputDeck( string_array const & inputFileNames, | ||
| string const & outputDirectory ) | ||
| { | ||
| if ( inputFileNames.empty() ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| string const timestamp = makeTimestamp(); | ||
| string const archiveDir = joinPath( outputDirectory, "archive_inputFiles", timestamp ); | ||
| makeDirsForPath( archiveDir + "/" ); | ||
|
kdrienCG marked this conversation as resolved.
|
||
|
|
||
|
kdrienCG marked this conversation as resolved.
Outdated
|
||
| string const baseDir = splitPath( getAbsolutePath(inputFileNames[0]) ).first; | ||
| std::set< string > absFilePaths = collectAbsFilePaths( inputFileNames ); | ||
|
|
||
| for ( string const & absFilePath : absFilePaths ) | ||
| { | ||
| string const destPath = joinPath( archiveDir, prefixBackwardPath( absFilePath, baseDir ) ); | ||
| makeDirsForPath( splitPath( destPath ).first + "/" ); | ||
|
|
||
| std::error_code ec; | ||
| bool copied = std::filesystem::copy_file( absFilePath, | ||
| destPath, | ||
| std::filesystem::copy_options::overwrite_existing, | ||
| ec ); | ||
| GEOS_LOG_IF( !copied, | ||
| GEOS_FMT( "Failed to copy archive file '{}' into '{}': {}", | ||
| absFilePath, destPath, ec.message() ) ); | ||
|
kdrienCG marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } /* namespace archiveInputDeck */ | ||
|
|
||
| } /* namespace geos */ | ||
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| * | ||
| * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC | ||
| * Copyright (c) 2018-2024 TotalEnergies | ||
| * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University | ||
| * Copyright (c) 2023-2024 Chevron | ||
| * Copyright (c) 2019- GEOS/GEOSX Contributors | ||
| * All rights reserved | ||
| * | ||
| * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
| * ------------------------------------------------------------------------------------------------------------ | ||
| */ | ||
|
|
||
| /** | ||
| * @file ArchiveInputDeck.hpp | ||
| */ | ||
|
|
||
| #ifndef GEOS_FILEIO_OUTPUTS_ARCHIVEINPUTDECK_HPP_ | ||
| #define GEOS_FILEIO_OUTPUTS_ARCHIVEINPUTDECK_HPP_ | ||
|
|
||
| #include "common/DataTypes.hpp" | ||
|
|
||
| namespace geos | ||
| { | ||
|
|
||
| namespace archiveInputDeck | ||
| { | ||
|
|
||
| /** | ||
| * @brief Copy XML input files into the output directory, preserving the | ||
| * folder structure | ||
| * @param inputFileNames Container of XML file names to start the copy from | ||
| * @param outputDirectory The output directory to copy files into | ||
| * | ||
| * Copy XML input files and every included files they contain (specified in | ||
| * the <Included> tag. This function creates a somewhat similar folder | ||
| * structure to the actual structure in the disk. | ||
| * | ||
| * Note: XML files that are located "behind" the callpoint (the path to | ||
| * the first input file given as the -i paramater) will be prefixed | ||
|
kdrienCG marked this conversation as resolved.
Outdated
|
||
| * with "__" for every "../" in the relative path from the callpoint. | ||
| */ | ||
| void archiveInputDeck( string_array const & inputFileNames, | ||
| string const & outputDirectory ); | ||
|
|
||
| } /* namespace archiveInputDeck */ | ||
|
|
||
| } /* namespace geos */ | ||
|
|
||
|
|
||
| #endif // GEOS_FILEIO_OUTPUTS_ARCHIVEINPUTDECK_HPP_ | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.