diff --git a/Framework/Algorithms/CMakeLists.txt b/Framework/Algorithms/CMakeLists.txt index 88a34c6746b4..c1e83489c422 100644 --- a/Framework/Algorithms/CMakeLists.txt +++ b/Framework/Algorithms/CMakeLists.txt @@ -263,7 +263,6 @@ set(SRC_FILES src/RebinRagged2.cpp src/RebinToWorkspace.cpp src/Rebunch.cpp - src/RecordPythonScript.cpp src/Regroup.cpp src/RemoveBackground.cpp src/RemoveBins.cpp @@ -618,7 +617,6 @@ set(INC_FILES inc/MantidAlgorithms/RebinRagged2.h inc/MantidAlgorithms/RebinToWorkspace.h inc/MantidAlgorithms/Rebunch.h - inc/MantidAlgorithms/RecordPythonScript.h inc/MantidAlgorithms/Regroup.h inc/MantidAlgorithms/RemoveBackground.h inc/MantidAlgorithms/RemoveBins.h diff --git a/Framework/Algorithms/inc/MantidAlgorithms/GenerateIPythonNotebook.h b/Framework/Algorithms/inc/MantidAlgorithms/GenerateIPythonNotebook.h index 7b220ae2d31c..7e4368683272 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/GenerateIPythonNotebook.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/GenerateIPythonNotebook.h @@ -35,7 +35,7 @@ class MANTID_ALGORITHMS_DLL GenerateIPythonNotebook final : public API::Algorith /// Algorithm's version for identification int version() const override { return 1; }; - const std::vector seeAlso() const override { return {"RecordPythonScript", "GeneratePythonScript"}; } + const std::vector seeAlso() const override { return {"GeneratePythonScript"}; } /// Algorithm's category for identification const std::string category() const override { return "Utility\\Python"; } diff --git a/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h b/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h index a89a93241406..9c8223fa1e69 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h @@ -38,7 +38,7 @@ class MANTID_ALGORITHMS_DLL GeneratePythonScript : public API::Algorithm { /// Algorithm's version for identification int version() const override { return 1; }; - const std::vector seeAlso() const override { return {"RecordPythonScript", "GenerateIPythonNotebook"}; } + const std::vector seeAlso() const override { return {"GenerateIPythonNotebook"}; } /// Algorithm's category for identification const std::string category() const override { return "Utility\\Python"; } diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h b/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h deleted file mode 100644 index 682b64c0bbed..000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h +++ /dev/null @@ -1,62 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2011 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 + -#pragma once - -#include "MantidAPI/AlgorithmObserver.h" -#include "MantidAPI/DeprecatedAlgorithm.h" -#include "MantidAlgorithms/DllConfig.h" -#include "MantidAlgorithms/GeneratePythonScript.h" - -namespace Mantid { -namespace Algorithms { - -/** RecordPythonScript : - - An Algorithm to generate a Python script file to reproduce the history of a - workspace. - - Properties: -
    -
  • Filename - the name of the file to write to.
  • -
  • InputWorkspace - the workspace name who's history is to be saved.
  • -
-*/ -class MANTID_ALGORITHMS_DLL RecordPythonScript : public Algorithms::GeneratePythonScript, - public API::AlgorithmObserver, - public API::DeprecatedAlgorithm { -public: - RecordPythonScript(); - /// Algorithm's name for identification - const std::string name() const override { return "RecordPythonScript"; }; - /// Summary of algorithms purpose - const std::string summary() const override { - return "An Algorithm to generate a Python script file to reproduce the " - "history of a workspace."; - } - - /// Algorithm's version for identification - int version() const override { return 1; }; - const std::vector seeAlso() const override { - return {"GenerateIPythonNotebook", "GeneratePythonScript"}; - } - /// Algorithm's category for identification - const std::string category() const override { return "Utility\\Python"; } - -private: - /// Initialise the properties - void init() override; - /// Run the algorithm - void exec() override; - const std::string alias() const override; - /// Handler of the start notifications. Must be overriden in inherited classes. - void startingHandle(API::IAlgorithm_sptr alg) override; - /// buffer for the script - std::string m_generatedScript; -}; - -} // namespace Algorithms -} // namespace Mantid diff --git a/Framework/Algorithms/src/RecordPythonScript.cpp b/Framework/Algorithms/src/RecordPythonScript.cpp deleted file mode 100644 index cce0f1f3d1e2..000000000000 --- a/Framework/Algorithms/src/RecordPythonScript.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 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 "MantidAlgorithms/RecordPythonScript.h" -#include "MantidAPI/FileProperty.h" - -#include - -#include - -using namespace Mantid::Kernel; -using namespace Mantid::API; - -namespace Mantid::Algorithms { - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(RecordPythonScript) - -// This is to overwrite inheriting ExportHistory alias from GeneratePythonScript -const std::string RecordPythonScript::alias() const { return ""; } - -//---------------------------------------------------------------------------------------------- -/// Constructor -RecordPythonScript::RecordPythonScript() : Algorithms::GeneratePythonScript(), API::AlgorithmObserver() { - useAlgorithm("GeneratePythonScript", 1); -} - -//---------------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------------- -/** Initialize the algorithm's properties. - */ -void RecordPythonScript::init() { - - declareProperty(std::make_unique("Filename", "", API::FileProperty::Save, ".py"), - "The file into which the Python script will be generated."); -} - -//---------------------------------------------------------------------------------------------- -/** Execute the algorithm. - */ -void RecordPythonScript::exec() { - observeStarting(); - // Keep going until you get cancelled - while (true) { - try { - // Exit if the user presses cancel - interruption_point(); - } catch (...) { - break; - } - progress(0.0, "Recording..."); - - // Sleep for 50 msec - Poco::Thread::sleep(50); - } - - // save the script to a file - const std::string filename = getPropertyValue("Filename"); - std::ofstream file(filename.c_str(), std::ofstream::trunc); - - if (file.is_open()) { - file << m_generatedScript; - file.flush(); - file.close(); - } else { - throw Exception::FileError("Unable to create file: ", filename); - } - - stopObservingManager(); -} - -/** Handler of the start notifications. Adds an algorithm call to the script. - * @param alg :: Shared pointer to the starting algorithm. - */ -void RecordPythonScript::startingHandle(API::IAlgorithm_sptr alg) { - auto props = alg->getProperties(); - - std::string algString; - for (auto &prop : props) { - std::string opener = "='"; - if ((*prop).value().find('\\') != std::string::npos) { - opener = "=r'"; - } - - std::string paramString = (*prop).name() + opener + (*prop).value() + "'"; - - // Miss out parameters that are empty. - if (paramString.length() != 0) { - if (algString.length() != 0) { - algString += ","; - } - algString += paramString; - } - } - - m_generatedScript += alg->name() + "(" + algString + ")\n"; -} - -} // namespace Mantid::Algorithms diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index 5c6908d37ab4..549b9962d745 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -288,7 +288,6 @@ missingOverride:${CMAKE_SOURCE_DIR}/Framework/Algorithms/inc/MantidAlgorithms/PD uninitMemberVarPrivate:${CMAKE_SOURCE_DIR}/Framework/Algorithms/inc/MantidAlgorithms/NormaliseToMonitor.h:114 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/MergeRuns.cpp:292 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/MergeRuns.cpp:679 -constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/RecordPythonScript.cpp:83 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/PaalmanPingsAbsorptionCorrection.cpp:452 constParameterReference:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/PolarizationCorrectionFredrikze.cpp:138 constParameterReference:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/PolarizationCorrectionFredrikze.cpp:155 diff --git a/docs/source/algorithms/RecordPythonScript-v1.rst b/docs/source/algorithms/RecordPythonScript-v1.rst deleted file mode 100644 index 28f290573101..000000000000 --- a/docs/source/algorithms/RecordPythonScript-v1.rst +++ /dev/null @@ -1,78 +0,0 @@ -.. algorithm:: - -.. summary:: - -.. relatedalgorithms:: - -.. properties:: - -This algorithm records the python commans of any algoithms that execute while it is running and saves them out to a file. - -This is similar to extracting the history of a workspace, but outputs evey algorithm that occurs during it's execution rather than just for a specific workspace. - -The file is written out once this algotithm is cancelled, either using the running algorithm details button or via python. - - -Usage ------ - -**Example:** - - -.. testcode:: RecordPythonScript - - from threading import Thread - import os, time - - #find a suitable directory to save the file - fileDir = config["defaultsave.directory"] - if not os.path.isdir(fileDir): - #use the users home directory if default save is not set - fileDir = os.path.expanduser('~') - outputFile = os.path.join(fileDir,"MyRecording.py") - - def startRecording(): - try: - RecordPythonScript(outputFile) - except RuntimeError: - pass - thread = Thread(target = startRecording) - thread.start() - - # a short pause to allow the thread to start - time.sleep(0.1) - - ws = CreateSampleWorkspace("Event","Multiple Peaks") - wsOut=CreateFlatEventWorkspace(ws,RangeStart=15000,RangeEnd=18000) - wsOut=RebinToWorkspace(wsOut,ws,PreserveEvents=True) - - # This will cancel the rocording algorithm - # you can do the same in the GUI - # by clicking on the details button on the bottom right - AlgorithmManager.cancelAll() - thread.join() - - #Load and print the resulting file - print("The result file has the following python recorded") - with open(outputFile, "r") as file: - print(file.read().rstrip()) - - #cleanup - os.remove(outputFile) - -Output: - -.. testoutput:: RecordPythonScript - :options: +NORMALIZE_WHITESPACE - - The result file has the following python recorded - CreateSampleWorkspace(OutputWorkspace='ws',WorkspaceType='Event',Function='Multiple Peaks',UserDefinedFunction='',XUnit='TOF',XMin='0',XMax='20000',BinWidth='200',NumEvents='1000',Random='0',NumScanPoints='1',InstrumentName='basic_rect',NumBanks='2',NumMonitors='0',BankPixelWidth='10',PixelDiameter='0.0080000000000000002',PixelHeight='0.00020000000000000001',PixelSpacing='0.0080000000000000002',BankDistanceFromSample='5',SourceDistanceFromSample='10') - CreateFlatEventWorkspace(InputWorkspace='ws',RangeStart='15000',RangeEnd='18000',OutputWorkspace='wsOut') - RebinToWorkspace(WorkspaceToRebin='wsOut',WorkspaceToMatch='ws',OutputWorkspace='wsOut',PreserveEvents='1') - - - - -.. categories:: - -.. sourcelink:: diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37869.rst b/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37869.rst new file mode 100644 index 000000000000..7c9a0110b75d --- /dev/null +++ b/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37869.rst @@ -0,0 +1 @@ +- The RecordPythonScript algorithm was deprecated in :ref:`Release 5.1.0 ` and has now been removed. Use :ref:`GeneratePythonScript` instead. \ No newline at end of file