9 #include <boost/date_time/posix_time/posix_time.hpp>
10 #include <boost/date_time/gregorian/gregorian.hpp>
11 #include <boost/program_options.hpp>
19 #include <opentrep/config/opentrep-paths.hpp>
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) {
64 boost::program_options::options_description
generic (
"Generic options");
66 (
"prefix",
"print installation prefix")
67 (
"version,v",
"print version string")
68 (
"help,h",
"produce help message");
72 boost::program_options::options_description config (
"Configuration");
76 "POR file-path (e.g., optd_por_public.csv)")
79 "Xapian database filepath (e.g., /tmp/opentrep/xapian_traveldb)")
82 "SQL database type (e.g., nodb for no SQL database, sqlite for SQLite, mysql for MariaDB/MySQL)")
84 boost::program_options::value< std::string >(&ioSQLDBConnectionString),
85 "SQL database connection string (e.g., ~/tmp/opentrep/sqlite_travel.db for SQLite, \"db=trep_trep user=trep password=trep\" for MariaDB/MySQL)")
88 "Deployment number (from to N, where N=1 normally)")
91 "Whether or not to include POR not referenced by IATA (0 = only IATA-referenced POR, 1 = all POR are included)")
94 "Whether or not to index the POR in Xapian (0 = do not touch the Xapian index, 1 = re-index all the POR in Xapian)")
97 "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)")
100 "Filepath for the logs")
105 boost::program_options::options_description hidden (
"Hidden options");
108 boost::program_options::value< std::vector<std::string> >(),
109 "Show the copyright (license)");
111 boost::program_options::options_description cmdline_options;
112 cmdline_options.add(
generic).add(config).add(hidden);
114 boost::program_options::options_description config_file_options;
115 config_file_options.add(config).add(hidden);
117 boost::program_options::options_description visible (
"Allowed options");
118 visible.add(
generic).add(config);
120 boost::program_options::positional_options_description p;
121 p.add (
"copyright", -1);
123 boost::program_options::variables_map vm;
124 boost::program_options::
125 store (boost::program_options::command_line_parser (argc, argv).
126 options (cmdline_options).positional(p).run(), vm);
128 std::ifstream ifs (
"opentrep-indexer.cfg");
129 boost::program_options::store (parse_config_file (ifs, config_file_options),
131 boost::program_options::notify (vm);
133 if (vm.count (
"help")) {
134 std::cout << visible << std::endl;
138 if (vm.count (
"version")) {
139 std::cout << PACKAGE_NAME <<
", version " << PACKAGE_VERSION << std::endl;
143 if (vm.count (
"prefix")) {
144 std::cout <<
"Installation prefix: " << PREFIXDIR << std::endl;
148 if (vm.count (
"porfile")) {
149 ioPORFilepath = vm[
"porfile"].as< std::string >();
150 std::cout <<
"POR file-path is: " << ioPORFilepath << std::endl;
153 if (vm.count (
"deploymentnb")) {
154 ioDeploymentNumber = vm[
"deploymentnb"].as<
unsigned short >();
155 std::cout <<
"Deployment number " << ioDeploymentNumber << std::endl;
158 if (vm.count (
"xapiandb")) {
159 ioXapianDBFilepath = vm[
"xapiandb"].as< std::string >();
160 std::cout <<
"Xapian index/database filepath is: " << ioXapianDBFilepath
161 << ioDeploymentNumber << std::endl;
165 if (vm.count (
"sqldbtype")) {
166 ioSQLDBTypeString = vm[
"sqldbtype"].as< std::string >();
167 std::cout <<
"SQL database type is: " << ioSQLDBTypeString
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 std::cout <<
"SQL database connection string is: " << lSQLDBConnString
213 std::cout <<
"Are non-IATA-referenced POR included? "
214 << ioIncludeNonIATAPOR << std::endl;
216 std::cout <<
"Index the POR in Xapian? "
217 << ioIndexPORInXapian << std::endl;
219 std::cout <<
"Add and re-index the POR in the SQL-based database? "
220 << ioAddPORInDB << std::endl;
222 if (vm.count (
"log")) {
223 ioLogFilename = vm[
"log"].as< std::string >();
224 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
232 int main (
int argc,
char* argv[]) {
235 std::string lLogFilename;
238 std::string lPORFilepathStr;
241 std::string lXapianDBNameStr;
244 std::string lSQLDBTypeStr;
247 std::string lSQLDBConnectionStr;
262 const int lOptionParserStatus =
264 lSQLDBTypeStr, lSQLDBConnectionStr, lDeploymentNumber,
265 lIncludeNonIATAPOR, lShouldIndexPORInXapian,
266 lShouldAddPORInSQLDB, lLogFilename);
273 std::ofstream logOutputFile;
275 logOutputFile.open (lLogFilename.c_str());
276 logOutputFile.clear();
279 std::cout <<
"Parsing and indexing the OpenTravelData POR data file (into "
280 <<
"Xapian and/or SQL databases) may take a few tens of minutes "
281 <<
"on some architectures (and a few minutes on fastest ones)..."
290 lXapianDBName, lDBType,
291 lSQLDBConnStr, lDeploymentNumber,
293 lShouldIndexPORInXapian,
294 lShouldAddPORInSQLDB);
301 logOutputFile.close();
304 std::cout << lNbOfEntries <<
" entries have been processed" << std::endl;