20using Mantid::Types::Core::DateAndTime;
38 "An input workspace.");
40 std::vector<std::string> exts{
".py"};
43 "The name of the file into which the workspace history will "
46 declareProperty(
"ScriptText", std::string(
""),
"Saves the history of the workspace to a variable.",
51 declareProperty(
"StartTimestamp", std::string(
""),
"The filter start time in the format YYYY-MM-DD HH:mm:ss",
54 declareProperty(
"EndTimestamp", std::string(
""),
"The filter end time in the format YYYY-MM-DD HH:mm:ss",
57 declareProperty(
"AppendTimestamp",
false,
"Appends the time the command was run as a comment afterwards",
60 std::vector<std::string> saveVersions{
"Specify Old",
"Specify All",
"Specify None"};
61 declareProperty(
"SpecifyAlgorithmVersions",
"Specify Old", std::make_shared<StringListValidator>(saveVersions),
62 "When to specify which algorithm version was used by Mantid.");
67 declareProperty(
"IgnoreTheseAlgProperties", std::vector<std::vector<std::string>>(),
68 "A list of algorithm properties to filter out of the built script",
Direction::Input);
69 declareProperty(
"AppendExecCount",
false,
"Whether execCount should be appended to the end of the built string");
72 "Whether the header comments should be excluded from the beginning of the built string");
80 const std::string startTime =
getProperty(
"StartTimestamp");
81 const std::string endTime =
getProperty(
"EndTimestamp");
82 const std::string saveVersions =
getProperty(
"SpecifyAlgorithmVersions");
83 const bool appendTimestamp =
getProperty(
"AppendTimestamp");
84 const bool appendExecCount =
getProperty(
"AppendExecCount");
85 const bool excludeHeader =
getProperty(
"ExcludeHeader");
86 const std::vector<std::string> ignoreTheseAlgs =
getProperty(
"IgnoreTheseAlgs");
87 const std::vector<std::vector<std::string>> ignoreTheseAlgProperties =
getProperty(
"IgnoreTheseAlgProperties");
100 if (!startTime.empty()) {
101 if (endTime.empty()) {
103 view->filterBetweenExecDate(DateAndTime(startTime));
105 view->filterBetweenExecDate(DateAndTime(startTime), DateAndTime(endTime));
109 std::string versionSpecificity;
110 if (saveVersions ==
"Specify Old")
111 versionSpecificity =
"old";
112 else if (saveVersions ==
"Specify None")
113 versionSpecificity =
"none";
115 versionSpecificity =
"all";
117 ScriptBuilder builder(view, versionSpecificity, appendTimestamp, ignoreTheseAlgs, ignoreTheseAlgProperties,
119 std::string generatedScript;
121 if (!excludeHeader) {
126 generatedScript +=
"# Python script generated by Mantid\n";
127 generatedScript +=
"# Version " + mantidVersion +
"\n";
128 generatedScript +=
"# SHA-1 " + gitSHA +
"\n\n";
131 generatedScript += builder.
build();
137 if (!filename.empty()) {
138 std::ofstream file(filename.c_str(), std::ofstream::trunc);
139 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.