From 92fcca4fb85ae70800e562f32e88ef799add6a40 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Wed, 2 Jun 2004 13:39:25 -0400 Subject: [PATCH] ENH: Implement scp submission --- Source/CTest/cmCTestSubmit.cxx | 112 +++++++++++++++++++++++++++++++-- Source/CTest/cmCTestSubmit.h | 3 +- Source/cmCTest.cxx | 20 +++++- Source/cmCTest.h | 1 + 4 files changed, 127 insertions(+), 9 deletions(-) diff --git a/Source/CTest/cmCTestSubmit.cxx b/Source/CTest/cmCTestSubmit.cxx index 98ba8cd3f..2c55ab15e 100644 --- a/Source/CTest/cmCTestSubmit.cxx +++ b/Source/CTest/cmCTestSubmit.cxx @@ -18,6 +18,7 @@ PURPOSE. See the above copyright notices for more information. #include "cmCTestSubmit.h" #include "cmSystemTools.h" +#include #include "curl/curl.h" #include @@ -407,11 +408,110 @@ bool cmCTestSubmit::TriggerUsingHTTP(const std::vector& files, return true; } -bool cmCTestSubmit::SubmitUsingSCP(const cmStdString&, - const std::vector&, - const cmStdString&, - const cmStdString&) +bool cmCTestSubmit::SubmitUsingSCP( + const cmStdString& scp_command, + const cmStdString& localprefix, + const std::vector& files, + const cmStdString& remoteprefix, + const cmStdString& url) { - std::cout << "SubmitUsingSCP is not yet implemented" << std::endl; - return false; + if ( !scp_command.size() || !localprefix.size() || + !files.size() || !remoteprefix.size() || !url.size() ) + { + return 0; + } + std::vector argv; + argv.push_back(scp_command.c_str()); // Scp command + argv.push_back(scp_command.c_str()); // Dummy string for file + argv.push_back(scp_command.c_str()); // Dummy string for remote url + argv.push_back(0); + + cmsysProcess* cp = cmsysProcess_New(); + cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); + //cmsysProcess_SetTimeout(cp, timeout); + + int retVal = 0; + + int problems = 0; + + std::vector::const_iterator it; + for ( it = files.begin(); + it != files.end(); + it ++ ) + { + std::string lfname = localprefix; + cmSystemTools::ConvertToUnixSlashes(lfname); + lfname += "/" + *it; + lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str()); + argv[1] = lfname.c_str(); + std::string rfname = url + "/" + remoteprefix + *it; + argv[2] = rfname.c_str(); + if ( m_Verbose ) + { + std::cout << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" + << argv[2] << "\"" << std::endl; + } + *m_LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" + << argv[2] << "\"" << std::endl; + cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_Execute(cp); + char* data; + int length; + while(cmsysProcess_WaitForData(cp, &data, &length, 0)) + { + std::cout.write(data, length); + } + cmsysProcess_WaitForExit(cp, 0); + int result = cmsysProcess_GetState(cp); + + if(result == cmsysProcess_State_Exited) + { + retVal = cmsysProcess_GetExitValue(cp); + if ( retVal != 0 ) + { + if ( m_Verbose ) + { + std::cout << "\tSCP returned: " << retVal << std::endl; + } + *m_LogFile << "\tSCP returned: " << retVal << std::endl; + problems ++; + } + } + else if(result == cmsysProcess_State_Exception) + { + retVal = cmsysProcess_GetExitException(cp); + if ( m_Verbose ) + { + std::cout << "\tThere was an exception: " << retVal << std::endl; + } + *m_LogFile << "\tThere was an exception: " << retVal << std::endl; + problems ++; + } + else if(result == cmsysProcess_State_Expired) + { + if ( m_Verbose ) + { + std::cout << "\tThere was a timeout" << std::endl; + } + *m_LogFile << "\tThere was a timeout" << std::endl; + problems ++; + } + else if(result == cmsysProcess_State_Error) + { + if ( m_Verbose ) + { + std::cout << "\tError executing SCP: " + << cmsysProcess_GetErrorString(cp) << std::endl; + } + *m_LogFile << "\tError executing SCP: " + << cmsysProcess_GetErrorString(cp) << std::endl; + problems ++; + } + } + cmsysProcess_Delete(cp); + if ( problems ) + { + return false; + } + return true; } diff --git a/Source/CTest/cmCTestSubmit.h b/Source/CTest/cmCTestSubmit.h index 5513adc85..fe5e53718 100644 --- a/Source/CTest/cmCTestSubmit.h +++ b/Source/CTest/cmCTestSubmit.h @@ -51,7 +51,8 @@ public: const std::vector& files, const cmStdString& remoteprefix, const cmStdString& url); - bool SubmitUsingSCP(const cmStdString& localprefix, + bool SubmitUsingSCP(const cmStdString& scp_command, + const cmStdString& localprefix, const std::vector& files, const cmStdString& remoteprefix, const cmStdString& url); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 9aaca0ecc..20a5094ed 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2619,6 +2619,8 @@ int cmCTest::SubmitResults() cnt ++; } } + std::cout << "Submit files (using " << m_DartConfiguration["DropMethod"] << ")" + << std::endl; cmCTestSubmit submit; submit.SetVerbose(m_Verbose); submit.SetLogFile(&ofs); @@ -2682,8 +2684,22 @@ int cmCTest::SubmitResults() } else { - std::cerr << "SCP submit not yet implemented" << std::endl; - ofs << "SCP submit not yet implemented" << std::endl; + std::string url; + if ( m_DartConfiguration["DropSiteUser"].size() > 0 ) + { + url += m_DartConfiguration["DropSiteUser"] + "@"; + } + url += m_DartConfiguration["DropSite"] + ":" + m_DartConfiguration["DropLocation"]; + + if ( !submit.SubmitUsingSCP(m_DartConfiguration["ScpCommand"], + m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) ) + { + std::cerr << " Problems when submitting via SCP" << std::endl; + ofs << " Problems when submitting via SCP" << std::endl; + return 0; + } + std::cout << " Submission successfull" << std::endl; + ofs << " Submission succesfull" << std::endl; } return 0; diff --git a/Source/cmCTest.h b/Source/cmCTest.h index cff496036..25b025cfb 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -291,6 +291,7 @@ private: }; typedef std::vector tm_TestResultsVector; + //! Map of configuration properties typedef std::map tm_DartConfigurationMap; typedef std::map tm_CoverageMap;