OpenTREP Logo  0.08.02
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
opentrep-dbmgr.cpp File Reference
#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 Documentation

◆ WordList_T

typedef std::vector<std::string> WordList_T

Definition at line 29 of file opentrep-dbmgr.cpp.

◆ TokenList_T

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.

Function Documentation

◆ K_OPENTREP_DEFAULT_LOG_FILENAME()

const std::string K_OPENTREP_DEFAULT_LOG_FILENAME ( "opentrep-dbmgr.log" )

Default name and location for the log file.

◆ operator<<()

template<class T>
std::ostream & operator<< ( std::ostream & os,
const std::vector< T > & v )

Definition at line 83 of file opentrep-dbmgr.cpp.

◆ readConfiguration()

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 )

◆ initReadline()

void initReadline ( swift::SReadline & ioInputReader)

Definition at line 286 of file opentrep-dbmgr.cpp.

References swift::SReadline::RegisterCompletions().

Referenced by main().

◆ extractCommand()

◆ parseConnectionString()

void parseConnectionString ( const TokenList_T & iTokenList,
std::string & ioConnectionString )

Definition at line 410 of file opentrep-dbmgr.cpp.

◆ parsePlaceKey()

void parsePlaceKey ( const TokenList_T & iTokenList,
std::string & ioPlaceKey )

Definition at line 424 of file opentrep-dbmgr.cpp.

Referenced by processUserCommand().

◆ toString()

◆ extractTokenList()

TokenList_T extractTokenList ( const TokenList_T & iTokenList,
const std::string & iRegularExpression )

◆ extractTokenListForIataCode()

TokenList_T extractTokenListForIataCode ( const TokenList_T & iTokenList)

Definition at line 490 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ extractTokenListForIcaoCode()

TokenList_T extractTokenListForIcaoCode ( const TokenList_T & iTokenList)

Definition at line 504 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ extractTokenListForFaaCode()

TokenList_T extractTokenListForFaaCode ( const TokenList_T & iTokenList)

Definition at line 518 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ extractTokenListForUNLOCode()

TokenList_T extractTokenListForUNLOCode ( const TokenList_T & iTokenList)

Definition at line 532 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ extractTokenListForUICCode()

TokenList_T extractTokenListForUICCode ( const TokenList_T & iTokenList)

Definition at line 546 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ extractTokenListForGeonameID()

TokenList_T extractTokenListForGeonameID ( const TokenList_T & iTokenList)

Definition at line 560 of file opentrep-dbmgr.cpp.

References extractTokenList().

Referenced by processUserCommand().

◆ requireSQLDatabase()

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().

◆ splitCommandLine()

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().

◆ processUserCommand()

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().

◆ main()

Variable Documentation

◆ K_OPENTREP_EARLY_RETURN_STATUS

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.