Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
|
#include <FileFinder.hpp>
Public Member Functions | |
FileFinder () | |
FileFinder (const std::string &rPath, RelativeTo::Value relativeTo) | |
FileFinder (const std::string &rLeafName, const FileFinder &rParentOrSibling) | |
FileFinder (const fs::path &rPath) | |
virtual | ~FileFinder () |
virtual void | SetPath (const std::string &rPath, RelativeTo::Value relativeTo) |
virtual void | SetPath (const std::string &rLeafName, const FileFinder &rParentOrSibling) |
bool | IsPathSet () const |
bool | Exists () const |
bool | IsFile () const |
bool | IsDir () const |
bool | IsEmpty () const |
std::string | GetAbsolutePath () const |
bool | IsNewerThan (const FileFinder &rOtherEntity) const |
std::string | GetLeafName () const |
std::string | GetLeafNameNoExtension () const |
std::string | GetExtension () const |
FileFinder | GetParent () const |
std::string | GetRelativePath (const FileFinder &rBasePath) const |
FileFinder | CopyTo (const FileFinder &rDest) const |
void | Remove () const |
void | DangerousRemove () const |
std::vector< FileFinder > | FindMatches (const std::string &rPattern) const |
bool | operator< (const FileFinder &otherFinder) const |
Static Public Member Functions | |
static bool | IsAbsolutePath (const std::string &rPath) |
static void | ReplaceSpacesWithUnderscores (std::string &rPath) |
static void | ReplaceUnderscoresWithSpaces (std::string &rPath) |
static void | FakePath (RelativeTo::Value fakeWhat, const std::string &rFakePath) |
static void | StopFaking () |
Private Member Functions | |
void | PrivateRemove (bool dangerous=false) const |
Private Attributes | |
std::string | mAbsPath |
Static Private Attributes | |
static bool | msFaking = false |
static RelativeTo::Value | msFakeWhat = RelativeTo::Absolute |
static std::string | msFakePath = "" |
A helper class for finding files or directories, given paths which can be relative to various locations (e.g. the Chaste source tree root, the current directory, the Chaste test output directory, or an absolute path).
Definition at line 70 of file FileFinder.hpp.
FileFinder::FileFinder | ( | ) |
Default constructor for subclasses to use. They should call SetPath() in their constructor.
This also allows classes to store a FileFinder instance that hasn't been properly set up yet, and assign to it later using operator=.
Definition at line 77 of file FileFinder.cpp.
Referenced by CopyTo(), FindMatches(), GetParent(), and PrivateRemove().
FileFinder::FileFinder | ( | const std::string & | rPath, |
RelativeTo::Value | relativeTo | ||
) |
Main constructor.
rPath | the path to the file/dir to find |
relativeTo | how to interpret this path |
Definition at line 82 of file FileFinder.cpp.
References SetPath().
FileFinder::FileFinder | ( | const std::string & | rLeafName, |
const FileFinder & | rParentOrSibling | ||
) |
Find a file (or folder) relative to some file or directory. If the second argument is a directory, we look for the given leaf name within it. If the second argument is a file, then we look for a sibling. An exception is raised if rParentOrSibling does not exist.
rLeafName | the leaf name of the file/dir to find |
rParentOrSibling | where to look for it |
Definition at line 87 of file FileFinder.cpp.
References SetPath().
FileFinder::FileFinder | ( | const fs::path & | rPath | ) |
Conversion constructor from a std::filesystem path object. Note that since fs::path has a conversion constructor from std::string, this allows us to be initialised with a string or character constant, too. The path will be interpreted as relative to the current working directory, unless it is an absolute path.
rPath | the path to the file/dir to find |
Definition at line 92 of file FileFinder.cpp.
References RelativeTo::Absolute, and SetPath().
|
virtual |
Needed because we have virtual methods.
Definition at line 97 of file FileFinder.cpp.
FileFinder FileFinder::CopyTo | ( | const FileFinder & | rDest | ) | const |
Copy this file or folder (recursively in the latter case) to the given destination. If the destination is a folder that exists, the source will be copied with the same name inside that folder. Otherwise the source will be copied with the given destination name.
If the source is a file and the destination is a file that exists it will be removed prior to copying. If the source is a folder and the destination is a file that exists then an error is thrown.
rDest | where to copy to |
Definition at line 309 of file FileFinder.cpp.
References FileFinder(), EXCEPTION, Exists(), IsDir(), IsFile(), and mAbsPath.
Referenced by CellMLToSharedLibraryConverter::ConvertCellmlToSo(), HeartConfig::CopySchema(), CardiacSimulation::CreateAndRun(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::save(), and AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::save().
void FileFinder::DangerousRemove | ( | ) | const |
This method will allow you to remove any file from under either * CHASTE_TEST_OUTPUT or * the source tree (but not elsewhere).
For this reason it is a very dangerous operation and should not be used if Remove could be instead.
BEWARE: if you have managed to set CHASTE_TEST_OUTPUT to "/" this could wipe your system!
Definition at line 426 of file FileFinder.cpp.
References PrivateRemove().
Referenced by CellMLToSharedLibraryConverter::ConvertCellmlToSo().
bool FileFinder::Exists | ( | ) | const |
Definition at line 182 of file FileFinder.cpp.
References mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), ExtendedBidomainTissue< DIM >::ExtendedBidomainTissue(), Hdf5DataReader::CommonConstructor(), OutputFileHandler::CommonConstructor(), CellMLToSharedLibraryConverter::Convert(), FibreConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), HeartConfig::CopySchema(), CopyTo(), BidomainTissue< SPACE_DIM >::CreateExtracellularConductivityTensors(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::CreateIntracellularConductivityTensor(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::InitialiseWriter(), IsNewerThan(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), Hdf5DataWriter::OpenFile(), PrivateRemove(), AbstractPurkinjeCellFactory< ELEMENT_DIM, SPACE_DIM >::ReadJunctionsFile(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::save(), and SetPath().
|
static |
For testing purposes, fake the value of one of the normally fixed paths, e.g. ChasteSourceRoot.
fakeWhat | which path to fake |
rFakePath | its fake value |
Definition at line 558 of file FileFinder.cpp.
References msFakePath, msFakeWhat, and msFaking.
std::vector< FileFinder > FileFinder::FindMatches | ( | const std::string & | rPattern | ) | const |
rPattern | the pattern to match names against |
Definition at line 431 of file FileFinder.cpp.
References FileFinder(), EXCEPTION, IsDir(), and mAbsPath.
Referenced by CellMLToSharedLibraryConverter::ConvertCellmlToSo(), and AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::save().
std::string FileFinder::GetAbsolutePath | ( | ) | const |
If this is a directory that exists (at the instant of this call), the absolute path is guaranteed to end in a '/'. Otherwise, the path is guaranteed not to end in a '/'.
Definition at line 223 of file FileFinder.cpp.
References IsDir(), and mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), FibreReader< DIM >::FibreReader(), OutputFileHandler::OutputFileHandler(), Hdf5DataReader::CommonConstructor(), AbstractConvergenceTester< CELL, CARDIAC_PROBLEM, DIM, PROBLEM_DIM >::Converge(), CellMLToSharedLibraryConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), OutputFileHandler::CopyFileTo(), AbstractHdf5Converter< ELEMENT_DIM, SPACE_DIM >::GenerateListOfDatasets(), OutputFileHandler::GetChasteTestOutputDirectory(), ElectroMechanicsProblemDefinition< DIM >::GetFibreSheetDirectionsFile(), DynamicModelLoaderRegistry::GetLoader(), GetRelativePath(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::InitialiseWriter(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), Hdf5DataWriter::OpenFile(), operator<(), PrivateRemove(), AbstractPurkinjeCellFactory< ELEMENT_DIM, SPACE_DIM >::ReadJunctionsFile(), ArchiveLocationInfo::SetArchiveDirectory(), SetPath(), AbstractCardiacMechanicsSolver< ELASTICITY_SOLVER, DIM >::SetVariableFibreSheetDirections(), and AbstractTetrahedralMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteNclFile().
std::string FileFinder::GetExtension | ( | ) | const |
Definition at line 249 of file FileFinder.cpp.
References mAbsPath.
Referenced by AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::save().
std::string FileFinder::GetLeafName | ( | ) | const |
i.e. the individual file or directory name and none of the preceding folders on its path.
Definition at line 239 of file FileFinder.cpp.
References mAbsPath.
Referenced by CellMLLoader::LoadCellMLFile().
std::string FileFinder::GetLeafNameNoExtension | ( | ) | const |
i.e. the individual file or directory name and none of the preceding folders on its path.
Definition at line 244 of file FileFinder.cpp.
References mAbsPath.
Referenced by FibreConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), CellMLLoader::LoadCellMLFile(), and AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::save().
FileFinder FileFinder::GetParent | ( | ) | const |
Definition at line 254 of file FileFinder.cpp.
References FileFinder(), RelativeTo::Absolute, and mAbsPath.
Referenced by FibreConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::save(), and SetPath().
std::string FileFinder::GetRelativePath | ( | const FileFinder & | rBasePath | ) | const |
rBasePath | where the returned path should be relative to |
Definition at line 264 of file FileFinder.cpp.
References EXCEPTION, and GetAbsolutePath().
Referenced by Hdf5ToMeshalyzerConverter< ELEMENT_DIM, SPACE_DIM >::Hdf5ToMeshalyzerConverter(), Hdf5ToVtkConverter< ELEMENT_DIM, SPACE_DIM >::Hdf5ToVtkConverter(), OutputFileHandler::OutputFileHandler(), and OutputFileHandler::GetRelativePath().
|
static |
rPath | the path to test |
Definition at line 526 of file FileFinder.cpp.
Referenced by AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::load(), ExtendedBidomainProblem< DIM >::load(), ArchiveLocationInfo::SetMeshPathname(), ExecutableSupport::SetOutputDirectory(), and SetPath().
bool FileFinder::IsDir | ( | ) | const |
Definition at line 192 of file FileFinder.cpp.
References mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), CopyTo(), FindMatches(), GetAbsolutePath(), IsEmpty(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), and SetPath().
bool FileFinder::IsEmpty | ( | ) | const |
bool FileFinder::IsFile | ( | ) | const |
Definition at line 187 of file FileFinder.cpp.
References mAbsPath.
Referenced by Hdf5ToMeshalyzerConverter< ELEMENT_DIM, SPACE_DIM >::Hdf5ToMeshalyzerConverter(), OutputFileHandler::CopyFileTo(), CopyTo(), IsEmpty(), and PrivateRemove().
bool FileFinder::IsNewerThan | ( | const FileFinder & | rOtherEntity | ) | const |
rOtherEntity | the entity to test against. |
Definition at line 232 of file FileFinder.cpp.
References Exists(), and mAbsPath.
Referenced by CellMLToSharedLibraryConverter::Convert().
bool FileFinder::IsPathSet | ( | ) | const |
Definition at line 177 of file FileFinder.cpp.
References mAbsPath.
Referenced by CellMLToSharedLibraryConverter::ConvertCellmlToSo(), ExecutableSupport::InitializePetsc(), ExecutableSupport::PrintError(), ExecutableSupport::WriteMachineInfoFile(), and ExecutableSupport::WriteProvenanceInfoFile().
bool FileFinder::operator< | ( | const FileFinder & | otherFinder | ) | const |
Provide a sort operator to get a logical ordering from FindMatches it orders by alphabetical (or ASCII really).
otherFinder | Another FileFinder |
Definition at line 553 of file FileFinder.cpp.
References GetAbsolutePath(), and mAbsPath.
|
private |
This is code common to Remove() and DangerousRemove(). Should remain private and not to be called from elsewhere. Remove() is only allowed to delete things with a .chaste_deletable_folder in the testoutput directory.
DangerousRemove() is allowed to delete anything in the source or testoutput directories.
dangerous | whether we are doing a dangerous remove. |
Definition at line 357 of file FileFinder.cpp.
References FileFinder(), RelativeTo::ChasteBuildRoot, RelativeTo::ChasteSourceRoot, EXCEPTION, Exists(), GetAbsolutePath(), OutputFileHandler::GetChasteTestOutputDirectory(), IsFile(), mAbsPath, OutputFileHandler::SIG_FILE_NAME, and ChastePosixPathFixer::ToPosix().
Referenced by DangerousRemove(), and Remove().
void FileFinder::Remove | ( | ) | const |
Recursively remove this file or folder. Since this is a potentially very dangerous operation, only locations under the Chaste test output folder may be removed.
Only folders created by an OutputFileHandler, or the contents of such a folder, may be deleted (folders that have .chaste_deletable_folder present).
If you need to delete a file or folder without .chaste_deletable_folder, then you have to use DangerousRemove().
Definition at line 421 of file FileFinder.cpp.
References PrivateRemove().
Referenced by CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), HoneycombMeshGenerator::HoneycombMeshGenerator(), ToroidalHoneycombMeshGenerator::ToroidalHoneycombMeshGenerator(), OutputDirectoryFifoQueue::CreateNextDir(), ImmersedBoundaryCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), and VertexBasedCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier().
|
static |
Replace any spaces in a path or filename with underscores.
rPath | a path or file name |
Definition at line 531 of file FileFinder.cpp.
|
static |
Replace any underscores in a path or filename with spaces (for making titles etc.).
rPath | a path or file name |
Definition at line 542 of file FileFinder.cpp.
|
virtual |
Change this FileFinder to point at a new location, relative to some file or directory.
rLeafName | the leaf name of the file/dir to find |
rParentOrSibling | where to look for it |
Definition at line 161 of file FileFinder.cpp.
References RelativeTo::Absolute, EXCEPTION, Exists(), GetAbsolutePath(), GetParent(), IsDir(), and SetPath().
|
virtual |
Change this FileFinder to point at a new location.
rPath | the path to the file/dir to find |
relativeTo | how to interpret this path |
Definition at line 101 of file FileFinder.cpp.
References RelativeTo::Absolute, RelativeTo::AbsoluteOrCwd, RelativeTo::ChasteBuildRoot, ChasteBuildRootDir(), RelativeTo::ChasteSourceRoot, ChasteSourceRootDir(), RelativeTo::ChasteTestOutput, RelativeTo::CWD, OutputFileHandler::GetChasteTestOutputDirectory(), IsAbsolutePath(), mAbsPath, msFakePath, msFakeWhat, msFaking, and NEVER_REACHED.
Referenced by AbstractHdf5Access::AbstractHdf5Access(), FileFinder(), FileFinder(), FileFinder(), HeartFileFinder::HeartFileFinder(), CellMLToSharedLibraryConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), HeartConfig::CopySchema(), OutputFileHandler::GetChasteTestOutputDirectory(), ExecutableSupport::InitializePetsc(), HeartConfig::LoadFromCheckpoint(), ExecutableSupport::PrintError(), ExecutableSupport::SetOutputDirectory(), HeartConfig::SetParametersFile(), SetPath(), ExecutableSupport::WriteMachineInfoFile(), and ExecutableSupport::WriteProvenanceInfoFile().
|
static |
Stop faking one of the fixed paths.
Definition at line 565 of file FileFinder.cpp.
References msFaking.
|
private |
The absolute path to our file.
Definition at line 306 of file FileFinder.hpp.
Referenced by CopyTo(), Exists(), FindMatches(), GetAbsolutePath(), GetExtension(), GetLeafName(), GetLeafNameNoExtension(), GetParent(), IsDir(), IsEmpty(), IsFile(), IsNewerThan(), IsPathSet(), operator<(), PrivateRemove(), and SetPath().
|
staticprivate |
The fake value of the faked path.
Definition at line 315 of file FileFinder.hpp.
Referenced by FakePath(), and SetPath().
|
staticprivate |
Which path to fake.
Definition at line 312 of file FileFinder.hpp.
Referenced by FakePath(), and SetPath().
|
staticprivate |
Whether to fake one of the fixed paths, e.g. ChasteSourceRoot.
Definition at line 309 of file FileFinder.hpp.
Referenced by FakePath(), SetPath(), and StopFaking().