Skip to content

Commit

Permalink
fmk - Compressing Template dir and changing python script name to par…
Browse files Browse the repository at this point in the history
…seDAKOTA and pointing at new agave app: many resulting changes
  • Loading branch information
fmckenna committed Sep 29, 2018
1 parent 7a3e270 commit 6b15336
Show file tree
Hide file tree
Showing 12 changed files with 2,008 additions and 8 deletions.
60 changes: 54 additions & 6 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

// Written: fmckenna

#include <ZipUtils.h>
#include <QTreeView>
#include <QStandardItemModel>
#include <QItemSelectionModel>
Expand Down Expand Up @@ -132,6 +133,7 @@ MainWindow::MainWindow(QWidget *parent)
// user settings
//

/*
QSettings settings("SimCenter", "uqFEM");
QVariant savedValue = settings.value("uuid");
QUuid uuid;
Expand All @@ -140,6 +142,7 @@ MainWindow::MainWindow(QWidget *parent)
settings.setValue("uuid",uuid);
} else
uuid =savedValue.toUuid();
*/

//
// create the interface, jobCreator and jobManager
Expand Down Expand Up @@ -368,7 +371,7 @@ MainWindow::MainWindow(QWidget *parent)
// setup parameters of request
QString requestParams;
QString hostname = QHostInfo::localHostName() + "." + QHostInfo::localDomainName();
//QUuid uuid = QUuid::createUuid();
QUuid uuid = QUuid::createUuid();
requestParams += "v=1"; // version of protocol
requestParams += "&tid=UA-121636495-1"; // Google Analytics account
requestParams += "&cid=" + uuid.toString(); // unique user identifier
Expand Down Expand Up @@ -462,9 +465,17 @@ void MainWindow::onRunButtonClicked() {

QFileInfo fileInfo(mainInput);
QDir fileDir = fileInfo.absolutePath();


QString fileName =fileInfo.fileName();
QString path = fileDir.absolutePath();// + QDir::separator();

if (! fileDir.exists()) {
errorMessage(QString("Directory ") + path + QString(" specified does not exist!"));
return;
}


//
// given path to input file we are going to create temporary directory below it
// and copy all files from this input file directory to the new subdirectory
Expand All @@ -490,6 +501,7 @@ void MainWindow::onRunButtonClicked() {
file.errorString()));
return;
}

