void tst_QProcessEnvironment::toStringList()
{
    QProcessEnvironment e;
    QVERIFY(e.isEmpty());
    QVERIFY(e.toStringList().isEmpty());

    e.insert("FOO", "bar");
    QStringList result = e.toStringList();
    QVERIFY(!result.isEmpty());
    QCOMPARE(result.length(), 1);
    QCOMPARE(result.at(0), QString("FOO=bar"));

    e.clear();
    e.insert("BAZ", "");
    result = e.toStringList();
    QCOMPARE(result.at(0), QString("BAZ="));

    e.insert("FOO", "bar");
    e.insert("A", "bc");
    e.insert("HELLO", "World");
    result = e.toStringList();
    QCOMPARE(result.length(), 4);

    // order is not specified, so use contains()
    QVERIFY(result.contains("FOO=bar"));
    QVERIFY(result.contains("BAZ="));
    QVERIFY(result.contains("A=bc"));
    QVERIFY(result.contains("HELLO=World"));
}
Esempio n. 2
0
static bool processEnvironmentsAreEqual(const QProcessEnvironment &env1,
                                        const QProcessEnvironment &env2)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
    return env1 == env2;
#else // qtbase/8b5cdc20be
    return env1.toStringList() == env2.toStringList();
#endif
}
Esempio n. 3
0
bool OfflineAstrometryParser::startSovler(const QString &filename,  const QStringList &args, bool generated)
{
    INDI_UNUSED(generated);

    #ifdef Q_OS_OSX
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    QStringList envlist = env.toStringList();
    envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH=/usr/local/bin:\\1");
    solver.setEnvironment(envlist);
    #endif

    QStringList solverArgs = args;
    // Add parity option if none is give and we already know parity before
    if (parity.isEmpty() == false && args.contains("parity") == false)
        solverArgs << "--parity" << parity;
    QString solutionFile = QDir::tempPath() + "/solution.wcs";
    solverArgs << "-W" <<  solutionFile << filename;

    fitsFile = filename;

    connect(&solver, SIGNAL(finished(int)), this, SLOT(solverComplete(int)));
    connect(&solver, SIGNAL(readyReadStandardOutput()), this, SLOT(logSolver()));

    // Reset parity on solver failure
    connect(this, &OfflineAstrometryParser::solverFailed, this, [&]() { parity = QString();});

#if QT_VERSION > QT_VERSION_CHECK(5,6,0)
    connect(&solver, &QProcess::errorOccurred, this, [&]()
    {
        align->appendLogText(i18n("Error starting solver: %1", solver.errorString()));
        emit solverFailed();
    });
#else
    connect(&solver, SIGNAL(error(QProcess::ProcessError)), this, SIGNAL(solverFailed()));
#endif

    solverTimer.start();

    QString solverPath;

    if(Options::astrometrySolverIsInternal())
        solverPath=QCoreApplication::applicationDirPath()+"/astrometry/bin/solve-field";
    else
        solverPath=Options::astrometrySolver();

    solver.start(solverPath, solverArgs);

    align->appendLogText(i18n("Starting solver..."));

    if (Options::solverVerbose())
    {
        QString command = solverPath + " " + solverArgs.join(" ");
        align->appendLogText(command);
    }

    return true;
}
// TODO: remove as much of this file as possible, as most of it isn't necessary
QScriptValue QProcessEnvironmenttoScriptValue(QScriptEngine *engine, const QProcessEnvironment &item)
{
  QScriptValue result = engine->newObject();
  QStringList env = item.toStringList();
  for (int i = 0; i < env.size(); i++)
  {
    QStringList line = env[i].split("=");
    result.setProperty(line[0], line[1]);
  }
  return result;
}
void EnvironmentVariablesDialog::setProcessEnvironment(const QProcessEnvironment &environment)
{
    QStringList values = environment.toStringList();
    ui->valueViewer->setRowCount(values.size());
    for (int i = 0; i < values.size(); i ++) {
        int tmp = values[i].indexOf('=');
        QString variable = values[i].mid(0, tmp);
        QString value = values[i].mid(tmp + 1);
        ui->valueViewer->setItem(i, 0, new QTableWidgetItem(variable));
        ui->valueViewer->setItem(i, 1, new QTableWidgetItem(value));
    }
}
void tst_QProcessEnvironment::caseSensitivity()
{
    QProcessEnvironment e;
    e.insert("foo", "bar");

#ifdef Q_OS_WIN
    // Windows is case-insensitive, but case-preserving
    QVERIFY(e.contains("foo"));
    QVERIFY(e.contains("FOO"));
    QVERIFY(e.contains("FoO"));

    QCOMPARE(e.value("foo"), QString("bar"));
    QCOMPARE(e.value("FOO"), QString("bar"));
    QCOMPARE(e.value("FoO"), QString("bar"));

    // Per Windows, this overwrites the value, but keeps the name's original capitalization
    e.insert("Foo", "Bar");

    QStringList list = e.toStringList();
    QCOMPARE(list.length(), 1);
    QCOMPARE(list.at(0), QString("foo=Bar"));
#else
    // otherwise, it's case sensitive
    QVERIFY(e.contains("foo"));
    QVERIFY(!e.contains("FOO"));

    e.insert("FOO", "baz");
    QVERIFY(e.contains("FOO"));
    QCOMPARE(e.value("FOO"), QString("baz"));
    QCOMPARE(e.value("foo"), QString("bar"));

    QStringList list = e.toStringList();
    QCOMPARE(list.length(), 2);
    QVERIFY(list.contains("foo=bar"));
    QVERIFY(list.contains("FOO=baz"));
#endif
}
Esempio n. 7
0
void GoplayBrowser::run()
{
    m_editor->saveAs(m_playFile);
    if (!m_editFile.isEmpty()) {
        m_editor->saveAs(m_editFile);
    }
    QProcessEnvironment env = LiteApi::getCurrentEnvironment(m_liteApp);
    QString go = FileUtil::lookPath("go",env,false);
    QStringList args;
    args << "run";
    args << "goplay.go";
    if (m_process->isRuning()) {
        m_process->kill();
    }
    m_output->clear();
    m_output->appendTag(QString("Run start ...\n\n"));
    m_process->setEnvironment(env.toStringList());

    m_process->start(go,args);
}
Esempio n. 8
0
bool BlastSearch::findProgram(QString programName, QString * command)
{
    QString findCommand = "which " + programName;
#ifdef Q_OS_WIN32
    findCommand = "WHERE " + programName;
#endif

    QProcess find;

    //On Mac, it's necessary to do some stuff with the PATH variable in order
    //for which to work.
#ifdef Q_OS_MAC
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    QStringList envlist = env.toStringList();

    //Add some paths to the process environment
    envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH="
                                                                   "/usr/bin:"
                                                                   "/bin:"
                                                                   "/usr/sbin:"
                                                                   "/sbin:"
                                                                   "/opt/local/bin:"
                                                                   "/usr/local/bin:"
                                                                   "$HOME/bin:"
                                                                   "/usr/local/ncbi/blast/bin:"
                                                                   "\\1");

    find.setEnvironment(envlist);
#endif

    find.start(findCommand);
    find.waitForFinished();

    //On a Mac, we need to use the full path to the program.
#ifdef Q_OS_MAC
    *command = QString(find.readAll()).simplified();
#endif

    return (find.exitCode() == 0);
}