Commit 4c28bc41 authored by Lisa's avatar Lisa

New akabei syntax officially supported, old one moved to the macky tool.

parent b3020ad4
......@@ -25,13 +25,14 @@ syncoperation.cpp
queryoperation.cpp
performoperation.cpp
apm.cpp
cmdline.cpp
akabeioptions.cpp
cmdlineparsing.cpp
main.cpp)
add_subdirectory(tools)
#qt4_automoc(${guzuta_SRCS})
kde4_add_executable(akabei ${apm_SRCS})
target_link_libraries(akabei ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICLIENT_LIBRARIES})
target_link_libraries(akabei ${KDE4_KDECORE_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICORE_LIBRARIES} ${AKABEICLIENT_LIBRARIES})
install(TARGETS akabei ${INSTALL_TARGETS_DEFAULT_ARGS})
/* This file is part of the Chakra project
* Definitions, using enums, of types, operations and options
Copyright (C) 2011 Lisa 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 _AKABEIENUMS_H
#define _AKABEIENUMS_H
/*
* NOTE: in OperationName most values are used by both syntax,
* but there are some exceptions. Don't rely on that.
*/
namespace APM
{
enum OperationType
{
NoType,
DatabaseOperationType,
QueryOperationType,
RemoveOperationType,
SyncOperationType,
UpgradeOperationType,
PerformOperationType
};
typedef enum OperationType OperationType;
enum OptionName
{
QueryPackageFile,
ShowLocal,
Local,
ShowLess,
InstallAsDeps,
InstallAsExplicit,
SkipDependencyCheck,
Force,
DownloadOnly,
OnlyNeeded,
Ignore,
IgnoreGroup,
DatabaseOnly,
RemoveConfig,
Recursive,
RootDir,
CacheDir,
DBPath
};
typedef enum OptionName OptionName;
enum OperationName {
None,
Help,
Version,
License,
Authors,
DatabaseOperation,
ShowChangelog,
ShowInstalledAsDeps,
ShowInstalledExplicitely,
CheckFiles,
ShowOwner,
ShowNotRequired,
ShowUpgradeable,
ShowPackagesOfGroup,
ShowInformation,
Search,
Install,
ListRepo,
Newest,
UpdateDatabases,
UpdateSystem,
UpgradeSystem,
Remove,
Unneeded,
Perform,
UpgradeOperation,
};
typedef enum OperationName OperationName;
};
#endif
\ No newline at end of file
/*
* This file is part of the Chakra project
Copyright (C) 2011 Lisa 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 "akabeioptions.h"
#include <QDebug>
AkabeiOption::AkabeiOption(APM::OptionName n, QString& cmdShort, QString& cmdLong, KLocalizedString desc, QString argname)
: m_name(n)
, m_commandShort(cmdShort)
, m_commandLong(cmdLong)
, m_description(desc)
, m_argname(argname)
{}
APM::OptionName AkabeiOption::name() const
{
return m_name;
}
QString AkabeiOption::commandShort() const
{
return m_commandShort;
}
QString AkabeiOption::commandLong() const
{
return m_commandLong;
}
KLocalizedString AkabeiOption::description() const
{
return m_description;
}
QString AkabeiOption::argname() const
{
return m_argname;
}
bool AkabeiOption::hasArgs() const
{
return !m_argname.isEmpty();
}
QStringList AkabeiOption::arguments() const
{
return m_args;
}
void AkabeiOption::operator=(const AkabeiOption& other)
{
this->m_name = other.m_name;
this->m_commandShort = other.m_commandShort;
this->m_commandLong = other.m_commandLong;
this->m_description = other.m_description;
this->m_argname = other.m_argname;
}
bool AkabeiOption::operator==(const AkabeiOption& other) const
{
return this->m_name == other.m_name;
}
void AkabeiOption::addArguments(QString& args)
{
m_args.append(args.split(","));
}
int AkabeiOption::length() const
{
int size = m_commandLong.size();
if (!m_commandShort.isEmpty()) {
size += DASH + COMMA + m_commandShort.size();
}
if (hasArgs()) {
size += m_argname.size() + QUOTES;
}
return size;
}
uint qHash(AkabeiOption const& obj)
{
return qHash(obj.name());
}
AkabeiOperation::AkabeiOperation()
: m_name(APM::None)
{}
AkabeiOperation::AkabeiOperation(APM::OperationName n, QString cmd, KLocalizedString desc, bool a)
: m_name(n)
, m_command(cmd)
, m_description(desc)
, m_freeArgs(a)
{}
void AkabeiOperation::addConnectionWithOption(APM::OptionName opt)
{
if (!m_options.contains(opt)) {
m_options.append(opt);
}
}
bool AkabeiOperation::isOptionSupported(APM::OptionName opt)
{
return m_options.contains(opt);
}
APM::OperationName AkabeiOperation::name() const
{
return m_name;
}
QString AkabeiOperation::command() const
{
return m_command;
}
KLocalizedString AkabeiOperation::description() const
{
return m_description;
}
bool AkabeiOperation::hasFreeArgs() const
{
return m_freeArgs;
}
QList<APM::OptionName> AkabeiOperation::options() const
{
return m_options;
}
void AkabeiOperation::operator=(const AkabeiOperation& other)
{
this->m_name = other.m_name;
this->m_command = other.m_command;
this->m_description = other.m_description;
this->m_freeArgs = other.m_freeArgs;
this->m_options = other.m_options;
}
/*
* This file is part of the Chakra project
* Definition of the operations and options supported, and of the objects used
* to represent them.
Copyright (C) 2011 Lisa 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 AKABEI_OPTIONS_H
#define AKABEI_OPTIONS_H
#include <QStringList>
#include <QHash>
#include <klocalizedstring.h>
#include "akabeienums.h"
/*
* These are useful when showing an aligned list in the help message to represent
* everything in the message which isn't in the objects (like spaces, commas, etc...)
*/
#define COMMA 2
#define DASH 1
#define QUOTES 3
#define INITIAL_SPACING 4
/**
* @class AkabeiOption
* @brief Representation of an option
*
*/
class AkabeiOption
{
APM::OptionName m_name;
QString m_commandShort;
QString m_commandLong;
KLocalizedString m_description;
QString m_argname;
QStringList m_args;
public:
AkabeiOption(APM::OptionName n, QString& cmdShort, QString& cmdLong, KLocalizedString desc, QString argname = "");
AkabeiOption() {}
/**
* @returns the symbolic name associated (unique)
*/
APM::OptionName name() const;
/**
* @returns the short command (can be empty)
*/
QString commandShort() const;
/**
* @returns the long version of the command (never empty)
*/
QString commandLong() const;
/**
* @returns a localized description of this option
*/
KLocalizedString description() const;
/**
* @returns an explanatory string for the argument: used in the help message
*/
QString argname() const;
/**
* @returns whether the option requires an argument (if not, then no argument must be present)
* @note an empty argument name means the option doesn't accept arguments
*/
bool hasArgs() const;
/**
* @returns after parsing the command line, the list of arguments found
*/
QStringList arguments() const;
/**
* @returns the number of character in the printable version of this object: used in the help message
* to keep alignment between lines
*/
int length() const;
void operator=(const AkabeiOption &);
bool operator==(const AkabeiOption &) const;
/**
* @param args the arguments found in the command line, separated by comma
*/
void addArguments(QString &args);
};
/*
* This is used when creating a QSet for removing duplicates in a list.
* Defines the unique key to be used for hashing this object (the name in this case).
*/
uint qHash(AkabeiOption const&);
/**
* @class AkabeiOption
* @brief Representation of an operation.
*
*/
class AkabeiOperation
{
private:
APM::OperationName m_name;
QString m_command;
KLocalizedString m_description;
bool m_freeArgs;
QList<APM::OptionName> m_options;
public:
AkabeiOperation();
AkabeiOperation(APM::OperationName, QString, KLocalizedString, bool a = false);
/**
* @returns the symbolic name associated (unique)
*/
APM::OperationName name() const;
/**
* @returns the (only) command this operation is described by
*/
QString command() const;
/**
* @returns a localized description
*/
KLocalizedString description() const;
/**
* @returns whether this operation admits arguments
*/
bool hasFreeArgs() const;
/**
* @returns the list of options that are meaningful in the context of this operation
*/
QList<APM::OptionName> options() const;
/**
* Adds a "connection" with the option: this means the option is meaningful if present with this operation.
* @param opt the unique identifier of the option.
*/
void addConnectionWithOption(APM::OptionName opt);
/**
* @returns whether the option is meaningful with this operation
*/
bool isOptionSupported(APM::OptionName opt);
void operator=(const AkabeiOperation &);
};
#endif
\ No newline at end of file
......@@ -8,6 +8,7 @@
version 2 of the License, or (at your option) any later version.
*/
#include "apm.h"
#include "akabeioptions.h"
#include "queryoperation.h"
#include "syncoperation.h"
......@@ -23,7 +24,7 @@
#include <QCoreApplication>
#include <QTimer>
OperationManager::OperationManager(APM::OperationType type, QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
OperationManager::OperationManager(APM::OperationType type, QList<APM::OperationName> operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject * parent)
: QObject(parent),
m_type(type),
m_operations(operations),
......@@ -39,13 +40,13 @@ OperationManager::OperationManager(APM::OperationType type, QList<APM::Operation
QString dbs;
if (options.contains(APM::RootDir)) {
root = options[APM::RootDir].args[0];
root = options[APM::RootDir].at(0);
}
if (options.contains(APM::CacheDir)) {
cache = options[APM::CacheDir].args[0];
cache = options[APM::CacheDir].at(0);
}
if (options.contains(APM::DBPath)) {
dbs = options[APM::DBPath].args[0];
dbs = options[APM::DBPath].at(0);
}
AkabeiClient::Backend::instance()->initialize(root, cache, dbs);
......
......@@ -15,13 +15,14 @@
#include <QtCore/QObject>
#include <QStringList>
#include "cmdline.h"
#include "cmdlineparsing.h"
#include "akabeioptions.h"
class OperationManager : public QObject
{
Q_OBJECT
public:
explicit OperationManager(APM::OperationType type, QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent = 0);
explicit OperationManager(APM::OperationType type, QList< APM::OperationName > operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject* parent = 0);
virtual ~OperationManager();
private slots:
......@@ -31,7 +32,7 @@ private slots:
private:
APM::OperationType m_type;
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QHash<APM::OptionName, QStringList> m_options;
QStringList m_args;
};
......
This diff is collapsed.
/*
* This file is part of the Chakra project
* Classes that manage the parsing
Copyright (C) 2011 Lisa 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 CMDLINEPARSING_H
#define CMDLINEPARSING_H
#include <QStringList>
#include <QHash>
#include <exception>
#include <kaboutdata.h>
#include <klocalizedstring.h>
#include "akabeioptions.h"
class CmdLineUtils
{
private:
static int getSpacingDistance(QHash<QString, AkabeiOperation> &, QHash<QString, AkabeiOption> &);
public:
static void printHelpMessage(QHash<QString, AkabeiOperation> &, QHash<QString, AkabeiOption> &, KAboutData &);
static void printVersion(KAboutData &);
static void printAuthors(KAboutData &);
static void printLicenses(KAboutData&);
};
class CmdLineParser
{
public:
CmdLineParser(int, char**, const KAboutData&);
/**
* Add operation to those supported.
*
* @param name the symbolic name
* @param command the command associated
* @param desc a description
* @param args whether the operation requires arguments
*/
void addOperation(APM::OperationName name, QString command, const char *desc, bool args);
/**
* Add option to those supported
*
* @param name the symbolic name
* @param cmdShort the short version of the command (can be empty)
* @param cmdLong the long command (never empty)
* @param desc a description
* @param argname the printable name of the arguments requested, if any
*/
void addOption(APM::OptionName name, QString cmdShort, QString cmdLong, const char *desc, QString argname="");
/**
* Add the possibility of use an option with an operation.
* The operation involved is the last one added to the pool.
*
* @param name the symbolic name of the option to add.
*/
void addConnectionWithOption(APM::OptionName name);
/**
* Some special options can be associated to every operation.
*
* @param name the symbolic name of that option
*/
void connectOptionWithEverything(APM::OptionName name);
/**
* Do parsing
*/
void parse();
/**
* @returns type of the operation
*/
APM::OperationType type();
/**
* @returns the operation object
*/
AkabeiOperation operation();
/**
* @returns an hash with all the options
*/
QHash<APM::OptionName, QStringList> options();
/**
* @returns everything else found in the command line which didn't fall
* in the previous categories
*/
QStringList args();
private:
QString m_lastOperation;
QStringList m_argv;
KAboutData m_data;
QHash<QString, AkabeiOperation> m_acceptedOperations;
QHash<QString, AkabeiOption> m_acceptedOptions;
AkabeiOperation m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
void init(int, char **);
void doParse();
};
class CmdLineParsingException : public std::exception
{
const char *message;
public:
CmdLineParsingException(const char *m)
: message(m)
{}
virtual const char *what() const throw()
{
return message;
}
};
class MissingOperationException : public CmdLineParsingException
{
public:
MissingOperationException()
: CmdLineParsingException("no operation specified.")
{}
};
#endif
\ No newline at end of file
This diff is collapsed.
......@@ -22,7 +22,7 @@ PerformOperation::PerformOperation(QObject* parent)
PerformOperation::~PerformOperation() {}
void PerformOperation::start(QHash<APM::OptionName, AkabeiOption> options, QStringList args)
void PerformOperation::start(QHash<APM::OptionName, QStringList> options, QStringList args)
{
m_options = options;
......
......@@ -12,7 +12,7 @@
#define PERFORMOPERATION_H
#include "apm.h"
#include "cmdline.h"
#include "cmdlineparsing.h"
#include "syncoperation.h"
#include "removeoperation.h"
......@@ -24,14 +24,14 @@ public:
explicit PerformOperation(QObject* parent = 0);
virtual ~PerformOperation();
void start(QHash<APM::OptionName, AkabeiOption> options, QStringList args);
void start(QHash<APM::OptionName, QStringList> options, QStringList args);
signals:
void performFinished();
private:
QStringList removePkgs, installPkgs;
QHash<APM::OptionName, AkabeiOption> m_options;
QHash<APM::OptionName, QStringList> m_options;
private slots:
void secondStep();
......
......@@ -23,7 +23,7 @@
#include <QDir>
#include <QCoreApplication>
QueryOperation::QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
QueryOperation::QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject * parent)
: QObject(parent)
, m_operations(operations)
, m_options(options)
......@@ -40,14 +40,14 @@ void QueryOperation::start()
{
APM::OperationName operation = m_operations.takeFirst();
if (operation == APM::ShowInformationLocal) {
if (operation == APM::ShowInformation) {
if (m_options.contains(APM::QueryPackageFile)) {
showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} else {
showInformation(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first(), Akabei::SearchNameEqual));
//CHange back to searchPackages when we have sorted results after Name and description
}
} else if (operation == APM::ShowPackagesOfGroupLocal) {
} else if (operation == APM::ShowPackagesOfGroup) {
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)),
SLOT(showGroup(QUuid,QList<Akabei::Group*>)));
Akabei::Backend::instance()->localDatabase()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + m_args.first() + "\"");
......@@ -72,14 +72,14 @@ void QueryOperation::start()
} else {
checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first()));
}
} else if (operation == APM::SearchLocal) {
} else if (operation == APM::Search) {
if (m_args.isEmpty())
showLocalPackages(QString());
else
showLocalPackages(m_args.first());
} else if (operation == APM::ShowOwner) {
showOwner(m_args.first());
} else if (operation == APM::SearchLocal) {
} else if (operation == APM::Search) {
showLocalQuery(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first(), Akabei::SearchNameEqual));
} else if (operation == APM::ShowNotRequired) {
showNotRequired();
......
......@@ -15,21 +15,21 @@
#include <QUuid>
#include "apm.h"
#include "cmdline.h"
#include "cmdlineparsing.h"
#include <akabeipackage.h>
class QueryOperation : public QObject
{
Q_OBJECT
public:
explicit QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent = 0);
explicit QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject * parent = 0);
virtual ~QueryOperation();
void start();
private:
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QHash<APM::OptionName, QStringList> m_options;
QStringList m_args;
void nextOperation();
......
......@@ -35,7 +35,7 @@ int getcols()
return ws.ws_col;
}
QueueOperation::QueueOperation(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QObject * parent)
QueueOperation::QueueOperation(APM::OperationName operation, QHash<APM::OptionName, QStringList> options, QObject * parent)
: QObject(parent),
m_operation(operation),
m_options(options)
......
......@@ -25,7 +25,7 @@ class QueueOperation : public QObject
{
Q_OBJECT
public:
QueueOperation(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QObject * parent = 0);