Commit 9591f314 authored by Lisa's avatar Lisa

First draft of the new command line parsing system

parent e343ac82
project(akabei) project(akabei)
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
find_package(KDE4 REQUIRED) find_package(KDE4 REQUIRED)
find_package(AkabeiClient REQUIRED) find_package(AkabeiClient REQUIRED)
find_package(AkabeiCore REQUIRED) find_package(AkabeiCore REQUIRED)
include (KDE4Defaults) include (KDE4Defaults)
include (MacroLibrary) include (MacroLibrary)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
include_directories(${QT_INCLUDES} include_directories(${QT_INCLUDES}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${KDE4_INCLUDE_DIR} ${KDE4_INCLUDE_DIR}
${AKABEICLIENT_INCLUDE_DIR} ${AKABEICLIENT_INCLUDE_DIR}
${AKABEICORE_INCLUDE_DIR}) ${AKABEICORE_INCLUDE_DIR})
set(apm_SRCS queueoperation.cpp upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp main.cpp) set(apm_SRCS queueoperation.cpp upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp cmdline.cpp main.cpp)
#qt4_automoc(${guzuta_SRCS}) #qt4_automoc(${guzuta_SRCS})
kde4_add_executable(akabei ${apm_SRCS}) kde4_add_executable(akabei ${apm_SRCS})
target_link_libraries(akabei ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICLIENT_LIBRARIES}) target_link_libraries(akabei ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICLIENT_LIBRARIES})
......
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QTimer> #include <QTimer>
APM::APM(OperationType type, QList<Operation> operations, QMultiHash<Operation, QString> options, QStringList args, QObject * parent) OperationManager::OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent), : QObject(parent),
m_operationType(type), m_type(type),
m_operations(operations), m_operation(operation),
m_options(options), m_options(options),
m_args(args) m_args(args)
{ {
...@@ -33,43 +33,55 @@ APM::APM(OperationType type, QList<Operation> operations, QMultiHash<Operation, ...@@ -33,43 +33,55 @@ APM::APM(OperationType type, QList<Operation> operations, QMultiHash<Operation,
//QCoreApplication::instance()->quit(); //QCoreApplication::instance()->quit();
//QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit())); //QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
connect(AkabeiClient::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), SLOT(statusChanged(Akabei::Backend::Status))); connect(AkabeiClient::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), SLOT(statusChanged(Akabei::Backend::Status)));
QString root = options.value(APM::RootDir); QString root = ".";
QString cache = options.value(APM::CacheDir); QString cache = ".";
QString dbs = options.value(APM::DBPath); QString dbs = ".";
if (options.contains(APM::RootDir)) {
root = options[APM::RootDir].args[0];
}
if (options.contains(APM::CacheDir)) {
cache = options[APM::CacheDir].args[0];
}
if (options.contains(APM::DBPath)) {
dbs = options[APM::DBPath].args[0];
}
AkabeiClient::Backend::instance()->initialize(root, cache, dbs); AkabeiClient::Backend::instance()->initialize(root, cache, dbs);
} }
APM::~APM() OperationManager::~OperationManager()
{} {
}
void APM::statusChanged(Akabei::Backend::Status status) void OperationManager::statusChanged(Akabei::Backend::Status status)
{ {
if (status == Akabei::Backend::StatusReady) if (status == Akabei::Backend::StatusReady)
start(); start();
} }
void APM::start() void OperationManager::start()
{ {
switch (m_operationType) { switch (m_type) {
case QueryOperationType: { case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(this); QueryOperation * query = new QueryOperation(this);
query->start(m_operations, m_options, m_args); query->start(m_operation, m_options, m_args);
break; break;
} }
case RemoveOperationType: { case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(this); RemoveOperation * remove = new RemoveOperation(this);
remove->start(m_operations, m_options, m_args); remove->start(m_operation, m_options, m_args);
break; break;
} }
case SyncOperationType: { case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(this); SyncOperation * sync = new SyncOperation(this);
sync->start(m_operations, m_options, m_args); sync->start(m_operation, m_options, m_args);
break; break;
} }
case UpgradeOperationType: { case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this); UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operations, m_options, m_args); upgrade->start(m_operation, m_options, m_args);
break; break;
} }
default: default:
......
...@@ -15,74 +15,23 @@ ...@@ -15,74 +15,23 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QStringList> #include <QStringList>
class APM : public QObject #include "cmdline.h"
class OperationManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum OperationType { explicit OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent = 0);
NoType = 0, virtual ~OperationManager();
DatabaseOperationType = 1,
QueryOperationType = 2,
RemoveOperationType = 3,
SyncOperationType = 4,
UpgradeOperationType = 5
};
enum Operation {
NoOperation = 0,
///Query operations
ShowChangelog,
ShowInstalledAsDeps,
ShowInstalledExplicitely,
ShowPackagesOfGroup, //Also in Sync
ShowInformation, //Also in Sync
CheckFiles,
ShowLocal,
ShowOwner,
QueryPackageFile,
SearchLocal,
ShowNotRequired,
ShowUpgradeable,
ShowLess,
///Sync operations
Install,
AsDeps,//Also in upgrade
AsExplicit,//Also in upgrade
RemoveOldPackages,
RemoveAllPackages,
SkipDependencyCheck,//Also in Remove/Upgrade
Force,//Also in upgrade
ListRepo,
Search,
DownloadOnly,
OnlyNeeded,
Ignore,
IgnoreGroup,
UpdateDatabases,
UpdateSystem,
///Remove operations
Remove,
Cascade,
DatabaseOnly,//Also in upgrade
RemoveConfig,
Recursive,
Unneeded,
///Upgrade operation makes only use of operations specified above
///Random
RootDir,
CacheDir,
DBPath
};
explicit APM(OperationType type, QList<Operation> operations, QMultiHash<Operation, QString> options, QStringList args, QObject* parent = 0);
virtual ~APM();
private slots: private slots:
void statusChanged(Akabei::Backend::Status); void statusChanged(Akabei::Backend::Status);
void start(); void start();
private: private:
OperationType m_operationType; APM::OperationType m_type;
QList<Operation> m_operations; APM::OperationName m_operation;
QMultiHash<Operation, QString> m_options; QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args; QStringList m_args;
}; };
......
This diff is collapsed.
/* 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 _CMDLINE_H
#define _CMDLINE_H
#include <QString>
#include <QList>
#include <QHash>
#include <klocalizedstring.h>
#include <kcmdlineargs.h>
#include <exception>
namespace APM
{
enum OperationType {
NoType, DatabaseOperationType, QueryOperationType, RemoveOperationType, SyncOperationType, UpgradeOperationType
};
typedef enum OperationType OperationType;
enum OptionName {
QueryPackageFile, ShowLocal, ShowLess, InstallAsDeps, InstallAsExplicit,
SkipDependencyCheck, Force, DownloadOnly, OnlyNeeded, Ignore, IgnoreGroup, DatabaseOnly,
RemoveConfig, Recursive,
RootDir, CacheDir, DBPath
};
typedef enum OptionName OptionName;
enum OperationName {
None,
ShowChangelog, ShowInstalledAsDeps, ShowInstalledExplicitely, ShowPackagesOfGroup, ShowPackagesOfGroupLocal, ShowInformationLocal,
ShowInformation, CheckFiles, ShowOwner, ShowNotRequired, ShowUpgradeable,
Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateDatabases, UpdateSystem, UpdateDatabaseAndSystem,
Remove, Cascade, Unneeded, SearchLocal,
DatabaseOperation, Upgrade, Help, Version
};
typedef enum OperationName OperationName;
};
/**
* \class AkabeiOption cmdline.h "cmdline.h"
* \brief Representation of a command line option
*/
class AkabeiOption
{
private:
void init(APM::OptionName, const char *, const char *, const char *, bool, QStringList);
public:
APM::OptionName name;
QByteArray commandShort, commandLong;
KLocalizedString description;
bool hasArg;
/*
* Args are required by some options like --ignore or --ignoregroup
*/
QStringList args;
AkabeiOption(APM::OptionName, const char *, const char *, const char *, bool);
AkabeiOption(APM::OptionName, const char *, const char *, const char *, bool, QStringList);
AkabeiOption() {}
};
typedef QList<AkabeiOption> AkabeiOptionList;
/**
* \class AkabeiOperation cmdline.h "cmdline.h"
* \brief Representation of a command line operation
*/
class AkabeiOperation
{
private:
void init(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool, QStringList);
public:
APM::OperationType type;
APM::OperationName name;
QByteArray commandShort, commandLong;
KLocalizedString description;
QHash<APM::OptionName, AkabeiOption> options; /* options that can be associated to this operation */
bool hasFreeArgs;
/*
* An example of free args is the list of packages following an install command
*/
QStringList freeArgs;
AkabeiOperation();
AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool);
AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool, QStringList);
/*
* Checks, with special rules, than no more than one operation is specified on the command line
* see cmdline.cpp for a more detailed explanation
*/
void set(AkabeiOperation &);
/*
* Options checking
*/
void addOption(AkabeiOption &);
bool isOptionSupported(APM::OptionName);
};
typedef QList<AkabeiOperation> AkabeiOperationList;
class CmdLine
{
private:
AkabeiOperation m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_freeArgs;
/* Database */
QMultiHash<QByteArray, AkabeiOperation> acceptedOperations;
AkabeiOptionList acceptedOptions;
QHash<QByteArray, APM::OperationType> typechars;
bool parsed;
public:
CmdLine();
void parse(int argc, char **argv);
APM::OperationType type();
APM::OperationName operation();
QHash<APM::OptionName, AkabeiOption> options();
QStringList freeArgs();
};
class CmdLineException : public std::exception
{
const char* message;
public:
CmdLineException(const char *m)
: message(m)
{}
virtual const char *what() const throw() {
return message;
}
};
#endif
This diff is collapsed.
...@@ -34,62 +34,57 @@ QueryOperation::~QueryOperation() ...@@ -34,62 +34,57 @@ QueryOperation::~QueryOperation()
} }
void QueryOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Operation, QString> options, QStringList args) void QueryOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args)
{ {
if (operations.contains(APM::ShowInformation)) { if (operation == APM::ShowInformationLocal) {
if (args.isEmpty()) if (options.contains(APM::QueryPackageFile)) {
return;
if (operations.contains(APM::QueryPackageFile)) {
showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
} else { } else {
qDebug() << args.first();
showInformation(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first(), Akabei::SearchNameEqual)); showInformation(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first(), Akabei::SearchNameEqual));
//CHange back to searchPackages when we have sorted results after Name and description //CHange back to searchPackages when we have sorted results after Name and description
} }
} else if (operations.contains(APM::ShowPackagesOfGroup)) { } else if (operation == APM::ShowPackagesOfGroupLocal) {
if (args.isEmpty())
return;
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)), connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)),
SLOT(showGroup(QUuid,QList<Akabei::Group*>))); SLOT(showGroup(QUuid,QList<Akabei::Group*>)));
Akabei::Backend::instance()->localDatabase()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + args.first() + "\""); Akabei::Backend::instance()->localDatabase()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + args.first() + "\"");
} else if (operations.contains(APM::ShowChangelog)) { } else if (operation == APM::ShowChangelog) {
if (args.isEmpty()) if (options.contains(APM::QueryPackageFile)) {
return;
if (operations.contains(APM::QueryPackageFile)) {
showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
} else { } else {
showChangelog(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first())); showChangelog(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first()));
} }
} else if (operations.contains(APM::ShowInstalledAsDeps) || operations.contains(APM::ShowInstalledExplicitely)) { } else if (operation == APM::ShowInstalledAsDeps || operation == APM::ShowInstalledExplicitely) {
QString query = "SELECT * FROM packages WHERE"; QString query = "SELECT * FROM packages WHERE";
if (!args.isEmpty()) if (!args.isEmpty()) // TODO: vedi un po' qua che vuol dire
query = query + " Name LIKE \"" + args.first() + "\" AND"; query = query + " Name LIKE \"" + args.first() + "\" AND";
if (operations.contains(APM::ShowInstalledAsDeps)) if (operation == APM::ShowInstalledAsDeps)
query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::InstalledAsDependencyReason); query = query + " InstallReason LIKE 0";// + QString((int)Akabei::Package::InstalledAsDependencyReason);
else else
query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::ExplicitlyInstalledReason); query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::ExplicitlyInstalledReason);
showInstalledAsDeps(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); showInstalledAsDeps(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
} else if (operations.contains(APM::CheckFiles)) { } else if (operation == APM::CheckFiles) {
if (args.isEmpty()) if (options.contains(APM::QueryPackageFile)) {
return;
if (operations.contains(APM::QueryPackageFile)) {
checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
} else { } else {
checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first())); checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first()));
} }
} else if (operations.contains(APM::ShowLocal)) { } else if (operation == APM::SearchLocal) {
if (args.isEmpty()) if (args.isEmpty())
showLocalPackages(QString()); showLocalPackages(QString());
else else
showLocalPackages(args.first()); showLocalPackages(args.first());
} else if (operations.contains(APM::ShowOwner) && !args.isEmpty()) { } else if (operation == APM::ShowOwner) {
showOwner(args.first()); showOwner(args.first());
} else if (operations.contains(APM::SearchLocal)) { } else if (operation == APM::SearchLocal) {
showLocalQuery(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first())); showLocalQuery(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first(), Akabei::SearchNameEqual));
} else if (operations.contains(APM::ShowNotRequired)) { } else if (operation == APM::ShowNotRequired) {
showNotRequired(); showNotRequired();
} else if (operations.contains(APM::ShowUpgradeable)) { } else if (operation == APM::ShowUpgradeable) {
showUpgradeable(); showUpgradeable();
} else { } else {
QTextStream err(stderr);
err << "akabei: Operation not supported yet" << endl;
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <QUuid> #include <QUuid>
#include "apm.h" #include "apm.h"
#include "cmdline.h"
#include <akabeipackage.h> #include <akabeipackage.h>
class QueryOperation : public QObject class QueryOperation : public QObject
...@@ -24,7 +25,7 @@ public: ...@@ -24,7 +25,7 @@ public:
explicit QueryOperation(QObject * parent = 0); explicit QueryOperation(QObject * parent = 0);
virtual ~QueryOperation(); virtual ~QueryOperation();
void start(QList<APM::Operation> operations, QMultiHash<APM::Operation, QString> options, QStringList args); void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
private slots: private slots:
void showInformation(QList<Akabei::Package*> packages); void showInformation(QList<Akabei::Package*> packages);
......
...@@ -35,23 +35,24 @@ int getcols() ...@@ -35,23 +35,24 @@ int getcols()
return ws.ws_col; return ws.ws_col;
} }
QueueOperation::QueueOperation(QList<APM::Operation> operations, QMultiHash< APM::Operation, QString > options, QObject * parent) QueueOperation::QueueOperation(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QObject * parent)
: QObject(parent), : QObject(parent),
m_operations(operations) m_operation(operation),
m_options(options)
{ {
if (operations.contains(APM::Force)) if (options.contains(APM::Force))
m_processingOptions |= Akabei::Force; m_processingOptions |= Akabei::Force;
if (operations.contains(APM::AsDeps)) if (options.contains(APM::InstallAsDeps))
m_processingOptions |= Akabei::InstallAsDependencies; m_processingOptions |= Akabei::InstallAsDependencies;
if (operations.contains(APM::AsExplicit)) if (options.contains(APM::InstallAsExplicit))
m_processingOptions |= Akabei::InstallAsExplicit; m_processingOptions |= Akabei::InstallAsExplicit;
if (operations.contains(APM::SkipDependencyCheck)) if (options.contains(APM::SkipDependencyCheck))
m_processingOptions |= Akabei::SkipDependencies; m_processingOptions |= Akabei::SkipDependencies;
if (operations.contains(APM::DownloadOnly)) if (options.contains(APM::DownloadOnly))
m_processingOptions |= Akabei::DownloadOnly; m_processingOptions |= Akabei::DownloadOnly;
if (operations.contains(APM::RemoveConfig)) if (options.contains(APM::RemoveConfig))
m_processingOptions |= Akabei::RemoveConfigs; m_processingOptions |= Akabei::RemoveConfigs;
if (operations.contains(APM::DatabaseOnly)) if (options.contains(APM::DatabaseOnly))
m_processingOptions |= Akabei::DatabaseOnly; m_processingOptions |= Akabei::DatabaseOnly;
} }
...@@ -116,7 +117,7 @@ void QueueOperation::validationFinished(bool valid, QList<AkabeiClient::Transact ...@@ -116,7 +117,7 @@ void QueueOperation::validationFinished(bool valid, QList<AkabeiClient::Transact
} }
//First we check if the packages we're about to remove are needed somewhere //First we check if the packages we're about to remove are needed somewhere
if (m_action == AkabeiClient::Remove && !m_operations.contains(APM::Cascade) && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { if (m_action == AkabeiClient::Remove && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) {
QList<Akabei::Package*> conflict; QList<Akabei::Package*> conflict;
foreach (AkabeiClient::QueueItem * item, AkabeiClient::Backend::instance()->queue()->items()) { foreach (AkabeiClient::QueueItem * item, AkabeiClient::Backend::instance()->queue()->items()) {
conflict << item->requiredByTree(); conflict << item->requiredByTree();
...@@ -323,4 +324,4 @@ void QueueOperation::transactionMessage(const QString& message) ...@@ -323,4 +324,4 @@ void QueueOperation::transactionMessage(const QString& message)
{ {
QTextStream out(stdout); QTextStream out(stdout);
out << message << endl; out << message << endl;
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ class QueueOperation : public QObject ...@@ -25,7 +25,7 @@ class QueueOperation : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
QueueOperation(QList<APM::Operation> operations, QMultiHash< APM::Operation, QString > options, QObject * parent = 0); QueueOperation(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QObject * parent = 0);
virtual ~QueueOperation(); virtual ~QueueOperation();
void start(AkabeiClient::PackageAction action, QList<Akabei::Package*> packages); void start(AkabeiClient::PackageAction action, QList<Akabei::Package*> packages);
...@@ -44,7 +44,8 @@ signals: ...@@ -44,7 +44,8 @@ signals:
private: private:
AkabeiClient::PackageAction m_action; AkabeiClient::PackageAction m_action;
Akabei::ProcessingOptions m_processingOptions; Akabei::ProcessingOptions m_processingOptions;
QList<APM::Operation> m_operations; APM::OperationName m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
QHash<Akabei::Package*, int> m_progresses; QHash<Akabei::Package*, int> m_progresses;
}; };
......
...@@ -35,31 +35,27 @@ RemoveOperation::~RemoveOperation() ...@@ -35,31 +35,27 @@ RemoveOperation::~RemoveOperation()
} }
void RemoveOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Operation, QString> options, QStringList args) void RemoveOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args)
{ {
m_operations = operations; m_operation = operation;
m_options = options; m_options = options;
m_args = args; m_args = args;
APM::Operation operation = APM::NoOperation;
if (!operations.isEmpty()) QString query = "SELECT * FROM packages WHERE";
operation = operations.first(); foreach (const QString &pkg, args) {
query = query + " name=\"" + pkg + "\"";
if (args.last() != pkg)
query = query + " OR";
}
if (operation == APM::Unneeded) { //TODO: Implement those! if (operation == APM::Unneeded) { //TODO: Implement those!
removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages()); removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages());
} else if (!args.isEmpty()) { } else if (operation == APM::Remove) {
QString query = "SELECT * FROM packages WHERE"; if (options.contains(APM::Recursive)) {
foreach (const QString &pkg, args) {
query = query + " name=\"" + pkg + "\"";
if (args.last() != pkg)
query = query + " OR";
}
if (operations.contains(APM::Recursive))
removeRecursive(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); removeRecursive(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
else } else {
remove(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); remove(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
} else if (!m_operations.isEmpty()) { }
QList<APM::Operation> ops = operations;
ops.removeFirst();
start(ops, options, args);
} else { } else {
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
} }
...@@ -71,7 +67,7 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages) ...@@ -71,7 +67,7 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages)
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
return; return;
} }
QueueOperation *operation = new QueueOperation(m_operations, m_options, this); QueueOperation *operation = new QueueOperation(m_operation, m_options, this);
operation->start(AkabeiClient::Remove, packages); operation->start(AkabeiClient::Remove, packages);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
} }
...@@ -90,7 +86,7 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages) ...@@ -90,7 +86,7 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
pkgs << p; pkgs << p;
} }
} }
QueueOperation *operation = new QueueOperation(m_operations, m_options, this); QueueOperation *operation = new QueueOperation(m_operation, m_options, this);
operation->start(AkabeiClient::Remove, pkgs); operation->start(AkabeiClient::Remove, pkgs);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
} }
...@@ -101,7 +97,7 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages) ...@@ -101,7 +97,7 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
return; return;
} }
qDebug() << "Remove" << packages.count() << "unnneeded"; qDebug() << "APM::Remove" << packages.count() << "unnneeded";
QList<Akabei::Package*> unneeded; QList<Akabei::Package*> unneeded;