21using Mantid::Types::Core::DateAndTime;
39 "An input workspace.");
41 std::vector<std::string> exts{
".py"};
44 "The name of the file into which the workspace history will "
47 declareProperty(
"ScriptText", std::string(
""),
"Saves the history of the workspace to a variable.",
52 declareProperty(
"StartTimestamp", std::string(
""),
"The filter start time in the format YYYY-MM-DD HH:mm:ss",
55 declareProperty(
"EndTimestamp", std::string(
""),
"The filter end time in the format YYYY-MM-DD HH:mm:ss",
58 declareProperty(
"AppendTimestamp",
false,
"Appends the time the command was run as a comment afterwards",
61 std::vector<std::string> saveVersions{
"Specify Old",
"Specify All",
"Specify None"};
62 declareProperty(
"SpecifyAlgorithmVersions",
"Specify Old", std::make_shared<StringListValidator>(saveVersions),
63 "When to specify which algorithm version was used by Mantid.");
68 declareProperty(
"IgnoreTheseAlgProperties", std::vector<std::vector<std::string>>(),
69 "A list of algorithm properties to filter out of the built script",
Direction::Input);
70 declareProperty(
"AppendExecCount",
false,
"Whether execCount should be appended to the end of the built string");
78 const std::string startTime =
getProperty(
"StartTimestamp");
79 const std::string endTime =
getProperty(
"EndTimestamp");
80 const std::string saveVersions =
getProperty(
"SpecifyAlgorithmVersions");
81 const bool appendTimestamp =
getProperty(
"AppendTimestamp");
82 const bool appendExecCount =
getProperty(
"AppendExecCount");
83 const std::vector<std::string> ignoreTheseAlgs =
getProperty(
"IgnoreTheseAlgs");
84 const std::vector<std::vector<std::string>> ignoreTheseAlgProperties =
getProperty(
"IgnoreTheseAlgProperties");
97 if (!startTime.empty()) {
98 if (endTime.empty()) {
100 view->filterBetweenExecDate(DateAndTime(startTime));
102 view->filterBetweenExecDate(DateAndTime(startTime), DateAndTime(endTime));
106 std::string versionSpecificity;
107 if (saveVersions ==
"Specify Old")
108 versionSpecificity =
"old";
109 else if (saveVersions ==
"Specify None")
110 versionSpecificity =
"none";
112 versionSpecificity =
"all";
114 ScriptBuilder builder(view, versionSpecificity, appendTimestamp, ignoreTheseAlgs, ignoreTheseAlgProperties,
116 std::string generatedScript;
120 generatedScript +=
"# Python script generated by Mantid\n";
121 generatedScript +=
"# Version " + mantidVersion +
"\n";
122 generatedScript +=
"# SHA-1 " + gitSHA +
"\n\n";
124 generatedScript += builder.
build();
130 if (!filename.empty()) {
131 std::ofstream file(filename.c_str(), std::ofstream::trunc);
132 file << generatedScript;
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
@ OptionalSave
to specify a file to write to but an empty string is
This class build a sttring which cana be executed as a python script.
const std::string build()
build a python script from the history view
This class stores information about the Workspace History used by algorithms on a workspace and the e...
std::shared_ptr< HistoryView > createView() const
Create a flat view of the workspaces algorithm history.
size_t size() const
How many entries are there.
A property class for workspaces.
GeneratePythonScript : TODO: DESCRIPTION.
void exec() override
Run the algorithm.
void init() override
Initialise the properties.
The Logger class is in charge of the publishing messages from the framework through various channels.
void information(const std::string &msg)
Logs at information level.
static const char * version()
The full version number.
static const char * revisionFull()
The full SHA-1 of the last commit.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
@ Input
An input workspace.
@ Output
An output workspace.