void atWrapper::downloadBaseline() { qDebug() << "Now downloading baseline..."; QFtp ftp; QObject::connect( &ftp, SIGNAL( listInfo( const QUrlInfo & ) ), this, SLOT( ftpMgetAddToList(const QUrlInfo & ) ) ); //Making sure that the needed local directories exist. QHashIterator<QString, QString> j(enginesToTest); while ( j.hasNext() ) { j.next(); QDir dir( output ); if ( !dir.cd( j.key() + ".baseline" ) ) dir.mkdir( j.key() + ".baseline" ); } //FTP to the host specified in the config file, and retrieve the test result baseline. ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.cd( ftpBaseDir ); QHashIterator<QString, QString> i(enginesToTest); while ( i.hasNext() ) { i.next(); mgetDirList.clear(); mgetDirList << i.key() + ".baseline"; ftp.cd( i.key() + ".baseline" ); ftp.list(); ftp.cd( ".." ); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); ftpMgetDone( true ); } ftp.close(); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void uiLoader::ftpGetFiles(QList<QString>& fileListing, const QString& pathRemoteDir, const QString& pathSaveDir) { QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); if ( !fileListing.empty() ) { for ( int i = 0; i < fileListing.size(); ++i ) { QFile file( pathSaveDir + "/" + fileListing.at(i) ); errorMsg = "could not open file for writing: " + file.fileName(); QVERIFY2( file.open(QIODevice::WriteOnly), qPrintable(errorMsg) ); QString ftpFileName = pathRemoteDir + '/' + fileListing.at(i); ftp.get( ftpFileName, &file ); //qDebug() << "\t(I) Got" << file.fileName(); ftp.list(); //Only there to fill up a slot in the pendingCommands queue. while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); file.close(); } } ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); fileListing.clear(); }
void atWrapper::ftpMgetDone( bool error) { Q_UNUSED( error ); //Downloading the files listed in mgetDirList... QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); QFile* file; if ( mgetDirList.size() > 1 ) for ( int i = 1; i < mgetDirList.size(); ++i ) { file = new QFile( QString( output ) + "/" + mgetDirList.at( 0 ) + "/" + mgetDirList.at( i ) ); if (file->open(QIODevice::WriteOnly)) { ftp.get( ftpBaseDir + "/" + mgetDirList.at( 0 ) + "/" + mgetDirList.at( i ), file ); ftp.list(); //Only there to fill up a slot in the pendingCommands queue. while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); file->close(); } else { qDebug() << "Couldn't open file for writing: " << file->fileName(); } } while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void uiLoader::createBaseline() { // can't use ftpUploadFile() here qDebug() << " ========== Uploading baseline of only the latest test values "; QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.cd( ftpBaseDir ); QDir dir( output ); // Upload all the latest test results to the FTP server's baseline directory. QHashIterator<QString, QString> i(enginesToTest); while ( i.hasNext() ) { i.next(); dir.cd( i.key() ); ftp.cd( i.key() + ".baseline" ); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setNameFilters( QStringList() << "*.png" ); QFileInfoList list = dir.entryInfoList(); dir.cd( ".." ); for (int n = 0; n < list.size(); n++) { QFileInfo fileInfo = list.at( n ); QFile file( QString( output ) + "/" + i.key() + "/" + fileInfo.fileName() ); errorMsg = "could not open file " + fileInfo.fileName(); QVERIFY2( file.open(QIODevice::ReadOnly), qPrintable(errorMsg)); QByteArray fileData = file.readAll(); file.close(); ftp.put( fileData, fileInfo.fileName(), QFtp::Binary ); qDebug() << "\t(I) Uploading:" << fileInfo.fileName() << "with file size" << fileData.size(); } ftp.cd( ".." ); } ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void uiLoader::ftpMkDir( QString pathDir ) { QFtp ftp; QSignalSpy commandSpy(&ftp, SIGNAL(commandFinished(int, bool))); ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); const int command = ftp.mkdir( pathDir ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); // check wheter there was an error or not for (int i = 0; i < commandSpy.count(); ++i) { if (commandSpy.at(i).at(0) == command) { if ( !commandSpy.at(i).at(1).toBool() ) { qDebug() << "\t(I) Created at remote machine:" << pathDir; } else { qDebug() << "\t(I) Could not create on remote machine - probably the dir exists"; } } } }
bool uiLoader::ftpUploadFile(const QString& filePathRemote, const QString& filePath) { QFile file(filePath); errorMsg = "could not open file: " + filePath; QVERIFY3( file.open(QIODevice::ReadOnly), qPrintable(errorMsg), false ); QByteArray contents = file.readAll(); file.close(); qDebug() << "\t(I) Uploading file to" << filePathRemote; QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.put( contents, filePathRemote, QFtp::Binary ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); return true; }
void atWrapper::uploadFailed( QString dir, QString filename, QByteArray filedata ) { //Upload a failed test case image to the FTP server. QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.cd( ftpBaseDir ); ftp.cd( dir ); ftp.put( filedata, filename, QFtp::Binary ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void atWrapper::ftpRmDirDone( bool error ) { //Deleting each file in the directory listning, rmDirList. Q_UNUSED( error ); QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); if ( rmDirList.size() > 1 ) for (int i = 1; i < rmDirList.size(); ++i) ftp.remove( rmDirList.at(0) + rmDirList.at( i ) ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void atWrapper::ftpRmDir( QString dir ) { //Hack to remove a populated directory. (caveat: containing only files and empty dirs, not recursive!) qDebug() << "Now removing directory: " << dir; QFtp ftp; QObject::connect( &ftp, SIGNAL( listInfo( const QUrlInfo & ) ), this, SLOT( ftpRmDirAddToList(const QUrlInfo & ) ) ); QObject::connect( &ftp, SIGNAL( done( bool ) ), this, SLOT( ftpRmDirDone( bool ) ) ); ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.list( ftpBaseDir + "/" + dir ); ftp.close(); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void uiLoader::ftpList(const QString & dir) { qDebug() << "\t(I) Getting list of files in dir" << dir; lsDirList.clear(); QFtp ftp; QObject::connect( &ftp, SIGNAL( listInfo( const QUrlInfo & ) ), this, SLOT( ftpAddLsEntry(const QUrlInfo & ) ) ); //QObject::connect( &ftp, SIGNAL( done( bool ) ), this, SLOT( ftpAddLsDone( bool ) ) ); ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.list( dir ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
// returns false if the directory already exists bool atWrapper::ftpMkDir( QString dir ) { //Simply used to avoid QFTP from bailing out and loosing a queue of commands. // IE: conveniance. QFtp ftp; QSignalSpy commandSpy(&ftp, SIGNAL(commandFinished(int, bool))); ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); const int command = ftp.mkdir( dir ); ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); for (int i = 0; i < commandSpy.count(); ++i) if (commandSpy.at(i).at(0) == command) return commandSpy.at(i).at(1).toBool(); return false; }
void uiLoader::ftpClearDirectory(const QString& pathDir) { qDebug() << "\t(I) Clearing directory remote: " << pathDir; ftpList(pathDir); QList<QString> dirListing(lsDirList); QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); for (int i = 0; i < dirListing.size(); ++i) { QString file = dirListing.at(i); qDebug() << "\t(I) Removing" << pathDir + file; ftp.remove(pathDir + file); } ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); }
void _GUI::checkForUpdate( string message, string VERSION, string REMOTE ) { QSignalMapper *map = new QSignalMapper(this); updateInfo* i = new updateInfo; i->buffer = new QBuffer(this); i->buffer->open( QBuffer::ReadWrite ); i->message = message; i->version = VERSION; i->remote = REMOTE; QFtp *ftp = new QFtp( this ); connect( ftp, SIGNAL(done(bool)), map, SLOT(map()) ); map->setMapping( ftp, i ); //connect( ftp, SIGNAL(done(bool)), this, SLOT(updateDone(bool)) ); connect( map, SIGNAL( mapped( QObject* ) ), this, SLOT(updateDone( QObject* )) ); ftp->connectToHost( "r99acm.device.mst.edu", 2121 ); ftp->login(); ftp->cd( "jenkins" ); ftp->get( REMOTE.c_str(), i->buffer ); ftp->close(); }
// returns false if no baseline exists bool atWrapper::setupFTP() { qDebug( "Setting up FTP environment" ); QString dir = ""; ftpMkDir( ftpBaseDir ); ftpBaseDir += "/" + QLibraryInfo::buildKey(); ftpMkDir( ftpBaseDir ); ftpBaseDir += "/" + QString( qVersion() ); ftpMkDir( ftpBaseDir ); QHashIterator<QString, QString> i(enginesToTest); QHashIterator<QString, QString> j(enginesToTest); bool haveBaseline = true; //Creating the baseline directories for each engine while ( i.hasNext() ) { i.next(); //qDebug() << "Creating dir with key:" << i.key(); ftpMkDir( ftpBaseDir + "/" + QString( i.key() ) + ".failed" ); ftpMkDir( ftpBaseDir + "/" + QString( i.key() ) + ".diff" ); if (!ftpMkDir( ftpBaseDir + "/" + QString( i.key() ) + ".baseline" )) haveBaseline = false; } QFtp ftp; ftp.connectToHost( ftpHost ); ftp.login( ftpUser, ftpPass ); ftp.cd( ftpBaseDir ); //Deleting previous failed directory and all the files in it, then recreating it. while ( j.hasNext() ) { j.next(); rmDirList.clear(); rmDirList << ftpBaseDir + "/" + j.key() + ".failed" + "/"; ftpRmDir( j.key() + ".failed" ); ftp.rmdir( j.key() + ".failed" ); ftp.mkdir( j.key() + ".failed" ); ftp.list(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); rmDirList.clear(); rmDirList << ftpBaseDir + "/" + j.key() + ".diff" + "/"; ftpRmDir( j.key() + ".diff" ); ftp.rmdir( j.key() + ".diff" ); ftp.mkdir( j.key() + ".diff" ); ftp.list(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); } ftp.close(); while ( ftp.hasPendingCommands() ) QCoreApplication::instance()->processEvents(); return haveBaseline; }
void FtpTransferThread::run() { #ifdef USE_FTP_CONNECTION_CACHE FtpConnectionCache* cache = FtpConnectionCache::getInstance(); cache->closeConnection(_engine->_url); #endif // Use a local event loop. The event loop of the thread itself seems to be // blocked as well when a main thread is blocked QEventLoop loop; // Use a separate QFtp instance because copying in a same server is // possible QFtp ftp; connect(&ftp, SIGNAL(done(bool)), &loop, SLOT(quit()), Qt::QueuedConnection); connect(&ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)), Qt::QueuedConnection); connect(this, SIGNAL(ftpAbort()), &ftp, SLOT(abort()), Qt::QueuedConnection); connect(this, SIGNAL(loopQuit()), &loop, SLOT(quit()), Qt::QueuedConnection); ftp.setTransferMode(_engine->_transferMode == "Passive" ? QFtp::Passive : QFtp::Active); ftp.connectToHost(_engine->_url.host(), _engine->_port); ftp.login(_engine->_userName, _engine->_password); if (_openMode & QIODevice::ReadOnly) { ftp.get(_engine->_textCodec->fromUnicode(_engine->_path), &_engine->_fileBuffer); } else if (_openMode & QIODevice::WriteOnly) { ftp.put(&_engine->_fileBuffer, _engine->_textCodec->fromUnicode(_engine->_path)); } ftp.close(); loop.exec(); // aborted ? if (ftp.state() != QFtp::Unconnected) { // wait at most 10s static const int MAX_WAIT = 10 * 1000; FtpSync ftpSync(&ftp); ftp.close(); ftpSync.wait(MAX_WAIT); // workaround to avoid the failure of first connecting after // abort if copying/moving in a same server ftp.connectToHost(_engine->_url.host(), _engine->_port); ftpSync.wait(MAX_WAIT); ftp.close(); ftpSync.wait(MAX_WAIT); } }
void tst_QtWidgets::snapshot() { QSKIP("Jesper will fix this test when he has time.", SkipAll); #if 0 StyleWidget widget(0, Qt::X11BypassWindowManagerHint); widget.show(); QPixmap pix = QPixmap::grabWidget(&widget); QVERIFY(!pix.isNull()); QBuffer buf; pix.save(&buf, "PNG"); QVERIFY(buf.size() > 0); QString filename = "qtwidgets_" + QHostInfo::localHostName() + "_" + QDateTime::currentDateTime().toString("yyyy.MM.dd_hh.mm.ss") + ".png"; QFtp ftp; ftp.connectToHost("qt-test-server.qt-test-net"); ftp.login("ftptest", "password"); ftp.cd("qtest/pics"); ftp.put(buf.data(), filename, QFtp::Binary); ftp.close(); int i = 0; while (i < 100 && ftp.hasPendingCommands()) { QCoreApplication::instance()->processEvents(); QTest::qWait(250); ++i; } QVERIFY2(ftp.error() == QFtp::NoError, ftp.errorString().toLocal8Bit().constData()); QVERIFY(!ftp.hasPendingCommands()); #endif }