Commit dfb77ce2 authored by Lisa's avatar Lisa

Perform operation added. Akabei termination changed with nextOperation() when needed.

parent fb8425ec
......@@ -17,7 +17,17 @@ include_directories(${QT_INCLUDES}
${AKABEICLIENT_INCLUDE_DIR}
${AKABEICORE_INCLUDE_DIR})
set(apm_SRCS queueoperation.cpp upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp cmdline.cpp main.cpp)
set(apm_SRCS
queueoperation.cpp
upgradeoperation.cpp
removeoperation.cpp
syncoperation.cpp
queryoperation.cpp
performoperation.cpp
apm.cpp
cmdline.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})
......
......@@ -13,6 +13,7 @@
#include "syncoperation.h"
#include "removeoperation.h"
#include "upgradeoperation.h"
#include "performoperation.h"
#include <akabeiclient/akabeiclientbackend.h>
......@@ -66,24 +67,34 @@ void OperationManager::start()
switch (m_type) {
case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(m_operations, m_options, m_args, this);
connect(query, SIGNAL(queryFinished()), QCoreApplication::instance(), SLOT(quit()));
query->start();
break;
}
case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(m_operations, m_options, m_args, this);
connect(remove, SIGNAL(removeFinished()), QCoreApplication::instance(), SLOT(quit()));
remove->start();
break;
}
case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(m_operations, m_options, m_args, this);
connect(sync, SIGNAL(syncFinished()), QCoreApplication::instance(), SLOT(quit()));
sync->start();
break;
}
case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this);
connect(upgrade, SIGNAL(upgradeFinished()), QCoreApplication::instance(), SLOT(quit()));
upgrade->start(m_operations, m_options, m_args);
break;
}
case APM::PerformOperationType: {
PerformOperation * perform = new PerformOperation(this);
connect(perform, SIGNAL(performFinished()), QCoreApplication::instance(), SLOT(quit()));
perform->start(m_options, m_args);
break;
}
default:
break;
}
......
......@@ -26,6 +26,7 @@ CmdLine::CmdLine()
typechars.insert("R", APM::RemoveOperationType);
typechars.insert("S", APM::SyncOperationType);
typechars.insert("U", APM::UpgradeOperationType);
typechars.insert("P", APM::PerformOperationType);
/*
* The argument list is only meaningful after reading the command line, so for now it stays empty
......@@ -148,6 +149,17 @@ CmdLine::CmdLine()
upgrade.addOption(ignore);
upgrade.addOption(ignoregroup);
AkabeiOperation perform(APM::PerformOperationType, APM::Perform, "P", "perform", "Performs a series of installations and removals", true);
perform.addOption(skipdependencycheck);
perform.addOption(force);
perform.addOption(databaseonly);
perform.addOption(removeconfig);
perform.addOption(recursive);
perform.addOption(installasdeps);
perform.addOption(installasexplicit);
perform.addOption(downloadonly);
perform.addOption(onlyneeded);
AkabeiOperation help(APM::NoType, APM::Help, "h", "help", "Shows the help message", false);
AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false);
......@@ -155,7 +167,7 @@ CmdLine::CmdLine()
tmp << &updatedb << &removeallcache << &help << &version << &install << &remove << &database;
tmp << &checkfiles << &showowner << &notrequired << &upgradeable << &cascade << &unneeded;
tmp << &removeold << &groups << &info << &listrepo << &groupsl << &searchl << &infol;
tmp << &search << &updatesys << &upgrade << &changelog << &installedasdeps << &installedexp;
tmp << &search << &updatesys << &upgrade << &changelog << &installedasdeps << &installedexp << &perform;
/*
* They have to be pointers otherwise the changes in this foreach
......@@ -171,7 +183,10 @@ CmdLine::CmdLine()
}
/* These are the only operation we need to access directly later, so better speed up searches a bit */
specialOperations << removeallcache << help << version << install;
specialOperations.insert(APM::RemoveAllCache, removeallcache);
specialOperations.insert(APM::Help, help);
specialOperations.insert(APM::Version, version);
specialOperations.insert(APM::Install, install);
}
AkabeiOption::AkabeiOption(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg)
......@@ -298,10 +313,10 @@ void CmdLine::parse(int argc, char** argv)
* These are considered separately and when found, they surpass any other operation that may be present.
*/
if (args->isSet("h")) {
AkabeiOperation help = specialOperations[1];
AkabeiOperation help = specialOperations[APM::Help];
m_operations.insert(APM::Help, help);
} else if (args->isSet("v")) {
AkabeiOperation version = specialOperations[2];
AkabeiOperation version = specialOperations[APM::Version];
m_operations.insert(APM::Version, version);
}
else {
......@@ -338,7 +353,7 @@ void CmdLine::parse(int argc, char** argv)
* so we have to check it separately. Again, malformed versions will be spotted later
*/
if (KCmdLineArgs::allArguments().contains("-Scc")) {
AkabeiOperation special = specialOperations.first();
AkabeiOperation special = specialOperations[APM::RemoveAllCache];
m_operations.insert(special.name, special);
found << special.commandShort;
}
......@@ -429,7 +444,7 @@ void CmdLine::parse(int argc, char** argv)
* -Sy with args first updates and then installs the packages
*/
if (!m_freeArgs.isEmpty() && m_operations.contains(APM::UpdateDatabases)) {
m_operations.insert(APM::Install, specialOperations.last());
m_operations.insert(APM::Install, specialOperations[APM::Install]);
}
if (!m_freeArgs.isEmpty() && !freeArgsRequired()) {
......
......@@ -39,7 +39,7 @@ enum OperationName {
UpdateDatabases, ShowChangelog, ShowInstalledAsDeps, ShowInstalledExplicitely, ShowPackagesOfGroup,
ShowPackagesOfGroupLocal, ShowInformationLocal, ShowInformation, CheckFiles, ShowOwner, ShowNotRequired, ShowUpgradeable,
Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateSystem,
Remove, Cascade, Unneeded, SearchLocal,
Remove, Cascade, Unneeded, SearchLocal, Perform,
DatabaseOperation, Upgrade, Help, Version
};
typedef enum OperationName OperationName;
......@@ -120,7 +120,7 @@ private:
QHash<QByteArray, APM::OperationType> typechars;
/* This is for the few operations that we need to access quickly later */
AkabeiOperationList specialOperations;
QHash<APM::OperationName, AkabeiOperation> specialOperations;
bool parsed;
......
/* This file is part of the Chakra project
Copyright (C) 2011 Lisa "shainer" Vitolo <shainer@chakra-project.org>
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 "performoperation.h"
#include <iostream>
#include <QTextStream>
#include <QList>
#include <QCoreApplication>
#include <QDebug>
PerformOperation::PerformOperation(QObject* parent)
: QObject(parent)
{}
PerformOperation::~PerformOperation() {}
void PerformOperation::start(QHash<APM::OptionName, AkabeiOption> options, QStringList args)
{
m_options = options;
foreach (QString pkg, args) {
if (pkg.endsWith("+")) {
installPkgs << pkg.remove(pkg.size() - 1, pkg.size()); /* removes the suffix */
} else if (pkg.endsWith("-")) {
removePkgs << pkg.remove(pkg.size() - 1, pkg.size());
} else {
QTextStream err(stderr);
err << "akabei: Invalid package argument \"" << pkg << "\" supplied.\n";
QCoreApplication::instance()->quit();
return;
}
}
if (!installPkgs.isEmpty()) {
QList<APM::OperationName> install;
install << APM::Install;
SyncOperation *syncOp = new SyncOperation(install, m_options, installPkgs, this);
connect(syncOp, SIGNAL(syncFinished()), this, SLOT(secondStep()));
syncOp->start();
} else {
secondStep();
}
}
void PerformOperation::secondStep()
{
if (!removePkgs.isEmpty()) {
QList<APM::OperationName> remove;
remove << APM::Remove;
RemoveOperation *removeOp = new RemoveOperation(remove, m_options, removePkgs, this);
connect(removeOp, SIGNAL(removeFinished()), this, SIGNAL(performFinished()));
removeOp->start();
} else {
emit performFinished();
}
}
#include "performoperation.moc"
\ No newline at end of file
/* This file is part of the Chakra project
Copyright (C) 2011 Lisa "shainer" Vitolo <shainer@chakra-project.org>
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 PERFORMOPERATION_H
#define PERFORMOPERATION_H
#include "apm.h"
#include "cmdline.h"
#include "syncoperation.h"
#include "removeoperation.h"
class PerformOperation : public QObject
{
Q_OBJECT
public:
explicit PerformOperation(QObject* parent = 0);
virtual ~PerformOperation();
void start(QHash<APM::OptionName, AkabeiOption> options, QStringList args);
signals:
void performFinished();
private:
QStringList removePkgs, installPkgs;
QHash<APM::OptionName, AkabeiOption> m_options;
private slots:
void secondStep();
};
#endif
\ No newline at end of file
......@@ -94,8 +94,11 @@ void QueryOperation::start()
void QueryOperation::showInformation(QList<Akabei::Package*> packages)
{
if (packages.isEmpty())
if (packages.isEmpty()) {
nextOperation();
return;
}
Akabei::Package * pkg = packages.first();
QTextStream out(stdout);
out.setFieldWidth(20);//TODO: Use QFontMetrics to get width of longest word and use that as width of the field (Also in -Si)
......@@ -129,7 +132,7 @@ void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
{
Q_UNUSED(uuid)
if (groups.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
Akabei::Group * group = groups.first();
......@@ -147,9 +150,10 @@ void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
Akabei::Package * pkg = packages.first();
QTextStream out(stdout);
out << pkg->retrieveChangelog() << endl;
......@@ -160,9 +164,10 @@ void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
QTextStream out(stdout);
QMap<QString, Akabei::Package*> sorted;
foreach (Akabei::Package * pkg, packages)
......@@ -176,9 +181,10 @@ void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
void QueryOperation::checkFiles(QList<Akabei::Package*> packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
Akabei::Package * pkg = packages.first();
QTextStream out(stdout);
int all = 0;
......@@ -226,7 +232,7 @@ void QueryOperation::showOwner(const QString &query)
if (!QFile::exists(query)) {
out << "File does not exists: " << query << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
return;
}
foreach (Akabei::Package * pkg, Akabei::Backend::instance()->localDatabase()->packages()) {
......@@ -234,7 +240,7 @@ void QueryOperation::showOwner(const QString &query)
if (Akabei::Config::instance()->rootDir().absoluteFilePath(file) == query) {
out << query << " is owned by " << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
return;
}
}
......@@ -305,7 +311,7 @@ void QueryOperation::showUpgradeable()
void QueryOperation::nextOperation()
{
if (m_operations.isEmpty()) {
QCoreApplication::instance()->quit();
emit queryFinished();
return;
}
start();
......
......@@ -45,6 +45,9 @@ private slots:
void showLocalQuery(QList<Akabei::Package*>);
void showNotRequired();
void showUpgradeable();
signals:
void queryFinished();
};
#endif // QUERYOPERATION_H
......@@ -61,11 +61,12 @@ void RemoveOperation::start()
}
void RemoveOperation::remove(QList<Akabei::Package*> packages)
{
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
QueueOperation *operation = new QueueOperation(APM::Remove, m_options, this);
operation->start(AkabeiClient::Remove, packages);
connect(operation, SIGNAL(finished()), SLOT(nextOperation()));
......@@ -74,7 +75,7 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages)
void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
QList<Akabei::Package*> pkgs;
......@@ -93,9 +94,10 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
qDebug() << "APM::Remove" << packages.count() << "unnneeded";
QList<Akabei::Package*> unneeded;
foreach (Akabei::Package * pkg, packages) {
......@@ -109,7 +111,7 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
unneeded << pkg;
}
if (unneeded.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
QueueOperation *operation = new QueueOperation(APM::Unneeded, m_options, this);
......@@ -120,7 +122,7 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
void RemoveOperation::nextOperation()
{
if (m_operations.isEmpty()) {
QCoreApplication::instance()->quit();
emit removeFinished();
return;
}
start();
......
......@@ -35,6 +35,9 @@ private:
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
signals:
void removeFinished();
};
#endif // REMOVEOPERATION_H
......@@ -49,13 +49,12 @@ SyncOperation::~SyncOperation() {}
// we can have proper errorhandling
// or let shainer write that CLI parser
void SyncOperation::start()
{
{
QTextStream err(stderr);
Akabei::Backend *backend = Akabei::Backend::instance();
APM::OperationName operation = m_operations.takeFirst();
switch(operation) {
case APM::UpdateDatabases:
{
......@@ -97,7 +96,7 @@ void SyncOperation::start()
}
case APM::Install:
{
{
connect(backend, SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)), SLOT(install(QUuid,QList<Akabei::Package*>)));
queryId = backend->searchPackages(m_args, Akabei::SearchNameEqual);
break;
......@@ -139,6 +138,7 @@ void SyncOperation::updateSystem()
void SyncOperation::upgrade(QUuid uuid, QList< Akabei::Package* > packages)
{
if (packages.isEmpty() || queryId != uuid) {
nextOperation();
return;
}
......@@ -175,6 +175,7 @@ void SyncOperation::upgrade(QUuid uuid, QList< Akabei::Package* > packages)
}
if (toBeUpgraded.isEmpty()) {
nextOperation();
return;
}
......@@ -212,6 +213,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
if (packages.isEmpty()) {
err << i18n("No appropriate packages found") << endl;
err.flush();
nextOperation();
return;
}
......@@ -238,7 +240,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
if (toBeInstalled.isEmpty() && toBeUpgraded.isEmpty() && toBeReinstalled.isEmpty()) {
out << i18n("No appropriate packages found") << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
return;
}
......@@ -289,7 +291,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
}
......@@ -302,7 +304,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
void SyncOperation::searchResult(QUuid , QList< Akabei::Package* > packages)
{
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
nextOperation();
return;
}
......@@ -345,8 +347,11 @@ void SyncOperation::listRepo(const QString &repo)
break;
}
}
if (!db)
if (!db) {
nextOperation();
return;
}
QTextStream out(stdout);
foreach (Akabei::Package * pkg, db->database()->packages()) {
Akabei::Package::List installed = Akabei::Backend::instance()->localDatabase()->queryPackages("SELECT * FROM packages WHERE Name LIKE \"" + pkg->name() + "\"");
......@@ -366,6 +371,7 @@ void SyncOperation::listRepo(const QString &repo)
void SyncOperation::showInformation(QUuid,QList<Akabei::Package*> packages)
{
if (packages.isEmpty()) {
nextOperation();
return;
}
......@@ -444,6 +450,7 @@ void SyncOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
Q_UNUSED(uuid)
if (groups.isEmpty()) {
nextOperation();
return;
}
Akabei::Group * group = groups.first();
......@@ -537,8 +544,8 @@ void SyncOperation::databaseStatusChanged(AkabeiClient::DatabaseHandler::Status
void SyncOperation::nextOperation()
{
if (m_operations.isEmpty()) {
QCoreApplication::instance()->quit();
emit syncFinished();
return;
}
start();
}
\ No newline at end of file
}
......@@ -52,6 +52,9 @@ private:
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
QUuid queryId;
signals:
void syncFinished();
};
#endif // SYNCOPERATION_H
......@@ -43,5 +43,5 @@ void UpgradeOperation::start(QList<APM::OperationName> operations, QHash<APM::Op
QueueOperation *op = new QueueOperation(operations.first(), options, this);
op->start(AkabeiClient::Install, pkgs);
connect(op, SIGNAL(finished()), SLOT(quit()));
connect(op, SIGNAL(finished()), this, SIGNAL(upgradeFinished()));
}
......@@ -23,6 +23,10 @@ public:
virtual ~UpgradeOperation();
void start(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
signals:
void upgradeFinished();
};
#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