53 std::string& ioPORFilepath,
54 std::string& ioXapianDBFilepath,
55 std::string& ioSQLDBTypeString,
56 std::string& ioSQLDBConnectionString,
57 unsigned short& ioDeploymentNumber,
58 bool& ioIncludeNonIATAPOR,
59 bool& ioIndexPORInXapian,
61 std::string& ioLogFilename,
62 std::ostringstream& oStr) {
65 boost::program_options::options_description generic (
"Generic options");
67 (
"prefix",
"print installation prefix")
68 (
"version,v",
"print version string")
69 (
"help,h",
"produce help message");
73 boost::program_options::options_description config (
"Configuration");
77 "POR file-path (e.g., optd_por_public.csv)")
80 "Xapian database filepath (e.g., /tmp/opentrep/xapian_traveldb)")
83 "SQL database type (e.g., nodb for no SQL database, sqlite for SQLite, mysql for MariaDB/MySQL)")
85 boost::program_options::value< std::string >(&ioSQLDBConnectionString),
86 "SQL database connection string (e.g., ~/tmp/opentrep/sqlite_travel.db for SQLite, \"db=trep_trep user=trep password=trep\" for MariaDB/MySQL)")
89 "Deployment number (from to N, where N=1 normally)")
92 "Whether or not to include POR not referenced by IATA (0 = only IATA-referenced POR, 1 = all POR are included)")
95 "Whether or not to index the POR in Xapian (0 = do not touch the Xapian index, 1 = re-index all the POR in Xapian)")
98 "Whether or not to add and index the POR in the SQL-based database (0 = do not touch the SQL-based database, 1 = add and re-index all the POR in the SQL-based database)")
101 "Filepath for the logs")
106 boost::program_options::options_description hidden (
"Hidden options");
109 boost::program_options::value< std::vector<std::string> >(),
110 "Show the copyright (license)");
112 boost::program_options::options_description cmdline_options;
113 cmdline_options.add(generic).add(config).add(hidden);
115 boost::program_options::options_description config_file_options;
116 config_file_options.add(config).add(hidden);
118 boost::program_options::options_description visible (
"Allowed options");
119 visible.add(generic).add(config);
121 boost::program_options::positional_options_description p;
122 p.add (
"copyright", -1);
124 boost::program_options::variables_map vm;
125 boost::program_options::
126 store (boost::program_options::command_line_parser (argc, argv).
127 options (cmdline_options).positional(p).run(), vm);
129 std::ifstream ifs (
"opentrep-indexer.cfg");
130 boost::program_options::store (parse_config_file (ifs, config_file_options),
132 boost::program_options::notify (vm);
134 if (vm.count (
"help")) {
135 std::cout << visible << std::endl;
139 if (vm.count (
"version")) {
140 std::cout << PACKAGE_NAME <<
", version " << PACKAGE_VERSION << std::endl;
144 if (vm.count (
"prefix")) {
145 std::cout <<
"Installation prefix: " << PREFIXDIR << std::endl;
149 if (vm.count (
"porfile")) {
150 ioPORFilepath = vm[
"porfile"].as< std::string >();
151 oStr <<
"POR file-path is: " << ioPORFilepath << std::endl;
154 if (vm.count (
"deploymentnb")) {
155 ioDeploymentNumber = vm[
"deploymentnb"].as<
unsigned short >();
156 oStr <<
"Deployment number: " << ioDeploymentNumber << std::endl;
159 if (vm.count (
"xapiandb")) {
160 ioXapianDBFilepath = vm[
"xapiandb"].as< std::string >();
161 oStr <<
"Xapian index/database filepath is: " << ioXapianDBFilepath
162 << ioDeploymentNumber << std::endl;
166 if (vm.count (
"sqldbtype")) {
167 ioSQLDBTypeString = vm[
"sqldbtype"].as< std::string >();
168 oStr <<
"SQL database type is: " << ioSQLDBTypeString << std::endl;
184 ioAddPORInDB =
false;
185 ioSQLDBConnectionString =
"";
197 if (vm.count (
"sqldbconx")) {
198 ioSQLDBConnectionString = vm[
"sqldbconx"].as< std::string >();
204 const std::string& lSQLDBConnString =
206 ioSQLDBConnectionString,
209 oStr <<
"SQL database connection string is: " << lSQLDBConnString
213 oStr <<
"Are non-IATA-referenced POR included? " << ioIncludeNonIATAPOR
216 oStr <<
"Index the POR in Xapian? " << ioIndexPORInXapian << std::endl;
218 oStr <<
"Add and re-index the POR in the SQL-based database? " << ioAddPORInDB
221 if (vm.count (
"log")) {
222 ioLogFilename = vm[
"log"].as< std::string >();
223 oStr <<
"Log filename is: " << ioLogFilename << std::endl;
231int main (
int argc,
char* argv[]) {
234 std::string lLogFilename;
237 std::string lPORFilepathStr;
240 std::string lXapianDBNameStr;
243 std::string lSQLDBTypeStr;
246 std::string lSQLDBConnectionStr;
261 std::ostringstream oIntroStr;
264 const int lOptionParserStatus =
266 lSQLDBTypeStr, lSQLDBConnectionStr, lDeploymentNumber,
267 lIncludeNonIATAPOR, lShouldIndexPORInXapian,
268 lShouldAddPORInSQLDB, lLogFilename, oIntroStr);
275 std::ofstream logOutputFile;
277 logOutputFile.open (lLogFilename.c_str());
278 logOutputFile.clear();
281 oIntroStr <<
"Parsing and indexing the OpenTravelData POR data file (into "
282 <<
"Xapian and/or SQL databases) may take a few tens of minutes "
283 <<
"on some architectures (and a few minutes on fastest ones)..."
285 std::cout << oIntroStr.str();
289 boost::posix_time::ptime lTimeUTC =
290 boost::posix_time::second_clock::universal_time();
291 logOutputFile <<
"[" << lTimeUTC <<
"][" << __FILE__ <<
"#"
292 << __LINE__ <<
"]:Parameters:" << std::endl
293 << oIntroStr.str() << std::endl;
301 lXapianDBName, lDBType,
302 lSQLDBConnStr, lDeploymentNumber,
304 lShouldIndexPORInXapian,
305 lShouldAddPORInSQLDB);
312 std::ostringstream oStr;
313 oStr << lNbOfEntries <<
" entries have been processed" << std::endl;
314 std::cout << oStr.str();
317 lTimeUTC = boost::posix_time::second_clock::universal_time();
318 logOutputFile <<
"[" << lTimeUTC <<
"][" << __FILE__ <<
"#"
319 << __LINE__ <<
"]:" << oStr.str() << std::endl;
322 logOutputFile.close();
int readConfiguration(int argc, char *argv[], std::string &ioPORFilepath, std::string &ioXapianDBFilepath, std::string &ioSQLDBTypeString, std::string &ioSQLDBConnectionString, unsigned short &ioDeploymentNumber, bool &ioIncludeNonIATAPOR, bool &ioIndexPORInXapian, bool &ioAddPORInDB, std::string &ioLogFilename, std::ostringstream &oStr)