Mantid
Loading...
Searching...
No Matches
FileFinder.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include <boost/python/class.hpp>
11#include <boost/python/list.hpp>
12#include <boost/python/overloads.hpp>
13#include <boost/python/reference_existing_object.hpp>
14
17using namespace boost::python;
18
19namespace {
20GNU_DIAG_OFF("unused-local-typedef")
21// Ignore -Wconversion warnings coming from boost::python
22// Seen with GCC 7.1.1 and Boost 1.63.0
23GNU_DIAG_OFF("conversion")
24
25BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFullPathOverloader, getFullPath, 1, 2)
26
27GNU_DIAG_ON("conversion")
28GNU_DIAG_ON("unused-local-typedef")
29} // namespace
30
41std::vector<std::string> runFinderProxy(const FileFinderImpl &self, const std::string &hintstr, list exts_list,
42 const bool useExtsOnly) {
43 // Convert python list to c++ vector
44 std::vector<std::string> exts;
45 for (int i = 0; i < len(exts_list); ++i)
46 exts.emplace_back(extract<std::string>(exts_list[i]));
47
48 // Before calling the function we need to release the GIL,
49 // drop the Python threadstate and reset anything installed
50 // via PyEval_SetTrace while we execute the C++ code -
51 // ReleaseGlobalInterpreter does this for us
53 return self.findRuns(hintstr, exts, useExtsOnly);
54}
55
57 class_<FileFinderImpl, boost::noncopyable>("FileFinderImpl", no_init)
58 .def("getFullPath", &FileFinderImpl::getFullPath,
59 getFullPathOverloader((arg("self"), arg("path"), arg("ignoreDirs") = false),
60 "Return a full path to the given file if it can be found within "
61 "datasearch.directories paths. Directories can be ignored with "
62 "ignoreDirs=True. An empty string is returned otherwise."))
63 .def("findRuns", &runFinderProxy,
64 (arg("self"), arg("hintstr"), arg("exts_list") = list(), arg("useExtsOnly") = false),
65 "Find a list of files file given a hint. "
66 "The hint can be a comma separated list of run numbers and can also "
67 "include ranges of runs, e.g. 123-135 or equivalently 123-35"
68 "If no instrument prefix is given then the current default is used."
69 "exts_list is an optional list containing strings of file "
70 "extensions to search."
71 "useExtsOnly is an optional bool. If it's true then don't use "
72 "facility exts.")
73 .def("getCaseSensitive", &FileFinderImpl::getCaseSensitive, (arg("self")),
74 "Option to get if file finder should be case sensitive.")
75 .def("setCaseSensitive", &FileFinderImpl::setCaseSensitive, (arg("self"), arg("cs")),
76 "Option to set if file finder should be case sensitive.")
77 .def("Instance", &FileFinder::Instance, return_value_policy<reference_existing_object>(),
78 "Returns a reference to the FileFinder singleton instance")
79 .staticmethod("Instance");
80}
void export_FileFinder()
Definition: FileFinder.cpp:56
std::vector< std::string > runFinderProxy(const FileFinderImpl &self, const std::string &hintstr, list exts_list, const bool useExtsOnly)
Runs FileFinder.findRuns after releasing the python GIL.
Definition: FileFinder.cpp:41
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(valueAsPrettyStrOverloader, valueAsPrettyStr, 0, 2) void export_Property()
Definition: Property.cpp:102
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
This class finds data files given an instrument name (optionally) and a run number.
Definition: FileFinder.h:36
bool getCaseSensitive() const
Option to get if file finder should be case sensitive.
Definition: FileFinder.cpp:93
std::string getFullPath(const std::string &filename, const bool ignoreDirs=false) const
Return the full path to the file given its name.
Definition: FileFinder.cpp:105
void setCaseSensitive(const bool cs)
Option to set if file finder should be case sensitive.
Definition: FileFinder.cpp:81
Manage the lifetime of a class intended to be a singleton.
Defines a structure for releasing the Python GIL using the RAII pattern.
STL namespace.