<commit_before>/*
 *   Copyright 2012 Coherent Theory LLC
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#include "packageidinstalljob.h"

#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>

#include "assetoperations.h"
#include "rpmhandler.h"

namespace Bodega
{

PackageIdInstallJob::PackageIdInstallJob(QNetworkReply *reply, Session *session,
                               RpmHandler *handler)
    : InstallJob(reply, session)
{
    m_handler = handler;
}

PackageIdInstallJob::~PackageIdInstallJob()
{
}

void PackageIdInstallJob::downloadFinished(const QString &localFile)
{
    QFile idFile(localFile);

    QString pkgId;
    if (!idFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        setError(Error(Error::Session,
                   QString(QLatin1String("packageid/1")),
                   tr("Install error"),
                   tr("failed to open the descriptor file")));
        return;
    }

    while (!idFile.atEnd()) {
        pkgId = QLatin1String(idFile.readLine());
        if (pkgId.split(QLatin1Char(';'), QString::KeepEmptyParts).count() == 4) {
            m_packageId = pkgId;
            break;
        }
    }
    idFile.close();
    if (m_packageId.isEmpty()) {
        setError(Error(Error::Session,
                   QString(QLatin1String("packageid/2")),
                   tr("Install error"),
                   tr("failed to parse the descriptor file")));
        return;
    }

    qDebug() << "Simulate install" << m_packageId;

    PackageKit::Transaction *transaction = new PackageKit::Transaction(this);
    transaction->simulateInstallPackage(PackageKit::Package(m_packageId));

    connect(transaction, SIGNAL(errorCode(PackageKit::Transaction::Error, QString)),<commit_msg>package descriptor is a valid INI file<commit_after>/*
 *   Copyright 2012 Coherent Theory LLC
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#include "packageidinstalljob.h"

#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QSettings>

#include "assetoperations.h"
#include "rpmhandler.h"

namespace Bodega
{

PackageIdInstallJob::PackageIdInstallJob(QNetworkReply *reply, Session *session,
                               RpmHandler *handler)
    : InstallJob(reply, session)
{
    m_handler = handler;
}

PackageIdInstallJob::~PackageIdInstallJob()
{
}

void PackageIdInstallJob::downloadFinished(const QString &localFile)
{
    QFile idFile(localFile);

    QString pkgId;
    if (!idFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        setError(Error(Error::Session,
                   QString(QLatin1String("packageid/1")),
                   tr("Install error"),
                   tr("failed to open the descriptor file")));
        return;
    }

    idFile.close();
    
    QSettings *settings = new QSettings(localFile, QSettings::IniFormat, 0);

    m_packageId = settings->value(QLatin1String("packageId")).toString();
    delete settings;

    if (m_packageId.isEmpty()) {
        setError(Error(Error::Session,
                   QString(QLatin1String("packageid/2")),
                   tr("Install error"),
                   tr("failed to parse the descriptor file")));
        return;
    }

    qDebug() << "Simulate install" << m_packageId;

    PackageKit::Transaction *transaction = new PackageKit::Transaction(this);
    transaction->simulateInstallPackage(PackageKit::Package(m_packageId));

    connect(transaction, SIGNAL(errorCode(PackageKit::Transaction::Error, QString)),
{'fraction_non_alphanumeric': 0.10195758564437195, 'fraction_numerical': 0.009176182707993474, 'mean_word_length': 3.1638370118845502, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4256171', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1343, 'n_words': 414}