#include <cassert>#include <iostream>#include <sstream>#include <fstream>#include <vector>#include <string>#include <boost/date_time/posix_time/posix_time.hpp>#include <boost/date_time/gregorian/gregorian.hpp>#include <boost/regex.hpp>#include <boost/tokenizer.hpp>#include <boost/algorithm/string.hpp>#include <boost/program_options.hpp>#include <opentrep/ui/cmdline/SReadline.hpp>#include <opentrep/OPENTREP_Service.hpp>#include <opentrep/OPENTREP_exceptions.hpp>#include <opentrep/Location.hpp>#include <opentrep/CityDetails.hpp>#include <opentrep/basic/BasConst_OPENTREP_Service.hpp>#include <opentrep/basic/Utilities.hpp>#include <opentrep/config/opentrep-paths.hpp>#include <opentrep/service/Logger.hpp>Go to the source code of this file.
Classes | |
| struct | Command_T |
Typedefs | |
| typedef std::vector< std::string > | WordList_T |
| typedef std::vector< std::string > | TokenList_T |
Functions | |
| const std::string | K_OPENTREP_DEFAULT_LOG_FILENAME ("opentrep-dbmgr.log") |
| template<class T> | |
| std::ostream & | operator<< (std::ostream &os, const std::vector< T > &v) |
| 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::string &ioCommand) |
| void | initReadline (swift::SReadline &ioInputReader) |
| Command_T::Type_T | extractCommand (TokenList_T &ioTokenList) |
| void | parseConnectionString (const TokenList_T &iTokenList, std::string &ioConnectionString) |
| void | parsePlaceKey (const TokenList_T &iTokenList, std::string &ioPlaceKey) |
| std::string | toString (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenList (const TokenList_T &iTokenList, const std::string &iRegularExpression) |
| TokenList_T | extractTokenListForIataCode (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenListForIcaoCode (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenListForFaaCode (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenListForUNLOCode (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenListForUICCode (const TokenList_T &iTokenList) |
| TokenList_T | extractTokenListForGeonameID (const TokenList_T &iTokenList) |
| bool | requireSQLDatabase (const OPENTREP::DBType &iDBType, const std::string &iCommandName) |
| std::vector< std::string > | splitCommandLine (const std::string &iCommandLine) |
| Command_T::Type_T | processUserCommand (const std::string &iUserInput, TokenList_T &ioTokenList, OPENTREP::OPENTREP_Service &ioOpentrepService, const OPENTREP::DBType &iDBType, const std::string &iLogFilename, const std::string &iPORFilepathStr, OPENTREP::DeploymentNumber_T &ioDeploymentNumber, OPENTREP::shouldIndexNonIATAPOR_T &ioIncludeNonIATAPOR, OPENTREP::shouldIndexPORInXapian_T &ioShouldIndexPORInXapian, OPENTREP::shouldAddPORInSQLDB_T &ioShouldAddPORInSQLDB) |
| int | main (int argc, char *argv[]) |
Variables | |
| const int | K_OPENTREP_EARLY_RETURN_STATUS = 99 |
| typedef std::vector<std::string> WordList_T |
Definition at line 29 of file opentrep-dbmgr.cpp.
| typedef std::vector<std::string> TokenList_T |
List of strings, representing the tokens as entered by the user on a command-line.
Definition at line 47 of file opentrep-dbmgr.cpp.
| const std::string K_OPENTREP_DEFAULT_LOG_FILENAME | ( | "opentrep-dbmgr.log" | ) |
Default name and location for the log file.
| std::ostream & operator<< | ( | std::ostream & | os, |
| const std::vector< T > & | v ) |
Definition at line 83 of file opentrep-dbmgr.cpp.
| 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::string & | ioCommand ) |
Read and parse the command line options.
Definition at line 92 of file opentrep-dbmgr.cpp.
References OPENTREP::DEFAULT_OPENTREP_ADD_IN_DB, OPENTREP::DEFAULT_OPENTREP_DEPLOYMENT_NUMBER, OPENTREP::DEFAULT_OPENTREP_INCLUDE_NONIATA_POR, OPENTREP::DEFAULT_OPENTREP_INDEX_IN_XAPIAN, OPENTREP::DEFAULT_OPENTREP_MYSQL_CONN_STRING, OPENTREP::DEFAULT_OPENTREP_PG_CONN_STRING, OPENTREP::DEFAULT_OPENTREP_POR_FILEPATH, OPENTREP::DEFAULT_OPENTREP_SQL_DB_TYPE, OPENTREP::DEFAULT_OPENTREP_SQLITE_DB_FILEPATH, OPENTREP::DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH, K_OPENTREP_DEFAULT_LOG_FILENAME(), K_OPENTREP_EARLY_RETURN_STATUS, OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP::parseAndDisplayConnectionString(), OPENTREP::DBType::PG, and OPENTREP::DBType::SQLITE3.
Referenced by main().
| void initReadline | ( | swift::SReadline & | ioInputReader | ) |
Definition at line 286 of file opentrep-dbmgr.cpp.
References swift::SReadline::RegisterCompletions().
Referenced by main().
| Command_T::Type_T extractCommand | ( | TokenList_T & | ioTokenList | ) |
Definition at line 323 of file opentrep-dbmgr.cpp.
References Command_T::CREATE_INDEXES, Command_T::CREATE_TABLES, Command_T::CREATE_USER, Command_T::FILL_FROM_POR_FILE, Command_T::HELP, Command_T::INFO, Command_T::LAST_VALUE, Command_T::LIST_ALL, Command_T::LIST_BY_FAA, Command_T::LIST_BY_GEONAMEID, Command_T::LIST_BY_IATA, Command_T::LIST_BY_ICAO, Command_T::LIST_BY_UICCODE, Command_T::LIST_BY_UNLOCODE, Command_T::LIST_CONT, Command_T::LIST_NB, Command_T::NOP, Command_T::QUIT, Command_T::RESET_CONNECTION_STRING, Command_T::TOGGLE_DEPLOYMENT_NUMBER, Command_T::TOGGLE_NONIATA_INDEXING_FLAG, Command_T::TOGGLE_SQLDB_INSERTING_FLAG, Command_T::TOGGLE_XAPIAN_IDEXING_FLAG, and Command_T::TUTORIAL.
Referenced by processUserCommand().
| void parseConnectionString | ( | const TokenList_T & | iTokenList, |
| std::string & | ioConnectionString ) |
Definition at line 410 of file opentrep-dbmgr.cpp.
| void parsePlaceKey | ( | const TokenList_T & | iTokenList, |
| std::string & | ioPlaceKey ) |
Definition at line 424 of file opentrep-dbmgr.cpp.
Referenced by processUserCommand().
| std::string toString | ( | const TokenList_T & | iTokenList | ) |
Definition at line 437 of file opentrep-dbmgr.cpp.
Referenced by extractTokenList(), OPENTREP::Result::fullTextMatch(), processUserCommand(), OPENTREP::Place::toStream(), OPENTREP::Result::toStream(), OPENTREP::ResultCombination::toStream(), and OPENTREP::ResultHolder::toStream().
| TokenList_T extractTokenList | ( | const TokenList_T & | iTokenList, |
| const std::string & | iRegularExpression ) |
Definition at line 454 of file opentrep-dbmgr.cpp.
References toString().
Referenced by extractTokenListForFaaCode(), extractTokenListForGeonameID(), extractTokenListForIataCode(), extractTokenListForIcaoCode(), extractTokenListForUICCode(), and extractTokenListForUNLOCode().
| TokenList_T extractTokenListForIataCode | ( | const TokenList_T & | iTokenList | ) |
Definition at line 490 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| TokenList_T extractTokenListForIcaoCode | ( | const TokenList_T & | iTokenList | ) |
Definition at line 504 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| TokenList_T extractTokenListForFaaCode | ( | const TokenList_T & | iTokenList | ) |
Definition at line 518 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| TokenList_T extractTokenListForUNLOCode | ( | const TokenList_T & | iTokenList | ) |
Definition at line 532 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| TokenList_T extractTokenListForUICCode | ( | const TokenList_T & | iTokenList | ) |
Definition at line 546 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| TokenList_T extractTokenListForGeonameID | ( | const TokenList_T & | iTokenList | ) |
Definition at line 560 of file opentrep-dbmgr.cpp.
References extractTokenList().
Referenced by processUserCommand().
| bool requireSQLDatabase | ( | const OPENTREP::DBType & | iDBType, |
| const std::string & | iCommandName ) |
Check that a SQL database has been configured (i.e., that the SQL database type is not 'nodb') before performing a SQL database look-up.
When no SQL database is configured, the underlying OpenTREP service methods (e.g., listByIataCode()) cannot obtain a SOCI database session, and would otherwise fail with an assertion error. So, that check avoids that crash, and instead reports a user-friendly error message.
Definition at line 584 of file opentrep-dbmgr.cpp.
References OPENTREP::DBType::describe(), and OPENTREP::DBType::NODB.
Referenced by processUserCommand().
| std::vector< std::string > splitCommandLine | ( | const std::string & | iCommandLine | ) |
Split a command line into a list of semicolon-separated commands, trimming white spaces around each command and discarding empty ones.
That method is used by the non-interactive command mode (-c/–command option), so that several dbmgr commands may be given at once (e.g., "list_nb ; list_by_iata nce").
Definition at line 608 of file opentrep-dbmgr.cpp.
Referenced by main().
| Command_T::Type_T processUserCommand | ( | const std::string & | iUserInput, |
| TokenList_T & | ioTokenList, | ||
| OPENTREP::OPENTREP_Service & | ioOpentrepService, | ||
| const OPENTREP::DBType & | iDBType, | ||
| const std::string & | iLogFilename, | ||
| const std::string & | iPORFilepathStr, | ||
| OPENTREP::DeploymentNumber_T & | ioDeploymentNumber, | ||
| OPENTREP::shouldIndexNonIATAPOR_T & | ioIncludeNonIATAPOR, | ||
| OPENTREP::shouldIndexPORInXapian_T & | ioShouldIndexPORInXapian, | ||
| OPENTREP::shouldAddPORInSQLDB_T & | ioShouldAddPORInSQLDB ) |
Interpret and execute a single (already tokenised) dbmgr command.
That dispatcher is shared by both the interactive (readline-based) session and the non-interactive command mode (-c/–command option), so that the two modes behave identically for a given command.
Definition at line 635 of file opentrep-dbmgr.cpp.
References Command_T::CREATE_INDEXES, Command_T::CREATE_TABLES, Command_T::CREATE_USER, OPENTREP::OPENTREP_Service::createSQLDBIndexes(), OPENTREP::OPENTREP_Service::createSQLDBTables(), OPENTREP::OPENTREP_Service::createSQLDBUser(), OPENTREP::DEFAULT_OPENTREP_DEPLOYMENT_NUMBER_SIZE, OPENTREP::DBType::describe(), extractCommand(), extractTokenListForFaaCode(), extractTokenListForGeonameID(), extractTokenListForIataCode(), extractTokenListForIcaoCode(), extractTokenListForUICCode(), extractTokenListForUNLOCode(), Command_T::FILL_FROM_POR_FILE, OPENTREP::OPENTREP_Service::getFilePaths(), OPENTREP::OPENTREP_Service::getIndexSize(), OPENTREP::OPENTREP_Service::getNbOfPORFromDB(), Command_T::HELP, Command_T::INFO, OPENTREP::OPENTREP_Service::insertIntoDBAndXapian(), Command_T::LAST_VALUE, Command_T::LIST_ALL, Command_T::LIST_BY_FAA, Command_T::LIST_BY_GEONAMEID, Command_T::LIST_BY_IATA, Command_T::LIST_BY_ICAO, Command_T::LIST_BY_UICCODE, Command_T::LIST_BY_UNLOCODE, Command_T::LIST_NB, OPENTREP::OPENTREP_Service::listByFaaCode(), OPENTREP::OPENTREP_Service::listByGeonameID(), OPENTREP::OPENTREP_Service::listByIataCode(), OPENTREP::OPENTREP_Service::listByIcaoCode(), OPENTREP::OPENTREP_Service::listByUICCode(), OPENTREP::OPENTREP_Service::listByUNLOCode(), OPENTREP::DBType::NODB, Command_T::NOP, OPENTREP_LOG_DEBUG, parsePlaceKey(), Command_T::QUIT, requireSQLDatabase(), Command_T::RESET_CONNECTION_STRING, OPENTREP::OPENTREP_Service::setSQLDBConnectString(), Command_T::TOGGLE_DEPLOYMENT_NUMBER, Command_T::TOGGLE_NONIATA_INDEXING_FLAG, Command_T::TOGGLE_SQLDB_INSERTING_FLAG, Command_T::TOGGLE_XAPIAN_IDEXING_FLAG, OPENTREP::OPENTREP_Service::toggleDeploymentNumber(), OPENTREP::OPENTREP_Service::toggleShouldAddPORInSQLDBFlag(), OPENTREP::OPENTREP_Service::toggleShouldIncludeAllPORFlag(), OPENTREP::OPENTREP_Service::toggleShouldIndexPORInXapianFlag(), OPENTREP::Location::toString(), toString(), Command_T::TUTORIAL, and OPENTREP::RootException::what().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] ) |
Definition at line 1393 of file opentrep-dbmgr.cpp.
References swift::SReadline::GetLine(), initReadline(), K_OPENTREP_EARLY_RETURN_STATUS, Command_T::NOP, OPENTREP_LOG_DEBUG, processUserCommand(), Command_T::QUIT, readConfiguration(), swift::SReadline::SaveHistory(), and splitCommandLine().
| const int K_OPENTREP_EARLY_RETURN_STATUS = 99 |
Early return status (so that it can be differentiated from an error).
Definition at line 41 of file opentrep-dbmgr.cpp.
1.17.0