Elements 6.1.2
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
ConnectionConfiguration.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2020 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <boost/program_options.hpp>
20#include <string>
21#include <vector>
22
25
26namespace Elements {
27inline namespace Services {
28namespace DataSync {
29
30using std::string;
31
33 parseConfigurationFile(filename);
34}
35
38}
39
41 // @TODO clean function
42
43 namespace po = boost::program_options;
44
45 /* Declare options */
46 po::options_description options{};
47 options.add_options()("host", po::value<string>(), "Hosting solution: iRODS or WebDAV (case insensitive)")(
48 "host-url", po::value<string>()->default_value(""),
49 "Host URL if needed")("user", po::value<string>()->default_value(""), "User name if needed")(
50 "password", po::value<string>()->default_value(""), "Password if needed")(
51 "overwrite", po::value<string>()->default_value("no"), "Allow overwriting local files if they already exist")(
52 "distant-workspace", po::value<string>(), "Path to distant repository workspace")(
53 "local-workspace", po::value<string>(),
54 "Path to local repository workspace")("tries", po::value<int>()->default_value(4), "Number of download tries");
55
56 /* Get config file path */
57 path abs_path = confFilePath(filename);
58
59 /* Read config file */
60 po::variables_map vm;
61 try {
62 po::store(po::parse_config_file<char>(abs_path.c_str(), options), vm);
63 po::notify(vm);
64 } catch (std::exception& e) {
65 throw e.what();
66 }
67
68 /* Configure object */
69 parseHost(vm["host"].as<string>());
70 hostUrl = vm["host-url"].as<string>();
71 user = vm["user"].as<string>();
72 password = vm["password"].as<string>();
73 parseOverwritingPolicy(vm["overwrite"].as<string>());
74 distantRoot = vm["distant-workspace"].as<string>();
75 localRoot = localWorkspacePrefix() / vm["local-workspace"].as<string>();
76 tries = static_cast<size_t>(vm["tries"].as<int>());
77}
78
79void ConnectionConfiguration::parseHost(const string& name) {
80 const string uncased = lower(name);
81 if (uncased == "irods") {
83 } else if (uncased == "webdav") {
85 } else {
86 throw UnknownHost(name);
87 }
88}
89
91
92 using std::vector;
93
94 const vector<string> overwrite_allowed_options = {"true", "yes", "y"};
95 const vector<string> overwrite_forbidden_options = {"false", "no", "n"};
96
97 string uncased = lower(policy);
98 if (valueIsListed(uncased, overwrite_allowed_options)) {
100 } else if (valueIsListed(uncased, overwrite_forbidden_options)) {
102 } else {
103 throw std::runtime_error("I don't know this overwriting policy: " + policy);
104 }
105}
106
107} // namespace DataSync
108} // namespace Services
109} // namespace Elements
ConnectionConfiguration(const path &configFile)
Create a dependency configuration by reading a configuration file.
bool overwritingAllowed() const
Check whether existing local files can be overwritten.
Exception raised when a hosting solution is not supported by the tool.
ELEMENTS_API path confFilePath(path filename)
ELEMENTS_API path localWorkspacePrefix()
ELEMENTS_API std::string lower(std::string text)
Path::Item path
importing the path item from ElementsKernel
Definition: DataSyncUtils.h:41
ELEMENTS_API bool valueIsListed(const T &value, const std::vector< T > &list)
Definition: DataSyncUtils.h:65