Ejemplo n.º 1
0
void SessionListWidget::parseQstat(QString const& qstat)
{
   QStringList lines = qstat.split('\n');

   JobDefinition *job = NULL;
   QMap<QString, QString> jobSpec, jobVars;

   QRegExp rxJobId("[0-9]+\\.pbs01");
   QRegExp rxKey("[A-Za-z_\\.]+");
   QString key(""), value("");
   for(QStringList::const_iterator line = lines.begin();
       line != lines.end();
       line++)
   {
      if(line->isEmpty()) { /* empty */ }
      else if(line->startsWith("Job Id:")) {
         if(job != NULL) {
            job->update(jobSpec);
            sessions.append(*job);
            delete job;
            job = NULL;
            jobSpec.clear();
            jobVars.clear();
         }
         rxJobId.indexIn(*line);
         job = new JobDefinition(rxJobId.cap());
      }
      else if(line->startsWith("    ")) {  /* keys start with 4 spaces */
         if(key == "Variable_List") {
            QStringList vars(jobSpec[key].split(","));
            for(QStringList::const_iterator i = vars.begin();
                i != vars.end(); 
                i++)
            {
               int eq = i->indexOf('=');
               jobVars.insert(i->left(eq), i->mid(eq + 1));
            }
         }
         rxKey.indexIn(*line);
         key = rxKey.cap(0);
         value = line->mid(line->indexOf('=') + 2);
         jobSpec.insert(key, value);
      }
      else if(line->at(0) == '\t') {
         /* append to the previous key */
         jobSpec[key].append(line->mid(1));
      }
   }
   if(job) {
      job->update(jobSpec);
      sessions.append(*job);
   }

   qDebug() << sessions;
}
Ejemplo n.º 2
0
bool MercurialPlugin::parseStatus(DVcsJob *job) const
{
    if (job->status() != VcsJob::JobSucceeded) {
        mercurialDebug() << "Job failed: " << job->output();
        return false;
    }

    const QString dir = job->directory().absolutePath().append(QDir::separator());
    mercurialDebug() << "Job succeeded for " << dir;
    const QStringList output = job->output().split('\n', QString::SkipEmptyParts);
    QList<QVariant> filestatus;

    QSet<QUrl> conflictedFiles;

    QStringList::const_iterator it = output.constBegin();

    // FIXME: Revive this functionality and add tests for it!
    // conflicts first
//     for (; it != output.constEnd(); it++) {
//         QChar stCh = it->at(0);
//         if (stCh == '%') {
//             it++;
//             break;
//         }
// 
//         QUrl file = QUrl::fromLocalFile(it->mid(2).prepend(dir));
// 
//         VcsStatusInfo status;
//         status.setUrl(file);
//         // FIXME: conflicts resolved
//         status.setState(VcsStatusInfo::ItemHasConflicts);
// 
//         conflictedFiles.insert(file);
//         filestatus.append(qVariantFromValue(status));
//     }

    // standard statuses next
    for (; it != output.constEnd(); it++) {
        QChar stCh = it->at(0);

        QUrl file = QUrl::fromLocalFile(it->mid(2).prepend(dir));

        if (!conflictedFiles.contains(file)) {
            VcsStatusInfo status;
            status.setUrl(file);
            status.setState(charToState(stCh.toLatin1()));
            filestatus.append(qVariantFromValue(status));
        }
    }

    job->setResults(qVariantFromValue(filestatus));
    return true;
}
CodaClientApplication::ParseArgsResult CodaClientApplication::parseArguments(QString *errorMessage)
{
    int argNumber = 1;
    const QStringList args = QCoreApplication::arguments();
    const QStringList::const_iterator cend = args.constEnd();
    QStringList::const_iterator it = args.constBegin();
    bool optionsEnd = false;
    for (++it; it != cend; ++it) {
        if (!optionsEnd  && *it == QLatin1String("--")) {
            optionsEnd = true;
            continue;
        }
        if (!optionsEnd &&  it->startsWith(QLatin1Char('-')) && it->size() == 2) {
            switch (it->at(1).toAscii()) {
            case 'v':
                m_verbose++;
                break;
            case 'd':
                m_launchDebug = true;
                break;
            case 's':
                m_installSilently = true;
                break;
            case 'c':
                if (++it == cend) {
                    *errorMessage = QString::fromLatin1("Parameter missing for -c");
                    return ParseArgsError;
                }
                m_putChunkSize = it->toULongLong() * 1024;
                if (!m_putChunkSize) {
                    *errorMessage = QString::fromLatin1("Invalid chunk size.");
                    return ParseArgsError;
                }
                break;
            default:
                *errorMessage = QString::fromLatin1("Invalid option %1").arg(*it);
                return ParseArgsError;
            }
        } else {
            if (!parseArgument(*it, argNumber++, errorMessage))
                return ParseArgsError;
        }
    } //for loop
    // Basic Check & init
    switch (m_mode) {
    case Invalid:
        return ParseArgsError;
    case Launch:
        if (m_address.isEmpty() || !m_launchUID || m_launchBinary.isEmpty()) {
            *errorMessage = QString::fromLatin1("Not enough parameters for launch.");
            return ParseInitError;
        }
        break;
    case Ping:
        if (m_address.isEmpty()) {
            *errorMessage = QString::fromLatin1("Not enough parameters for ping.");
            return ParseInitError;
        }
        if (!isSerialPort(m_address)) {
            *errorMessage = QString::fromLatin1("'ping' not supported for TCP/IP.");
            return ParseInitError;
        }
        break;
    case Install:
        if (m_address.isEmpty() || m_installSisFile.isEmpty()) {
            *errorMessage = QString::fromLatin1("Not enough parameters for install.");
            return ParseInitError;
        }
        break;
    case Uninstall:
        if (!m_uninstallPackage) {
            *errorMessage = QString::fromLatin1("Not enough parameters for uninstall.");
            return ParseInitError;
        }
        break;
    case Put: {
        if (m_address.isEmpty() || m_putLocalFile.isEmpty() || m_putRemoteFile.isEmpty()) {
            *errorMessage = QString::fromLatin1("Not enough parameters for put.");
            return ParseInitError;
        }
        const QFileInfo fi(m_putLocalFile);
        if (!fi.isFile() || !fi.isReadable()) {
            *errorMessage = QString::fromLatin1("Local file '%1' not readable.").arg(m_putLocalFile);
            return ParseInitError;
        }
    }
        break;
    default:
        break;
    }
    return ParseArgsOk;
}