QJsonObject json;
inputWidget->outputToJSON(json);
QJsonDocument doc(json);
Expand All @@ -508,9 +520,19 @@ void MainWindow::onRunButtonClicked() {
// QDir::separator() + QString("localApp");

//
QString pySCRIPT = appDIR + QDir::separator() + QString("parseJson3.py");
QString pySCRIPT = appDIR + QDir::separator() + QString("parseDAKOTA.py");
QString tDirectory = path + QDir::separator() + QString("tmp.SimCenter");

//
// check the python script exists
//

QFile pyDAKOTA(pySCRIPT);
if (! pyDAKOTA.exists()) {
errorMessage("Dakota script does not exist, the parseDAKOTA.py script was not found in exe folder! .. download application again");
return;
}

// remove current results widget

results->setResultWidget(0);
Expand Down Expand Up @@ -578,11 +600,17 @@ void MainWindow::onRunButtonClicked() {

QDir dirToRemove(sourceDir);
dirToRemove.removeRecursively(); // padhye 4/28/2018, this removes the temprorary directory
// // so to debug you can simply comment it
// so to debug you can simply comment it

//
// process the results
//
QDir desitinationDIR(destinationDir);

if (! desitinationDIR.exists("dakota.out")) {
errorMessage("Dakota did not run, check the path you provided in parseDakota or contact us");
return;
}

QString filenameOUT = destinationDir + tr("dakota.out");
QString filenameTAB = destinationDir + tr("dakotaTab.out");
Expand Down Expand Up @@ -647,7 +675,7 @@ void MainWindow::onRemoteRunButtonClicked(){
file.close();

//
// now use the applications parseJSON file to run dakota and produce output files:
// now use the applications parseDAKOTA file to run dakota and produce output files:
// dakota.in dakota.out dakotaTab.out dakota.err
//

Expand All @@ -658,9 +686,15 @@ void MainWindow::onRemoteRunButtonClicked(){
// QDir::separator() + QString("localApp");

//
QString pySCRIPT = appDIR + QDir::separator() + QString("parseJson3.py");
QString pySCRIPT = appDIR + QDir::separator() + QString("parseDAKOTA.py");
QString tDirectory = path + QDir::separator() + QString("tmp.SimCenter") + strUnique;

QFile pyDAKOTA(pySCRIPT);
if (! pyDAKOTA.exists()) {
errorMessage("Dakota script does not exist, the parseDAKOTA.py script was not found in exe folder! .. download application again");
return;
}

// remove current results widget
results->setResultWidget(0);

Expand All @@ -686,7 +720,7 @@ void MainWindow::onRemoteRunButtonClicked(){


QProcess *proc = new QProcess();
qDebug() << "HELLO";

#ifdef Q_OS_WIN
QString command = QString("python ") + pySCRIPT + QString(" ") + tDirectory + QString(" ") + tmpDirectory + QString(" runningRemote");
qDebug() << command;
Expand All @@ -705,6 +739,20 @@ void MainWindow::onRemoteRunButtonClicked(){
#endif
proc->waitForStarted();


//
// in tmpDirectory we will zip up current template dir and then remove before sending (doone to reduce number of sends)
//

QString tDirectory2 = path + QDir::separator() + QString("tmp.SimCenter") + strUnique;
QString templateDIR(tDirectory2 + QDir::separator() + QString("templatedir"));
QString zipFile(tDirectory2 + QDir::separator() + QString("templatedir.zip"));
ZipUtils::ZipFolder(QDir(templateDIR), zipFile);
qDebug() << "ZIP DIR: " << templateDIR;
qDebug() << "ZIP FILE: " << zipFile;
QDir dirToRemove(templateDIR);
dirToRemove.removeRecursively();

//
// when setup is complete, pop open the jobCreateor Widget which will allow user
// to set some needed info before running at DesignSafe
Expand Down
19 changes: 19 additions & 0 deletions MiniZip/MiniZip.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

INCLUDEPATH += $$PWD

win32{
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib
}

HEADERS += $$PWD/zip.h $$PWD/ioapi.h

SOURCES += $$PWD/zip.c $$PWD/ioapi.c $$PWD/*.cpp

linux{
LIBS += -lz
}

macx{
LIBS += -lz
}

83 changes: 83 additions & 0 deletions MiniZip/ZipUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <ZipUtils.h>
#include <zip.h>
#include <QDirIterator>

bool ZipUtils::ZipFolder(QDir directoryToZip, QString zipFilePath)
{

zipFile newZipFile = zipOpen(zipFilePath.toStdString().c_str(), APPEND_STATUS_CREATE);

//Checking if the file is opened
if(NULL == newZipFile)
return false;

int result = ZIP_OK;

QDirIterator dirIt(directoryToZip, QDirIterator::Subdirectories);

//We need to find the parent to get relative path including directory name
QDir parentDir(directoryToZip.absolutePath());
parentDir.cdUp();

//Looping through files and directories
while (dirIt.hasNext())
{
QFileInfo fileInfo(dirIt.next());

if(fileInfo.isDir())
continue;

if(fileInfo.fileName() == "." || fileInfo.fileName() == "..")
continue;

QFile afile(fileInfo.filePath());


if(afile.exists())
{

if(!afile.open(QFile::ReadOnly))
return false;

QByteArray fileByteArray = afile.readAll();

QString relFilePath = parentDir.relativeFilePath(fileInfo.absoluteFilePath());

result = zipOpenNewFileInZip(newZipFile,
relFilePath.toStdString().c_str(),
NULL,
NULL,
0,
NULL,
0,
NULL,
Z_DEFLATED,
Z_BEST_COMPRESSION);

//checking if file entry is opened
if(result != ZIP_OK)
return false;

result = zipWriteInFileInZip(newZipFile, fileByteArray.data(), fileByteArray.length());

//checking if writing was successful
if(result != ZIP_OK)
return false;

//close file inside zip
result = zipCloseFileInZip(newZipFile);

//checking if file entry closing was successful
if(result != ZIP_OK)
return false;
}

}



//Closing zip file
result = zipClose(newZipFile, "Compressed directory");

return result;
}
11 changes: 11 additions & 0 deletions MiniZip/ZipUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ZIPUTILS_H
#define ZIPUTILS_H
#include <QDir>
#include <QString>

namespace ZipUtils {

bool ZipFolder(QDir directoryToZip, QString zipFilePath);

}
#endif // ZIPUTILS_H
Loading

0 comments on commit 6b15336

Please sign in to comment.