[glom] PostgreSelf: Remove the version number parsing methods.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] PostgreSelf: Remove the version number parsing methods.
- Date: Tue, 1 Sep 2015 10:35:19 +0000 (UTC)
commit 24af4acf7c08065d539bcfffbc104b93056e755b
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Sep 1 12:18:37 2015 +0200
PostgreSelf: Remove the version number parsing methods.
Because they are not used.
(In the previous commit I ported these from Glib::Regex to std::regex
just as a way to learn about the std::regex API and to make sure that I
can bring back working code if I need this again.)
Makefile_tests.am | 6 -
.../connectionpool_backends/postgres_self.cc | 135 --------------------
.../connectionpool_backends/postgres_self.h | 14 --
tests/test_postgres_version_regexes.cc | 52 --------
4 files changed, 0 insertions(+), 207 deletions(-)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 94b1c17..f61b64d 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -27,7 +27,6 @@ check_PROGRAMS = \
tests/test_document_autosave \
tests/test_field_file_format \
tests/test_parsing_time \
- tests/test_postgres_version_regexes \
tests/test_signal_reemit \
tests/python/test_load_python_library\
tests/python/test_python_module \
@@ -69,7 +68,6 @@ TESTS = tests/test_document_load \
tests/test_field_file_format \
tests/test_field_file_format_in_locales.sh \
tests/test_parsing_time \
- tests/test_postgres_version_regexes \
tests/test_signal_reemit \
tests/test_dtd_file_validation.sh \
tests/test_glade_file_validation.sh \
@@ -186,10 +184,6 @@ tests_test_parsing_time_SOURCES = tests/test_parsing_time.cc
tests_test_parsing_time_LDADD = $(tests_ldadd)
tests_test_parsing_time_CPPFLAGS = $(tests_cppflags)
-tests_test_postgres_version_regexes_SOURCES = tests/test_postgres_version_regexes.cc
-tests_test_postgres_version_regexes_LDADD = $(tests_ldadd)
-tests_test_postgres_version_regexes_CPPFLAGS = $(tests_cppflags)
-
tests_test_signal_reemit_SOURCES = tests/test_signal_reemit.cc
tests_test_signal_reemit_LDADD = $(LIBGLOM_LIBS)
tests_test_signal_reemit_CPPFLAGS = $(tests_cppflags)
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc
b/glom/libglom/connectionpool_backends/postgres_self.cc
index ec954c7..14e066c 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -225,141 +225,6 @@ Backend::InitErrors PostgresSelfHosted::initialize(const SlotProgress& slot_prog
return result ? InitErrors::NONE : InitErrors::COULD_NOT_START_SERVER;
}
-Glib::ustring PostgresSelfHosted::get_postgresql_utils_version_from_string(const std::string& version_output)
-{
- Glib::ustring result;
-
- //Use a regex to get the version number:
- std::regex regex;
-
- //We want the characters at the end:
- const gchar VERSION_REGEX[] = "pg_ctl \\(PostgreSQL\\) (\\S+)";
-
- try
- {
- regex = std::regex(VERSION_REGEX);
- }
- catch(const std::regex_error& ex)
- {
- std::cerr << G_STRFUNC << ": std::regex constructor() failed: " << ex.what() << std::endl;
- return result;
- }
-
- // We get, for instance, "\n" and 8.4.1" and "\n".
- //TODO: Find a way to do a simple range-based for over the regex matches?
- auto matches_begin =
- std::sregex_iterator(version_output.begin(), version_output.end(), regex);
- auto matches_end = std::sregex_iterator();
-
- for(auto iter = matches_begin; iter != matches_end; ++iter)
- {
- const auto match = *iter;
-
- //We don't use a range-based for loop, so we can more easily
- //skip the [0] match, which is the full (parent) match:
- auto sub_matches_begin = match.cbegin();
- ++sub_matches_begin; //Skip [0], which is the full (parent) match.
- auto sub_matches_end = match.cend();
- for(auto sub_iter = sub_matches_begin ; sub_iter != sub_matches_end; ++sub_iter)
- {
- const auto& sub = *sub_iter;
- const auto str = sub.str();
- //std::cout << "debug: str=" << str << std::endl;
- if(!str.empty())
- return str; //Found.
- }
- }
-
- return result;
-}
-
-Glib::ustring PostgresSelfHosted::get_postgresql_utils_version(const SlotProgress& slot_progress)
-{
- Glib::ustring result;
-
- const auto command = get_path_to_postgres_executable("pg_ctl") + " --version";
-
- //The first command does not return, but the second command can check whether it succeeded:
- std::string output;
- const auto spawn_result = Glom::Spawn::execute_command_line_and_wait(command, slot_progress, output);
- if(!spawn_result)
- {
- std::cerr << G_STRFUNC << ": Error while attempting to discover the pg_ctl version." << std::endl;
- return Glib::ustring();
- }
-
- return get_postgresql_utils_version_from_string(output);
-}
-
-float PostgresSelfHosted::get_postgresql_utils_version_as_number_from_string(const std::string& version_str)
-{
- //std::cout << "debug: " << G_STRFUNC << ": " << version_str << std::endl;
-
- float result = 0;
-
- std::regex regex;
-
- //We want the characters at the end:
- const gchar VERSION_REGEX[] = "(\\d*)\\.(\\d*)";
-
- try
- {
- regex = std::regex(VERSION_REGEX);
- }
- catch(const std::regex_error& ex)
- {
- std::cerr << G_STRFUNC << ": std::regex constructor() failed: " << ex.what() << std::endl;
- return result;
- }
-
- //We need to loop over the numbers because we get some "" items that we want to ignore:
- guint count = 0; //We want 2 numbers.
-
- auto matches_begin =
- std::sregex_iterator(version_str.begin(), version_str.end(), regex);
- auto matches_end = std::sregex_iterator();
-
- for(auto iter = matches_begin; iter != matches_end; ++iter)
- {
- const auto match = *iter;
- //std::cout << "match: START" << match.str() << "END" << std::endl;
-
- //We don't use a range-based for loop, so we can more easily
- //skip the [0] match, which is the full (parent) match:
- auto sub_matches_begin = match.cbegin();
- ++sub_matches_begin; //Skip [0], which is the full (parent) match.
- auto sub_matches_end = match.cend();
- for(auto sub_iter = sub_matches_begin ; sub_iter != sub_matches_end; ++sub_iter)
- {
- const auto& sub = *sub_iter;
- const auto str = sub.str();
- if(str.empty())
- continue;
-
- const auto num = atoi(str.c_str());
- if(count == 0)
- result = num;
- else if(count == 1)
- {
- result += (0.1 * num);
- return result;
- }
-
- ++count;
- }
- }
-
- return result;
-}
-
-float PostgresSelfHosted::get_postgresql_utils_version_as_number(const SlotProgress& slot_progress)
-{
- const std::string version_str = get_postgresql_utils_version(slot_progress);
-
- return get_postgresql_utils_version_as_number_from_string(version_str);
-}
-
-
Backend::StartupErrors PostgresSelfHosted::startup(const SlotProgress& slot_progress, bool network_shared)
{
m_network_shared = network_shared;
diff --git a/glom/libglom/connectionpool_backends/postgres_self.h
b/glom/libglom/connectionpool_backends/postgres_self.h
index 608e7ff..4c18945 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.h
+++ b/glom/libglom/connectionpool_backends/postgres_self.h
@@ -54,12 +54,6 @@ public:
*/
static bool install_postgres(const SlotProgress& slot_progress);
- ///This is public so it can be tested:
- static Glib::ustring get_postgresql_utils_version_from_string(const std::string& version_output);
-
- ///This is public so it can be tested:
- static float get_postgresql_utils_version_as_number_from_string(const std::string& version_str);
-
private:
virtual InitErrors initialize(const SlotProgress& slot_progress, const Glib::ustring& initial_username,
const Glib::ustring& password, bool network_shared = false);
@@ -76,14 +70,6 @@ private:
* order, and return the first one that is available.
*/
static unsigned int discover_first_free_port(unsigned int start_port, unsigned int end_port);
-
- /** Run the command-line with the --version option to discover what version
- * of PostgreSQL is installed, so we can use the appropriate configuration
- * options when self-hosting.
- */
- Glib::ustring get_postgresql_utils_version(const SlotProgress& slot_progress);
-
- float get_postgresql_utils_version_as_number(const SlotProgress& slot_progress);
void show_active_connections();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]