Commit 07e6a2e1 authored by Lukas Appelhans's avatar Lukas Appelhans

Upgrade operation should work

parent 58786b5a
......@@ -15,7 +15,7 @@ include_directories(${QT_INCLUDES}
${AKABEICLIENT_INCLUDE_DIR}
${AKABEICORE_INCLUDE_DIR})
set(apm_SRCS removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp main.cpp)
set(apm_SRCS upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp main.cpp)
#qt4_automoc(${guzuta_SRCS})
kde4_add_executable(akabei ${apm_SRCS})
target_link_libraries(akabei ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICLIENT_LIBRARIES})
......
......@@ -12,6 +12,7 @@
#include "queryoperation.h"
#include "syncoperation.h"
#include "removeoperation.h"
#include "upgradeoperation.h"
#include <akabeiclient/akabeiclientbackend.h>
......@@ -63,6 +64,11 @@ void APM::start()
sync->start(m_operations, m_options, m_args);
break;
}
case UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operations, m_options, m_args);
break;
}
default:
break;
}
......
......@@ -44,12 +44,12 @@ public:
ShowUpgradeable,
ShowLess,
///Sync operations
AsDeps,
AsExplicit,
AsDeps,//Also in upgrade
AsExplicit,//Also in upgrade
RemoveOldPackages,
RemoveAllPackages,
SkipDependencyCheck,//Also in Remove
Force,
SkipDependencyCheck,//Also in Remove/Upgrade
Force,//Also in upgrade
ListRepo,
Search,
DownloadOnly,
......@@ -60,10 +60,11 @@ public:
UpdateSystem,
///Remove operations
Cascade,
DatabaseOnly,
DatabaseOnly,//Also in upgrade
RemoveConfig,
Recursive,
Unneeded
///Upgrade operation makes only use of operations specified above
};
explicit APM(OperationType type, QList<Operation> operations, QMultiHash<Operation, QString> options, QStringList args, QObject* parent = 0);
virtual ~APM();
......
......@@ -36,7 +36,11 @@ void RemoveOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Op
m_operations = operations;
m_options = options;
m_args = args;
if (operations.contains(APM::DatabaseOnly)) {
APM::Operation operation = APM::NoOperation;
if (!operations.isEmpty())
operation = operations.first();
if (operation == APM::Unneeded) { //TODO: Implement those!
} else if (operation == APM::Recursive) {
} else {
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, args) {
......
/* This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "upgradeoperation.h"
#include <kdebug.h>
#include <akabeiclientbackend.h>
#include <akabeiclientqueue.h>
#include <akabeiclienttransactionhandler.h>
#include <klocale.h>
#include <akabeiconfig.h>
#include <QFile>
#include <kio/global.h>
#include <QDir>
#include <akabeioperationrunner.h>
#include <QCoreApplication>
//FIXME: There is actually a bunch of code duplication with SyncOperation and RemoveOperation... maybe we can create something that is used in all of them :)
UpgradeOperation::UpgradeOperation(QObject * parent)
: QObject(parent)
{
}
UpgradeOperation::~UpgradeOperation()
{
}
void UpgradeOperation::start(QList< APM::Operation > operations, QMultiHash< APM::Operation, QString > options, QStringList args)
{
if (args.isEmpty()) {
return;
}
QList<Akabei::Package*> pkgs;
foreach (const QString &p, args)
pkgs << Akabei::Backend::instance()->loadPackageFromFile(p);
foreach (Akabei::Package * pkg, pkgs)
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Install);
Akabei::ProcessingOptions processingOpts;
if (operations.contains(APM::Force))
processingOpts |= Akabei::Force;
if (operations.contains(APM::AsDeps))
processingOpts |= Akabei::InstallAsDependencies;
if (operations.contains(APM::AsExplicit))
processingOpts |= Akabei::InstallAsExplicit;
if (operations.contains(APM::SkipDependencyCheck))
processingOpts |= Akabei::SkipDependencies;
if (operations.contains(APM::DownloadOnly))
processingOpts |= Akabei::DownloadOnly;
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(newTransactionMessage(QString)), SLOT(transactionMessage(QString)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(processingOpts);
}
void UpgradeOperation::validationFinished(bool valid)
{
QTextStream out(stdout);
if (!valid) {
out << i18n("The transaction could not be validated") << endl;
out.flush();
return;
}
int downloadSize = 0;
int installSize = 0;
out << i18n("Packages: ");
foreach (AkabeiClient::QueueItem * item, AkabeiClient::Backend::instance()->queue()->items()) {
if (item != AkabeiClient::Backend::instance()->queue()->items().first())
out << ", ";
out << item->package()->name();
if (item->package()->database() != Akabei::Backend::instance()->localDatabase() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(item->package()->filename())))
downloadSize += item->package()->size();
installSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Install && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { //FIXME: Why this?
foreach (Akabei::Package * dep, item->dependencyTree()) {
out << ", " << dep->name();
if (dep->database() != Akabei::Backend::instance()->localDatabase() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(dep->filename())))
downloadSize += dep->size();
installSize += dep->installedSize();
}
}
}
out << endl << endl;
out << i18n("Download size: %1", KIO::convertSize(downloadSize)) << endl;
out << i18n("Installed size: %1", KIO::convertSize(installSize)) << endl;
out.flush();
out << i18n("Continue with installation?[y/n]");
out.flush();
//std::string input;
//getline(std::cin, input);
//if (input != "y")
// return;
kDebug() << "Let's install";
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(progressChanged(int)), SLOT(showProgress(int)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(finished()), SLOT(finished()));
AkabeiClient::Backend::instance()->transactionHandler()->process();
}
void UpgradeOperation::showProgress(int progress)
{
QTextStream out(stdout);
out.reset();
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";//FIXME
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
void UpgradeOperation::finished()
{
QTextStream out(stdout);
if (Akabei::Backend::instance()->operationRunner()->errors().isEmpty()) {
out << i18n("The transaction finished successfully!") << endl;
} else {
out << i18np("There has been an error during the transaction.", "There have been errors during the transaction.", Akabei::Backend::instance()->operationRunner()->errors().count());
}
QCoreApplication::instance()->quit();
}
void UpgradeOperation::errors(QList<Akabei::Error*>& errors)
{
kDebug() << "yoyoyo";
QTextStream out(stdout);
out << i18n("Errors occurred: ") << endl;
foreach (Akabei::Error * err, errors) {
out << err->description() << endl;
}
out.flush();
}
void UpgradeOperation::transactionMessage(const QString& message)
{
QTextStream out(stdout);
out << message << endl;
}
/* This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef UPGRADEOPERATION_H
#define UPGRADEOPERATION_H
#include <QtCore/QObject>
#include "apm.h"
#include <akabeierror.h>
class UpgradeOperation : public QObject
{
Q_OBJECT
public:
UpgradeOperation(QObject * parent = 0);
virtual ~UpgradeOperation();
void start(QList<APM::Operation> operations, QMultiHash<APM::Operation, QString> options, QStringList args);
private slots:
void validationFinished(bool valid);
void showProgress(int progress);
void finished();
void errors(QList<Akabei::Error*>& errors);
void transactionMessage(const QString &message);
};
#endif // UPGRADEOPERATION_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment