Skip to content
Snippets Groups Projects
Commit 325a1f44 authored by Jan Reher's avatar Jan Reher
Browse files

Implemented reading of csv config file in test mode (very verbose).

parent 3aac9e99
No related branches found
No related tags found
2 merge requests!4Many proven updates being brought into stable branch.,!3Commented in the lines in apdUnitCreator.cpp that do the actual database
Pipeline #1593 failed with stages
in 2 seconds
...@@ -7,6 +7,7 @@ find_package(Qt5 COMPONENTS Core Gui Widgets Network Xml) ...@@ -7,6 +7,7 @@ find_package(Qt5 COMPONENTS Core Gui Widgets Network Xml)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/includes/) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/includes/)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/proddb/) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/proddb/)
INCLUDE_DIRECTORIES($ENV{proddb_clientlib_includes}) INCLUDE_DIRECTORIES($ENV{proddb_clientlib_includes})
INCLUDE_DIRECTORIES("/home/tau/jreher/git/proddb-clientlib")
LINK_DIRECTORIES($ENV{proddb_clientlib_libpath}) LINK_DIRECTORIES($ENV{proddb_clientlib_libpath})
add_library(toolbox "toolbox.cpp" "serialListReader.h" "serialListReader.cxx" "gridListReader.h" "gridListReader.cxx") add_library(toolbox "toolbox.cpp" "serialListReader.h" "serialListReader.cxx" "gridListReader.h" "gridListReader.cxx")
......
...@@ -11,15 +11,20 @@ using namespace std; ...@@ -11,15 +11,20 @@ using namespace std;
using namespace ProductionDatabase; using namespace ProductionDatabase;
namespace po = boost::program_options; namespace po = boost::program_options;
struct unitInfo {
std::string redSerial = "";
std::string blueSerial = "";
std::string crystalSerial = "";
std::string barCode = "";
};
static string fileName = "serials.dat"; static string fileName = "serials.dat";
static int boxNo = 0; static int boxNo = 0;
static bool debug = false; static bool debug = false;
static string username = ""; static string username = "";
static string password = ""; static string password = "";
static vector<string> apdSerials; static vector<unitInfo> newUnits;
static std::vector<int> boxes;
static std::vector<int> positions;
void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]); void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]);
void loadSerialsFromFileName(string m_fileName, bool m_debug = false); void loadSerialsFromFileName(string m_fileName, bool m_debug = false);
...@@ -33,29 +38,27 @@ int main(int argc, char* argv[]) { ...@@ -33,29 +38,27 @@ int main(int argc, char* argv[]) {
loadSerialsFromFileName(fileName); loadSerialsFromFileName(fileName);
if (username == "" || password == "") proddb->queryCredentials(); // if (username == "" || password == "") proddb->queryCredentials();
else proddb->setCredentials(username, password); // else proddb->setCredentials(username, password);
DatabaseClientResponse response = proddb->checkConnectivityAndCredentials(); // DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
if (response != Successful ) { // if (response != Successful ) {
cerr << "Connection to database failed because of error: " << response << endl; // cerr << "Connection to database failed because of error: " << response << endl;
return response; // return response;
} // }
if (debug) cout << "Connection successful!" << endl; // if (debug) cout << "Connection successful!" << endl;
proddb->storeApdBoxNumber(apdSerials,boxes,positions);
cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs." // cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
<< "\nThank you for using apdBoxSetter! :)" << endl << endl; // << "\nThank you for using apdBoxSetter! :)" << endl << endl;
return (-apdSerials.empty()); return (-newUnits.empty());
} }
void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) { void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
po::options_description desc("Available options"); po::options_description desc("Available options");
desc.add_options() desc.add_options()
("help", "produce help message") ("help", "produce help message")
("type", po::value<string>(), "(required) type of APDs [new, irr]")
("box", po::value<int>(), "(required) box number to be assigned")
("fileName", po::value<string>(), "file name or serial numbers [serials.dat]") ("fileName", po::value<string>(), "file name or serial numbers [serials.dat]")
("debug", "emit additional messages for debugging purposes") ("debug", "emit additional messages for debugging purposes")
("user", po::value<string>(), "User name to connect to DB. Only used when combined with pass!") ("user", po::value<string>(), "User name to connect to DB. Only used when combined with pass!")
...@@ -69,21 +72,6 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) { ...@@ -69,21 +72,6 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
cout << desc << "\n"; cout << desc << "\n";
exit(0); exit(0);
} }
if (vm.count("box")) {
boxNo = int(vm["box"].as<int>());
} else {
cout << "Which box should these APDs be assigned to?" << endl;
try {
cin >> boxNo;
cout << endl;
} catch (...) {
boxNo = 0;
}
if (boxNo <= 0) {
cerr << "Invalid batch number!" << endl;
exit(-1);
}
}
if (vm.count("fileName")) { if (vm.count("fileName")) {
fileName = vm["fileName"].as<string>(); fileName = vm["fileName"].as<string>();
cout << "Reading serials from " << fileName << endl; cout << "Reading serials from " << fileName << endl;
...@@ -106,9 +94,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) { ...@@ -106,9 +94,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
exit(0); exit(0);
} }
apdSerials.clear(); newUnits.clear();
positions.clear();
boxes.clear();
int pos = 1; int pos = 1;
...@@ -119,19 +105,18 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) { ...@@ -119,19 +105,18 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
pos++; pos++;
continue; continue;
} }
apdSerials.push_back(line); unitInfo newUnit;
boxes.push_back(boxNo);
positions.push_back(pos++); std::stringstream linestream(line);
linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> newUnit.barCode;
std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
newUnits.push_back(newUnit);
if (m_debug) cout << "Found serial: " << line << endl; if (m_debug) cout << "Found serial: " << line << endl;
} }
if (apdSerials.size() != positions.size() || apdSerials.size() != boxes.size()) {
cerr << "ERROR: Array sizes don't match!" << endl; cerr << "Found " << newUnits.size() << " new Units to be entered." << endl;
apdSerials.clear();
boxes.clear();
positions.clear();
return;
}
cerr << "Found " << apdSerials.size() << " APDs" << endl;
return; return;
} }
......
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