From c210458c7012c4df8e7d3c5f59efd0cda59434bd Mon Sep 17 00:00:00 2001 From: Cedric CAFFY <cedric.caffy@cern.ch> Date: Tue, 4 Feb 2020 11:19:41 +0100 Subject: [PATCH] Renamed StatisticsCmd in StatisticsSaveCmd Added the enty in the cta.spec.in --- cta.spec.in | 1 + statistics/CMakeLists.txt | 33 ++--- statistics/StatisticsCmdLineArgsTest.cpp | 121 ------------------ ...tatisticsCmd.cpp => StatisticsSaveCmd.cpp} | 16 +-- ...tatisticsCmd.hpp => StatisticsSaveCmd.hpp} | 8 +- ...Args.cpp => StatisticsSaveCmdLineArgs.cpp} | 8 +- ...Args.hpp => StatisticsSaveCmdLineArgs.hpp} | 4 +- ...sCmdMain.cpp => StatisticsSaveCmdMain.cpp} | 4 +- 8 files changed, 32 insertions(+), 163 deletions(-) delete mode 100644 statistics/StatisticsCmdLineArgsTest.cpp rename statistics/{StatisticsCmd.cpp => StatisticsSaveCmd.cpp} (87%) rename statistics/{StatisticsCmd.hpp => StatisticsSaveCmd.hpp} (90%) rename statistics/{StatisticsCmdLineArgs.cpp => StatisticsSaveCmdLineArgs.cpp} (91%) rename statistics/{StatisticsCmdLineArgs.hpp => StatisticsSaveCmdLineArgs.hpp} (94%) rename statistics/{StatisticsCmdMain.cpp => StatisticsSaveCmdMain.cpp} (90%) diff --git a/cta.spec.in b/cta.spec.in index 1822e43367..3455b9d3c7 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -318,6 +318,7 @@ Scripts and utilities to faciliate working with the CTA catalogue %attr(0755,root,root) %{_bindir}/cta-catalogue-schema-drop %attr(0755,root,root) %{_bindir}/cta-catalogue-schema-verify %attr(0755,root,root) %{_bindir}/cta-database-poll +%attr(0755,root,root) %{_bindir}/cta-statistics-save %attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-admin-user-create.1cta.gz %attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-create.1cta.gz %attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-drop.1cta.gz diff --git a/statistics/CMakeLists.txt b/statistics/CMakeLists.txt index 4baa8c4d92..73b2c1e95a 100644 --- a/statistics/CMakeLists.txt +++ b/statistics/CMakeLists.txt @@ -23,9 +23,9 @@ include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") set (STATISTICS_LIB_SRC_FILES - StatisticsCmd.cpp - StatisticsCmdLineArgs.cpp - StatisticsCmdMain.cpp + StatisticsSaveCmd.cpp + StatisticsSaveCmdLineArgs.cpp + StatisticsSaveCmdMain.cpp StatisticsSchema.cpp ) @@ -68,27 +68,16 @@ install (FILES ${CMAKE_SOURCE_DIR}/catalogue/cta-catalogue.conf.example DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cta PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) -add_executable(cta-statistics - StatisticsCmd.cpp - StatisticsCmdLineArgs.cpp - StatisticsCmdMain.cpp +add_executable(cta-statistics-save + StatisticsSaveCmd.cpp + StatisticsSaveCmdLineArgs.cpp + StatisticsSaveCmdMain.cpp MysqlStatisticsSchema.cpp ) -target_link_libraries (cta-statistics ctastatistics ctacatalogue ctaschemachecker) +target_link_libraries (cta-statistics-save ctastatistics ctacatalogue ctaschemachecker) -set_property(TARGET cta-statistics APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH}) -set_property(TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH}) +set_property(TARGET cta-statistics-save APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH}) +set_property(TARGET cta-statistics-save APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH}) -install (TARGETS cta-statistics DESTINATION /usr/bin) - -set (STATISTICS_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES - StatisticsCmdLineArgsTest.cpp -) - -add_library (ctastatisticscmdlineunittests SHARED - ${STATISTICS_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES}) -set_property(TARGET ctastatisticscmdlineunittests PROPERTY SOVERSION "${CTA_SOVERSION}") -set_property(TARGET ctastatisticscmdlineunittests PROPERTY VERSION "${CTA_LIBVERSION}") - -install (TARGETS ctastatisticscmdlineunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) +install (TARGETS cta-statistics-save DESTINATION /usr/bin) \ No newline at end of file diff --git a/statistics/StatisticsCmdLineArgsTest.cpp b/statistics/StatisticsCmdLineArgsTest.cpp deleted file mode 100644 index e5efb088a9..0000000000 --- a/statistics/StatisticsCmdLineArgsTest.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 CERN - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - *(at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "common/exception/Exception.hpp" -#include "catalogue/VerifySchemaCmdLineArgs.hpp" - -#include <gtest/gtest.h> -#include <list> - -namespace unitTests { - -class cta_catalogue_VerifySchemaCmdLineArgsTest : public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string using the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - // Allow getopt_long to be called again - optind = 0; - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; - -TEST_F(cta_catalogue_VerifySchemaCmdLineArgsTest, help_short) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-verify"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_VerifySchemaCmdLineArgsTest, help_long) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-verify"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_TRUE(cmdLine.help); - ASSERT_TRUE(cmdLine.dbConfigPath.empty()); -} - -TEST_F(cta_catalogue_VerifySchemaCmdLineArgsTest, dbConfigPath) { - using namespace cta::catalogue; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-catalogue-schema-verify"); - args->argv[1] = dupString("dbConfigPath"); - args->argv[2] = NULL; - - VerifySchemaCmdLineArgs cmdLine(args->argc, args->argv); - - ASSERT_FALSE(cmdLine.help); - ASSERT_EQ(std::string("dbConfigPath"), cmdLine.dbConfigPath); -} - -} // namespace unitTests diff --git a/statistics/StatisticsCmd.cpp b/statistics/StatisticsSaveCmd.cpp similarity index 87% rename from statistics/StatisticsCmd.cpp rename to statistics/StatisticsSaveCmd.cpp index 6935f2de85..bcecc14db8 100644 --- a/statistics/StatisticsCmd.cpp +++ b/statistics/StatisticsSaveCmd.cpp @@ -18,7 +18,7 @@ #include "rdbms/ConnPool.hpp" #include "rdbms/AutocommitMode.hpp" -#include "StatisticsCmd.hpp" +#include "StatisticsSaveCmd.hpp" #include "StatisticsSchema.hpp" #include "catalogue/SchemaChecker.hpp" #include "MysqlStatisticsSchema.hpp" @@ -30,22 +30,22 @@ namespace statistics { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -StatisticsCmd::StatisticsCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream): +StatisticsSaveCmd::StatisticsSaveCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream): CmdLineTool(inStream, outStream, errStream) { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -StatisticsCmd::~StatisticsCmd() noexcept { +StatisticsSaveCmd::~StatisticsSaveCmd() noexcept { } //------------------------------------------------------------------------------ // exceptionThrowingMain //------------------------------------------------------------------------------ -int StatisticsCmd::exceptionThrowingMain(const int argc, char *const *const argv) { +int StatisticsSaveCmd::exceptionThrowingMain(const int argc, char *const *const argv) { using namespace cta::catalogue; - const StatisticsCmdLineArgs cmdLineArgs(argc, argv); + const StatisticsSaveCmdLineArgs cmdLineArgs(argc, argv); if(cmdLineArgs.help) { printUsage(m_out); @@ -87,7 +87,7 @@ int StatisticsCmd::exceptionThrowingMain(const int argc, char *const *const argv //------------------------------------------------------------------------------ // tableExists //------------------------------------------------------------------------------ -bool StatisticsCmd::tableExists(const std::string tableName, rdbms::Conn &conn) const { +bool StatisticsSaveCmd::tableExists(const std::string tableName, rdbms::Conn &conn) const { const auto names = conn.getTableNames(); for(const auto &name : names) { if(tableName == name) { @@ -100,8 +100,8 @@ bool StatisticsCmd::tableExists(const std::string tableName, rdbms::Conn &conn) //------------------------------------------------------------------------------ // printUsage //------------------------------------------------------------------------------ -void StatisticsCmd::printUsage(std::ostream &os) { - StatisticsCmdLineArgs::printUsage(os); +void StatisticsSaveCmd::printUsage(std::ostream &os) { + StatisticsSaveCmdLineArgs::printUsage(os); } diff --git a/statistics/StatisticsCmd.hpp b/statistics/StatisticsSaveCmd.hpp similarity index 90% rename from statistics/StatisticsCmd.hpp rename to statistics/StatisticsSaveCmd.hpp index 654cc3e7d2..0b99b62fc5 100644 --- a/statistics/StatisticsCmd.hpp +++ b/statistics/StatisticsSaveCmd.hpp @@ -22,7 +22,7 @@ #include "catalogue/CatalogueSchema.hpp" #include "rdbms/Conn.hpp" #include "rdbms/Login.hpp" -#include "StatisticsCmdLineArgs.hpp" +#include "StatisticsSaveCmdLineArgs.hpp" namespace cta { namespace statistics { @@ -30,7 +30,7 @@ namespace statistics { /** * Command-line tool for verifying the catalogue schema. */ -class StatisticsCmd: public cta::catalogue::CmdLineTool { +class StatisticsSaveCmd: public cta::catalogue::CmdLineTool { public: /** @@ -40,12 +40,12 @@ public: * @param outStream Standard output stream. * @param errStream Standard error stream. */ - StatisticsCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream); + StatisticsSaveCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream); /** * Destructor. */ - ~StatisticsCmd() noexcept; + ~StatisticsSaveCmd() noexcept; enum class VerifyStatus { OK, INFO, ERROR, UNKNOWN }; diff --git a/statistics/StatisticsCmdLineArgs.cpp b/statistics/StatisticsSaveCmdLineArgs.cpp similarity index 91% rename from statistics/StatisticsCmdLineArgs.cpp rename to statistics/StatisticsSaveCmdLineArgs.cpp index ab649bb4fa..9318531553 100644 --- a/statistics/StatisticsCmdLineArgs.cpp +++ b/statistics/StatisticsSaveCmdLineArgs.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "StatisticsCmdLineArgs.hpp" +#include "StatisticsSaveCmdLineArgs.hpp" #include "common/exception/CommandLineNotParsed.hpp" #include <getopt.h> @@ -29,7 +29,7 @@ namespace statistics { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -StatisticsCmdLineArgs::StatisticsCmdLineArgs(const int argc, char *const *const argv): +StatisticsSaveCmdLineArgs::StatisticsSaveCmdLineArgs(const int argc, char *const *const argv): help(false) { static struct option longopts[] = { @@ -101,10 +101,10 @@ StatisticsCmdLineArgs::StatisticsCmdLineArgs(const int argc, char *const *const //------------------------------------------------------------------------------ // printUsage //------------------------------------------------------------------------------ -void StatisticsCmdLineArgs::printUsage(std::ostream &os) { +void StatisticsSaveCmdLineArgs::printUsage(std::ostream &os) { os << "Usage:" << std::endl << - " cta-statistics --catalogueconf catalogueDbConnectionFile --statisticsconf statisticsDbConnectionFile [options]" << std::endl << + " cta-statistics-save --catalogueconf catalogueDbConnectionFile --statisticsconf statisticsDbConnectionFile [options]" << std::endl << "Where:" << std::endl << " catalogueDbConnectionFile" << std::endl << " The path to the file containing the connection details of the CTA" << std::endl << diff --git a/statistics/StatisticsCmdLineArgs.hpp b/statistics/StatisticsSaveCmdLineArgs.hpp similarity index 94% rename from statistics/StatisticsCmdLineArgs.hpp rename to statistics/StatisticsSaveCmdLineArgs.hpp index 08b428d0f5..29f53217a4 100644 --- a/statistics/StatisticsCmdLineArgs.hpp +++ b/statistics/StatisticsSaveCmdLineArgs.hpp @@ -27,7 +27,7 @@ namespace statistics { * Structure to store the command-line arguments of the command-line tool * named cta-statistics */ -struct StatisticsCmdLineArgs { +struct StatisticsSaveCmdLineArgs { /** * True if the usage message should be printed. */ @@ -52,7 +52,7 @@ struct StatisticsCmdLineArgs { * executable. * @param argv The vector of command-line arguments. */ - StatisticsCmdLineArgs(const int argc, char *const *const argv); + StatisticsSaveCmdLineArgs(const int argc, char *const *const argv); /** * Prints the usage message of the command-line tool. diff --git a/statistics/StatisticsCmdMain.cpp b/statistics/StatisticsSaveCmdMain.cpp similarity index 90% rename from statistics/StatisticsCmdMain.cpp rename to statistics/StatisticsSaveCmdMain.cpp index 0ef80bee2f..72f315edf9 100644 --- a/statistics/StatisticsCmdMain.cpp +++ b/statistics/StatisticsSaveCmdMain.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "StatisticsCmd.hpp" +#include "StatisticsSaveCmd.hpp" #include <iostream> @@ -24,6 +24,6 @@ // main //------------------------------------------------------------------------------ int main(const int argc, char *const *const argv) { - cta::statistics::StatisticsCmd cmd(std::cin, std::cout, std::cerr); + cta::statistics::StatisticsSaveCmd cmd(std::cin, std::cout, std::cerr); return cmd.main(argc, argv); } -- GitLab