Skip to content

Commit

Permalink
Fixed callbacks and doc updates (#4243)
Browse files Browse the repository at this point in the history
* Fixed callbacks and doc updates

* added some extra docs
  • Loading branch information
jessemapel committed Jan 7, 2021
1 parent 67f1e73 commit 05cf919
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
24 changes: 9 additions & 15 deletions isis/src/base/apps/topds4/topds4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ namespace Isis {
Process p;
p.SetInputCube(icube);

// Setup the output file so that we can use it in callbacks
QString outputFile = ui.GetFileName("TO");

// NEED TO WRITE AND CLOSE THE OUTPUT FILE BEFORE RENDERING SO THE FILE SIZE CALLBACK CAN GET THE FINAL FILE SIZE

// Name for output image
FileName outputFileName(outputFile);
QString path(outputFileName.originalPath());
Expand Down Expand Up @@ -157,27 +156,26 @@ namespace Isis {
});

/**
* Renders to the filename of the output img
* Renders to the filename of the output image file
*/
env.add_callback("imageFileName", 0, [icube](Arguments& args) {
QString cubeFilename = icube->fileName().split("/").back();
return (cubeFilename.split(".")[0] + ".img").toStdString();
env.add_callback("imageFileName", 0, [outputCubePath](Arguments& args) {
return outputCubePath.split("/").back().toStdString();
});

/**
* Renders to the final file size in bytes of the output cube or img
* Renders to the final file size in bytes of the output image file
*/
env.add_callback("outputFileSize", 0, [outputFile](Arguments& args) {
FileName cubeFilename = outputFile;
return QFile(outputFile).size();
return QFile(outputFile).size();
});

/**
* Renders to the MD5 hash for the input cube
* Renders to the MD5 hash for the output image file
*/
env.add_callback("md5Hash", 0, [icube](Arguments& args) {
env.add_callback("md5Hash", 0, [outputCubePath](Arguments& args) {
md5wrapper md5;
return md5.getHashFromFile(icube->fileName()).toStdString();
return md5.getHashFromFile(outputCubePath).toStdString();
});

std::string inputTemplate = ui.GetFileName("TEMPLATE").toStdString();
Expand All @@ -192,9 +190,5 @@ namespace Isis {
jsonDataFile << dataSource.dump(4);
jsonDataFile.close();
}

std::cout << "============Result===============" << std::endl;
std::cout << result << std::endl;
std::cout << "=================================" << std::endl;
}
}
15 changes: 12 additions & 3 deletions isis/src/base/apps/topds4/topds4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
</p>
<p>
The image file is generated from the input ISIS cube specified by the FROM parameter.
The format of the output image file can be either an ISIS cube or a raw binary file containing
only the image DNs (i.e., no header or trailing data).
The output image file will a copy of the input ISIS cube with the image data stored in
Band Sequential format.
</p>
<p>
This application uses the <a href=https://pantor.github.io/inja/>Inja templating engine</a>
to render the template file. The input data from the cube and extra data sources
is converted to JSON and then it is accessed via the Inja templating syntax.
See the <a href=https://pantor.github.io/inja/>Inja documentation</a> for the full template
syntax. The data from the label of the input cube is accessible under "MainLabel",
the data from the original label of the input cube is accessible under "OriginalLabel",
and the extra data is accessible under "ExtraPvl", "ExtraXml", and "ExtraJson".
</p>
</description>

Expand Down Expand Up @@ -65,7 +74,7 @@
</brief>
<description>
The output file name of the PDS4 label. The output image name will be derived from this
parameter by removing the last extension and adding .cub
parameter by removing the last extension and adding .cub.
</description>
</parameter>
</group>
Expand Down
5 changes: 3 additions & 2 deletions isis/tests/FunctionalTestsTopds4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,13 @@ TEST_F(SmallCube, FunctionalTestTopds4ImageFileName) {
renderedStream.open(renderedFile.toStdString());
std::string line;
std::getline(renderedStream, line);
EXPECT_EQ("small.img", line);
EXPECT_EQ("current_time.cub", line);
}

TEST_F(SmallCube, FunctionalTestTopds4MD5Hash) {
QString templateFile = tempDir.path()+"/current_time.tpl";
QString renderedFile = tempDir.path()+"/current_time.txt";
QString renderedCube = tempDir.path()+"/current_time.cub";
std::ofstream of;
of.open(templateFile.toStdString());
of << "{{md5Hash()}}";
Expand All @@ -375,5 +376,5 @@ TEST_F(SmallCube, FunctionalTestTopds4MD5Hash) {
std::string line;
std::getline(renderedStream, line);
md5wrapper md5;
EXPECT_EQ(md5.getHashFromFile(testCube->fileName()).toStdString(), line);
EXPECT_EQ(md5.getHashFromFile(renderedCube).toStdString(), line);
}

0 comments on commit 05cf919

Please sign in to comment.