remove ini parsing

This commit is contained in:
karenzshea 2016-02-12 20:11:35 -05:00 committed by Patrick Niklaus
parent 2679c1cf0a
commit b80e96547e
6 changed files with 57 additions and 192 deletions

View File

@ -1,28 +0,0 @@
#ifndef INI_FILE_HPP
#define INI_FILE_HPP
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <algorithm>
#include <string>
namespace osrm
{
namespace util
{
// support old capitalized option names by down-casing them with a regex replace
inline std::string read_file_lower_content(const boost::filesystem::path &path)
{
boost::filesystem::fstream config_stream(path);
std::string ini_file_content((std::istreambuf_iterator<char>(config_stream)),
std::istreambuf_iterator<char>());
std::transform(std::begin(ini_file_content), std::end(ini_file_content),
std::begin(ini_file_content), ::tolower);
return ini_file_content;
}
}
}
#endif // INI_FILE_HPP

View File

@ -1,13 +1,15 @@
#ifndef ROUTED_OPTIONS_HPP
#define ROUTED_OPTIONS_HPP
#include "util/ini_file.hpp"
#include "util/version.hpp"
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include <boost/any.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <unordered_map>
#include <fstream>
@ -139,8 +141,7 @@ GenerateServerProgramOptions(const int argc,
"Path to a configuration file") //
("trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
// declare a group of options that will be allowed both on command line
// as well as in a config file
// declare a group of options that will be allowed on command line
boost::program_options::options_description config_options("Configuration");
config_options.add_options() //
("hsgrdata", value<boost::filesystem::path>(&paths["hsgrdata"]), ".hsgr file") //
@ -172,8 +173,7 @@ GenerateServerProgramOptions(const int argc,
("max-matching-size", value<int>(&max_locations_map_matching)->default_value(100),
"Max. locations supported in map matching query");
// hidden options, will be allowed both on command line and in config
// file, but will not be shown to the user
// hidden options, will be allowed on command line, but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()("base,b", value<boost::filesystem::path>(&paths["base"]),
"base path to .osrm file");
@ -186,9 +186,6 @@ GenerateServerProgramOptions(const int argc,
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]");
visible_options.add(generic_options).add(config_options);
@ -215,20 +212,6 @@ GenerateServerProgramOptions(const int argc,
boost::program_options::notify(option_variables);
// parse config file
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
std::string ini_file_contents = read_file_lower_content(path_iterator->second);
std::stringstream config_stream(ini_file_contents);
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
return INIT_OK_START_ENGINE;
}
if (1 > requested_num_threads)
{
throw exception("Number of threads must be a positive number");

View File

@ -28,13 +28,9 @@ parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"config,c",
boost::program_options::value<boost::filesystem::path>(&contractor_config.config_file_path)
->default_value("contractor.ini"),
"Path to a configuration file.");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message");
// declare a group of options that will be allowed both on command line and in config file
// declare a group of options that will be allowed on command line
boost::program_options::options_description config_options("Configuration");
config_options.add_options()(
"profile,p",
@ -62,8 +58,7 @@ parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_
"Write out edge-weight debugging geometry data in GeoJSON format to this file");
#endif
// hidden options, will be allowed both on command line and in config file, but will not be
// shown to the user
// hidden options, will be allowed on command line, but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
&contractor_config.osrm_input_path),
@ -77,9 +72,6 @@ parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
"Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
visible_options.add(generic_options).add(config_options);
@ -92,14 +84,6 @@ parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_
.run(),
option_variables);
const auto &temp_config_path = option_variables["config"].as<boost::filesystem::path>();
if (boost::filesystem::is_regular_file(temp_config_path))
{
boost::program_options::store(boost::program_options::parse_config_file<char>(
temp_config_path.string().c_str(), cmdline_options, true),
option_variables);
}
if (option_variables.count("version"))
{
util::SimpleLogger().Write() << OSRM_VERSION;

View File

@ -1,7 +1,6 @@
#include "extractor/extractor.hpp"
#include "extractor/extractor_config.hpp"
#include "util/simple_logger.hpp"
#include "util/ini_file.hpp"
#include "util/version.hpp"
#include <tbb/task_scheduler_init.h>
@ -27,13 +26,9 @@ parseArguments(int argc, char *argv[], extractor::ExtractorConfig &extractor_con
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"config,c",
boost::program_options::value<boost::filesystem::path>(&extractor_config.config_file_path)
->default_value("extractor.ini"),
"Path to a configuration file.");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message");
// declare a group of options that will be allowed both on command line and in config file
// declare a group of options that will be allowed both on command line
boost::program_options::options_description config_options("Configuration");
config_options.add_options()(
"profile,p",
@ -61,7 +56,7 @@ parseArguments(int argc, char *argv[], extractor::ExtractorConfig &extractor_con
"Write out GeoJSON with turn penalty data");
#endif // DEBUG_GEOMETRY
// hidden options, will be allowed both on command line and in config file, but will not be
// hidden options, will be allowed on command line, but will not be
// shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
@ -76,9 +71,6 @@ parseArguments(int argc, char *argv[], extractor::ExtractorConfig &extractor_con
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
visible_options.add(generic_options).add(config_options);
@ -106,19 +98,6 @@ parseArguments(int argc, char *argv[], extractor::ExtractorConfig &extractor_con
boost::program_options::notify(option_variables);
// parse config file
if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
{
util::SimpleLogger().Write() << "Reading options from: "
<< extractor_config.config_file_path.string();
std::string ini_file_contents =
util::read_file_lower_content(extractor_config.config_file_path);
std::stringstream config_stream(ini_file_contents);
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
}
if (!option_variables.count("input"))
{
util::SimpleLogger().Write() << visible_options;

View File

@ -1,5 +1,4 @@
#include "server/server.hpp"
#include "util/ini_file.hpp"
#include "util/routed_options.hpp"
#include "util/simple_logger.hpp"

View File

@ -2,10 +2,9 @@
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
#include "util/ini_file.hpp"
#include "util/version.hpp"
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
using namespace osrm;
@ -18,10 +17,7 @@ bool generateDataStoreOptions(const int argc,
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"springclean,s", "Remove all regions in shared memory")(
"config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])
->default_value("server.ini"),
"Path to a configuration file");
"springclean,s", "Remove all regions in shared memory");
// declare a group of options that will be allowed both on command line
// as well as in a config file
@ -46,8 +42,7 @@ bool generateDataStoreOptions(const int argc,
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
".timestamp file");
// hidden options, will be allowed both on command line and in config
// file, but will not be shown to the user
// hidden options, will be allowed on command line but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()(
"base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
@ -61,9 +56,6 @@ bool generateDataStoreOptions(const int argc,
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>");
visible_options.add(generic_options).add(config_options);
@ -97,50 +89,7 @@ bool generateDataStoreOptions(const int argc,
boost::program_options::notify(option_variables);
const bool parameter_present =
(paths.find("hsgrdata") != paths.end() &&
!paths.find("hsgrdata")->second.string().empty()) ||
(paths.find("nodesdata") != paths.end() &&
!paths.find("nodesdata")->second.string().empty()) ||
(paths.find("edgesdata") != paths.end() &&
!paths.find("edgesdata")->second.string().empty()) ||
(paths.find("geometry") != paths.end() &&
!paths.find("geometry")->second.string().empty()) ||
(paths.find("ramindex") != paths.end() &&
!paths.find("ramindex")->second.string().empty()) ||
(paths.find("fileindex") != paths.end() &&
!paths.find("fileindex")->second.string().empty()) ||
(paths.find("core") != paths.end() && !paths.find("core")->second.string().empty()) ||
(paths.find("timestamp") != paths.end() &&
!paths.find("timestamp")->second.string().empty());
if (parameter_present)
{
if ((paths.find("config") != paths.end() &&
boost::filesystem::is_regular_file(paths.find("config")->second)) ||
option_variables.count("base"))
{
util::SimpleLogger().Write(logWARNING) << "conflicting parameters";
util::SimpleLogger().Write() << visible_options;
return false;
}
}
// parse config file
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
util::SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
std::string ini_file_contents = util::read_file_lower_content(path_iterator->second);
std::stringstream config_stream(ini_file_contents);
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
}
else if (option_variables.count("base"))
{
path_iterator = paths.find("base");
auto path_iterator = paths.find("base");
BOOST_ASSERT(paths.end() != path_iterator);
std::string base_string = path_iterator->second.string();
@ -197,7 +146,6 @@ bool generateDataStoreOptions(const int argc,
{
path_iterator->second = base_string + ".timestamp";
}
}
path_iterator = paths.find("hsgrdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||