Skip to content
Snippets Groups Projects
Commit f32e8dcd authored by Joseph Boudreau's avatar Joseph Boudreau
Browse files

Merge branch 'main-gmcat' into 'main'

gmcat: various changes

See merge request !286
parents fc000174 ca9351d2
No related branches found
No related tags found
1 merge request!286gmcat: various changes
Pipeline #6946382 passed with warnings
...@@ -35,6 +35,7 @@ const std::string shared_obj_extension=".so"; ...@@ -35,6 +35,7 @@ const std::string shared_obj_extension=".so";
void publishMetaData( GMDBManager & db, void publishMetaData( GMDBManager & db,
const std::string& repoPath,
std::vector<std::string> &inputFiles, std::vector<std::string> &inputFiles,
std::vector<std::string> &inputPlugins, std::vector<std::string> &inputPlugins,
std::string &outputFile); std::string &outputFile);
...@@ -48,9 +49,12 @@ int main(int argc, char ** argv) { ...@@ -48,9 +49,12 @@ int main(int argc, char ** argv) {
// //
std::string gmcat= argv[0]; std::string gmcat= argv[0];
std::string usage= "usage: " + gmcat + " [plugin1"+shared_obj_extension std::string usage= "usage: " + gmcat + " [OPTIONS] [plugin1"+shared_obj_extension
+ "] [plugin2" + shared_obj_extension + "] [plugin2" + shared_obj_extension
+ "] ...[file1.db] [file2.db].. -o outputFile]"; + "] ...[file1.db] [file2.db].. -o outputFile]\n"
+ "Options:\n"
+ "\t-v Print verbose output to the screen (default: direct verbose output to /tmp)\n"
+ "\t-g Path to the local GeoModelATLAS repository (default: .)";
// //
// Print usage message if no args given: // Print usage message if no args given:
// //
...@@ -64,6 +68,7 @@ int main(int argc, char ** argv) { ...@@ -64,6 +68,7 @@ int main(int argc, char ** argv) {
std::vector<std::string> inputFiles; std::vector<std::string> inputFiles;
std::vector<std::string> inputPlugins; std::vector<std::string> inputPlugins;
std::string outputFile; std::string outputFile;
std::string gmAtlasDir{"."};
bool outputFileSet = false; bool outputFileSet = false;
for (int argi=1;argi<argc;argi++) { for (int argi=1;argi<argc;argi++) {
std::string argument=argv[argi]; std::string argument=argv[argi];
...@@ -80,6 +85,9 @@ int main(int argc, char ** argv) { ...@@ -80,6 +85,9 @@ int main(int argc, char ** argv) {
setenv("GEOMODEL_GEOMODELIO_VERBOSE", "1", 1); // does overwrite setenv("GEOMODEL_GEOMODELIO_VERBOSE", "1", 1); // does overwrite
verbose=true; verbose=true;
} }
else if (argument.find("-g")!=std::string::npos) {
gmAtlasDir = std::string(argv[++argi]);
}
else if (argument.find(shared_obj_extension)!=std::string::npos) { else if (argument.find(shared_obj_extension)!=std::string::npos) {
inputPlugins.push_back(argument); inputPlugins.push_back(argument);
} }
...@@ -125,16 +133,24 @@ int main(int argc, char ** argv) { ...@@ -125,16 +133,24 @@ int main(int argc, char ** argv) {
// Loop over plugins, create the geometry and put it under the world: // Loop over plugins, create the geometry and put it under the world:
// //
std::ofstream file; std::ofstream file;
std::string verboseOutput{"/tmp/gmcat-"+std::to_string(getpid())};
std::streambuf *coutBuff=std::cout.rdbuf(); std::streambuf *coutBuff=std::cout.rdbuf();
std::streambuf *fileBuff=file.rdbuf(); std::streambuf *fileBuff=file.rdbuf();
if (!verbose) { if (!verbose) {
file.open(("/tmp/gmcat-"+std::to_string(getpid())).c_str()); file.open(verboseOutput.c_str());
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins
for (const std::string & plugin : inputPlugins) { for (const std::string & plugin : inputPlugins) {
GeoGeometryPluginLoader loader; GeoGeometryPluginLoader loader;
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "Building geometry using the plugin " << plugin << " ..." << std::endl;
std::cout.rdbuf(fileBuff);
}
GeoVGeometryPlugin *factory=loader.load(plugin); GeoVGeometryPlugin *factory=loader.load(plugin);
if (!factory) { if (!factory) {
std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl; std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl;
...@@ -151,12 +167,23 @@ int main(int argc, char ** argv) { ...@@ -151,12 +167,23 @@ int main(int argc, char ** argv) {
if( nullptr != factory->getPublisher() ) { if( nullptr != factory->getPublisher() ) {
vecPluginsPublishers.push_back( factory->getPublisher() ); // cache the publisher, if any, for later vecPluginsPublishers.push_back( factory->getPublisher() ); // cache the publisher, if any, for later
} }
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff);
}
} }
// //
// Loop over files, create the geometry and put it under the world: // Loop over files, create the geometry and put it under the world:
// //
for (const std::string & file : inputFiles) { for (const std::string & file : inputFiles) {
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "Reading geometry from the file " << file << " ..." << std::endl;
std::cout.rdbuf(fileBuff);
}
GMDBManager* db = new GMDBManager(file); GMDBManager* db = new GMDBManager(file);
if (!db->checkIsDBOpen()){ if (!db->checkIsDBOpen()){
std::cerr << "gmcat -- Error opening the input file: " << file << std::endl; std::cerr << "gmcat -- Error opening the input file: " << file << std::endl;
...@@ -186,6 +213,12 @@ int main(int argc, char ** argv) { ...@@ -186,6 +213,12 @@ int main(int argc, char ** argv) {
} }
delete db; delete db;
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff);
}
} }
// //
// Open a new database: // Open a new database:
...@@ -205,18 +238,42 @@ int main(int argc, char ** argv) { ...@@ -205,18 +238,42 @@ int main(int argc, char ** argv) {
GeoModelIO::WriteGeoModel dumpGeoModelGraph(db); GeoModelIO::WriteGeoModel dumpGeoModelGraph(db);
resizedWorld->exec(&dumpGeoModelGraph); resizedWorld->exec(&dumpGeoModelGraph);
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "Writing auxiliary tables to the output database ..." << std::endl;
std::cout.rdbuf(fileBuff);
}
if (vecPluginsPublishers.size() > 0) { if (vecPluginsPublishers.size() > 0) {
dumpGeoModelGraph.saveToDB(vecPluginsPublishers); dumpGeoModelGraph.saveToDB(vecPluginsPublishers);
} else { } else {
dumpGeoModelGraph.saveToDB(); dumpGeoModelGraph.saveToDB();
} }
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff);
}
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "Writing metadata to the output database ..." << std::endl;
std::cout.rdbuf(fileBuff);
}
try {
publishMetaData(db,gmAtlasDir,inputFiles,inputPlugins,outputFile);
}
catch(std::runtime_error& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
if(!verbose) {
std::cout.rdbuf(coutBuff);
std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff);
}
publishMetaData(db,inputFiles,inputPlugins,outputFile);
std::cout.rdbuf(coutBuff); std::cout.rdbuf(coutBuff);
std::cout << "SUCCESS!" << std::endl;
std::cout << "(verbose output at " << verboseOutput << ")" << std::endl;
return 0; return 0;
} }
...@@ -33,6 +33,7 @@ std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false) ...@@ -33,6 +33,7 @@ std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false)
} }
void publishMetaData( GMDBManager & db, void publishMetaData( GMDBManager & db,
const std::string& repoPath,
std::vector<std::string> &inputFiles, std::vector<std::string> &inputFiles,
std::vector<std::string> &inputPlugins, std::vector<std::string> &inputPlugins,
std::string &outputFile) { std::string &outputFile) {
...@@ -98,26 +99,30 @@ void publishMetaData( GMDBManager & db, ...@@ -98,26 +99,30 @@ void publishMetaData( GMDBManager & db,
} }
} }
} }
std::string isGitManaged=getCommandOutput("git rev-parse --is-inside-work-tree"); std::string isGitManaged=getCommandOutput("git -C " + repoPath + " rev-parse --is-inside-work-tree");
if (isGitManaged=="true\n") { if (isGitManaged=="true\n") {
xtraMetadata.repo=getCommandOutput("git remote get-url origin"); xtraMetadata.repo=getCommandOutput("git -C " + repoPath + " remote get-url origin");
xtraMetadata.branch=getCommandOutput("git rev-parse --abbrev-ref HEAD"); xtraMetadata.branch=getCommandOutput("git -C " + repoPath + " rev-parse --abbrev-ref HEAD");
std::string status=getCommandOutput("git status --porcelain"); std::string status=getCommandOutput("git -C " + repoPath + " status --porcelain");
if (status.find(" M ")!=std::string::npos) { if (status.find(" M ")!=std::string::npos) {
xtraMetadata.isClean="no"; xtraMetadata.isClean="no";
} }
else { else {
std::string synchedToOrigin=getCommandOutput("git diff origin/"+xtraMetadata.branch,true); std::string synchedToOrigin=getCommandOutput("git -C " + repoPath + " diff origin/"+xtraMetadata.branch,true);
if (synchedToOrigin!="") { if (synchedToOrigin!="") {
xtraMetadata.isClean="no"; xtraMetadata.isClean="no";
} }
else { else {
xtraMetadata.isClean="yes"; xtraMetadata.isClean="yes";
xtraMetadata.commitHash=getCommandOutput("git log -1 --format=format:\"%H\""); xtraMetadata.commitHash=getCommandOutput("git -C " + repoPath + " log -1 --format=format:\"%H\"");
xtraMetadata.associatedTag=getCommandOutput("git describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null"); xtraMetadata.associatedTag=getCommandOutput("git -C " + repoPath + " describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null");
} }
} }
} }
else {
std::cerr << std::endl << "ERROR: provided directory " << repoPath << " is NOT inside a local git reporistory!" << std::endl;
throw std::runtime_error("Metadata not written!");
}
// //
// Fill the header file with metadata // Fill the header file with metadata
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment