Commit 5a1b0c25 authored by David Fairbrother's avatar David Fairbrother
Browse files

Add Python Export for FileFinderUtils

Adds a Python export for FileFinderUtils, the new object does not
include finding resource packs though, as the converter is registered at
a global scope in ExperimentInfo.cpp.
parent bc3283b4
......@@ -184,10 +184,12 @@ std::string FileFinderUtils::getFullPathParamIDF(std::string instName,
// find the first beat file
const std::string result = lookupFile(dirName, instName);
if (!result.empty()) {
std::cout << "Found: " << result << '\n';
return result;
}
}
std::cout << "Found Nothing \n";
return "";
}
......
......@@ -19,6 +19,7 @@ set(EXPORT_FILES
src/Exports/AlgorithmManager.cpp
src/Exports/AnalysisDataService.cpp
src/Exports/FileProperty.cpp
src/Exports/FileFinderUtils.cpp
src/Exports/MultipleFileProperty.cpp
src/Exports/FrameworkManager.cpp
src/Exports/ISpectrum.cpp
......
......@@ -32,6 +32,9 @@ using namespace boost::python;
GET_POINTER_SPECIALIZATION(ExperimentInfo)
/// Converter from C++ signature to python signature
// As we can't have two converters in the global namespace we will
// keep the converter with ExperimentInfo despite the C++ impl moving to
// FileFinderUtils for backwards compatibility and as there is a single user
list getResourceFilenames(const std::string &prefix, const list &fileFormats,
const list &directoryNames, const std::string &date) {
return Converters::ToPyList<std::string>()(
......@@ -66,8 +69,8 @@ void export_ExperimentInfo() {
.def("getInstrument", &ExperimentInfo::getInstrument,
return_value_policy<RemoveConstSharedPtr>(), args("self"),
"Returns the :class:`~mantid.geometry.Instrument` for this run.")
// FileFinderUtils binds Kept for backwards compat.
.def("getResourceFilenames", &FileFinderUtils::getResourceFilenames,
// FileFinderHelpers binds Kept for backwards compat.
.def("getResourceFilenames", &getResourceFilenames,
(arg("prefix"), arg("fileFormats"), arg("directoryNames"),
arg("date")),
"Compile a list of files in compliance with name pattern-matching,\n"
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2020 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAPI/FileFinderUtils.h"
#include "MantidKernel/WarningSuppressions.h"
#include "MantidPythonInterface/core/Converters/PySequenceToVector.h"
#include "MantidPythonInterface/core/Converters/ToPyList.h"
#include "MantidPythonInterface/core/GetPointer.h"
#include "MantidPythonInterface/core/Policies/RemoveConst.h"
#include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/list.hpp>
#include <boost/python/overloads.hpp>
#include <boost/python/register_ptr_to_python.hpp>
#include <string>
using Mantid::API::FileFinderUtils;
using namespace Mantid::PythonInterface;
using namespace boost::python;
GET_POINTER_SPECIALIZATION(FileFinderUtils)
GNU_DIAG_OFF("unused-local-typedef")
// Ignore -Wconversion warnings coming from boost::python
// Seen with GCC 7.1.1 and Boost 1.63.0
GNU_DIAG_OFF("conversion")
/// Overload generator for getInstrumentFilename
BOOST_PYTHON_FUNCTION_OVERLOADS(getInstrumentFilename_Overload,
FileFinderUtils::getInstrumentFilename, 1, 2)
BOOST_PYTHON_FUNCTION_OVERLOADS(getIPFPath_Overload,
FileFinderUtils::getFullPathParamIDF, 1, 2)
GNU_DIAG_ON("conversion")
GNU_DIAG_ON("unused-local-typedef")
void exportFileFinderUtils() {
register_ptr_to_python<std::shared_ptr<FileFinderUtils>>();
class_<FileFinderUtils>("FileFinderUtils", no_init)
// -
.def("getInstrumentFilename", &FileFinderUtils::getInstrumentFilename,
getInstrumentFilename_Overload(
"Returns IDF filename", (arg("instrument"), arg("date") = "")))
.staticmethod("getInstrumentFilename")
// -
.def("getIPFPath", &FileFinderUtils::getFullPathParamIDF,
getIPFPath_Overload(
"Returns the full path to the given instrument parameter file "
"for the named instrument if it exists in the instrument search "
"directories, or the optional user provided path.\n"
"instName: The name of the instrument to lookup the IPF "
"for\n"
"directoryHint: (Optional) Searches the user provided path "
"before any instrument dirs\n"
"returns: The full path as a string if found, else an "
"empty string",
(arg("instName"), arg("directoryHint") = "")))
.staticmethod("getIPFPath");
}
\ No newline at end of file
......@@ -7,7 +7,9 @@
#pragma once
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include <array>
#include <cstddef>
namespace MantidQt {
namespace SliceViewer {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment