Commit 9b06ba79 authored by Lisa's avatar Lisa
Browse files

Added a new operation to show all installed packages.

parent 2b224f25
......@@ -72,6 +72,7 @@ enum OperationName {
ShowPackagesOfGroup,
ShowInformation,
Search,
ShowInstalledPackages,
Install,
ListRepo,
Newest,
......
......@@ -54,6 +54,9 @@ void initAkabeiOperations(CommandLineParser *parser)
AkabeiOperation database(APM::DatabaseOperationType, APM::DatabaseOperation, "", "database", "Database operation", false);
AkabeiOperation installed(APM::QueryOperationType, APM::ShowInstalledPackages, "", "local", "Shows installed packages", false);
installed.addConnectionWithOption(APM::ShowLess);
AkabeiOperation changelog(APM::QueryOperationType, APM::ShowChangelog, "", "changelog", "Shows changelog of the package", true);
changelog.addConnectionWithOption(APM::QueryPackageFile);
......@@ -63,7 +66,7 @@ void initAkabeiOperations(CommandLineParser *parser)
AkabeiOperation exp(APM::QueryOperationType, APM::ShowInstalledExplicitely, "", "explicit", "Shows packages which got installed explicitely", false);
exp.addConnectionWithOption(APM::Ignore);
exp.addConnectionWithOption(APM::IgnoreGroup);
exp.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation check(APM::QueryOperationType, APM::CheckFiles, "", "check", "Check if the files of the package are available", true);
check.addConnectionWithOption(APM::QueryPackageFile);
......@@ -97,7 +100,6 @@ void initAkabeiOperations(CommandLineParser *parser)
AkabeiOperation repo(APM::SyncOperationType, APM::ListRepo, "", "repo", "List all packages in a repository", true);
repo.addConnectionWithOption(APM::Ignore);
repo.addConnectionWithOption(APM::IgnoreGroup);
repo.addConnectionWithOption(APM::Local);
AkabeiOperation search(APM::SyncOperationType, APM::Search, "", "search", "Searches repositories for a word", true);
search.addConnectionWithOption(APM::Local);
......@@ -113,6 +115,8 @@ void initAkabeiOperations(CommandLineParser *parser)
clean.addConnectionWithOption(APM::Force);
clean.addConnectionWithOption(APM::RemoveConfig);
clean.addConnectionWithOption(APM::DatabaseOnly);
clean.addConnectionWithOption(APM::Ignore);
clean.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation sync(APM::SyncOperationType, APM::UpdateDatabases, "", "sync", "Refresh databases", false);
......@@ -151,6 +155,7 @@ void initAkabeiOperations(CommandLineParser *parser)
get.addConnectionWithOption(APM::SkipDependencyCheck);
parser->addOperation(database);
parser->addOperation(installed);
parser->addOperation(changelog);
parser->addOperation(deps);
parser->addOperation(exp);
......@@ -194,10 +199,8 @@ void initPakabeiOperations(CommandLineParser *parser)
AkabeiOperation check(APM::QueryOperationType, APM::CheckFiles, "k", "check", "Check if the files of the package are available", true);
check.addConnectionWithOption(APM::QueryPackageFile);
check.addConnectionWithOption(APM::ShowLocal);
AkabeiOperation owner(APM::QueryOperationType, APM::ShowOwner, "o", "owns", "Returns the package which contains the file", true);
owner.addConnectionWithOption(APM::ShowLocal);
AkabeiOperation unrequired(APM::QueryOperationType, APM::ShowNotRequired, "t", "unrequired", "Returns packages which are not required by others", false);
unrequired.addConnectionWithOption(APM::Ignore);
......@@ -208,24 +211,27 @@ void initPakabeiOperations(CommandLineParser *parser)
upgrades.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation groupsl(APM::QueryOperationType, APM::ShowPackagesOfGroup, "g", "groups", "Shows all packages in a package group", true);
groupsl.addConnectionWithOption(APM::Ignore);
AkabeiOperation infol(APM::QueryOperationType, APM::ShowInformation, "i", "info", "Shows package information", true);
infol.addConnectionWithOption(APM::ShowLess);
infol.addConnectionWithOption(APM::QueryPackageFile);
AkabeiOperation searchl(APM::QueryOperationType, APM::Search, "s", "search", "Searches repositories for a word", true);
searchl.addConnectionWithOption(APM::Ignore);
searchl.addConnectionWithOption(APM::IgnoreGroup);
searchl.addConnectionWithOption(APM::ShowLess);
AkabeiOperation installed(APM::QueryOperationType, APM::ShowInstalledPackages, "ss", "installed", "Shows all installed packages", false);
installed.addConnectionWithOption(APM::ShowLess);
AkabeiOperation remove(APM::RemoveOperationType, APM::Remove, "R", "remove", "Remove packages", true);
remove.addConnectionWithOption(APM::SkipDependencyCheck);
remove.addConnectionWithOption(APM::Force);
remove.addConnectionWithOption(APM::DatabaseOnly);
remove.addConnectionWithOption(APM::RemoveConfig);
remove.addConnectionWithOption(APM::Recursive);
AkabeiOperation unneeded(APM::RemoveOperationType, APM::Unneeded, "u", "unneeded", "Remove not needed packages", false);
unneeded.addConnectionWithOption(APM::Force);
unneeded.addConnectionWithOption(APM::RemoveConfig);
unneeded.addConnectionWithOption(APM::DatabaseOnly);
unneeded.addConnectionWithOption(APM::Ignore);
unneeded.addConnectionWithOption(APM::IgnoreGroup);
......@@ -238,18 +244,15 @@ void initPakabeiOperations(CommandLineParser *parser)
install.addConnectionWithOption(APM::OnlyNeeded);
AkabeiOperation groups(APM::SyncOperationType, APM::ShowPackagesOfGroup, "g", "groups", "Shows all packages in a package group", true);
groups.addConnectionWithOption(APM::Ignore);
AkabeiOperation info(APM::SyncOperationType, APM::ShowInformation, "i", "info", "Shows package information", true);
info.addConnectionWithOption(APM::ShowLess);
info.addConnectionWithOption(APM::QueryPackageFile);
AkabeiOperation search(APM::SyncOperationType, APM::Search, "s", "search", "Searches repositories for a word", true);
search.addConnectionWithOption(APM::Ignore);
search.addConnectionWithOption(APM::IgnoreGroup);
search.addConnectionWithOption(APM::ShowLess);
AkabeiOperation repo(APM::SyncOperationType, APM::ListRepo, "l", "list", "List all packages in a repository", true);
repo.addConnectionWithOption(APM::ShowLocal);
repo.addConnectionWithOption(APM::Ignore);
repo.addConnectionWithOption(APM::IgnoreGroup);
......@@ -261,13 +264,14 @@ void initPakabeiOperations(CommandLineParser *parser)
sysupgrade.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation upgrade(APM::UpgradeOperationType, APM::UpgradeOperation, "U", "upgrade", "Upgrade operation", true);
upgrade.addConnectionWithOption(APM::DownloadOnly);
upgrade.addConnectionWithOption(APM::Ignore);
upgrade.addConnectionWithOption(APM::IgnoreGroup);
upgrade.addConnectionWithOption(APM::Force);
upgrade.addConnectionWithOption(APM::InstallAsDeps);
upgrade.addConnectionWithOption(APM::InstallAsExplicit);
upgrade.addConnectionWithOption(APM::SkipDependencyCheck);
AkabeiOperation perform(APM::PerformOperationType, APM::Perform, "P", "perform", "Performs a series of installations and removals", true);
perform.addConnectionWithOption(APM::SkipDependencyCheck);
perform.addConnectionWithOption(APM::Force);
perform.addConnectionWithOption(APM::Force);
perform.addConnectionWithOption(APM::DatabaseOnly);
perform.addConnectionWithOption(APM::RemoveConfig);
perform.addConnectionWithOption(APM::Recursive);
......@@ -287,6 +291,7 @@ void initPakabeiOperations(CommandLineParser *parser)
parser->addOperation(groupsl);
parser->addOperation(infol);
parser->addOperation(searchl);
parser->addOperation(installed);
parser->addOperation(remove);
parser->addOperation(unneeded);
parser->addOperation(install);
......
......@@ -25,6 +25,21 @@ bool CommandLine::isSet(const QString& command)
return false;
}
/*
* Handle options with a short command composed of the same letter
* repeated twice
*/
if (command.size() == 2) {
actualCom = QString::fromAscii("-") + command[0];
if (m_commands.count(actualCom) == 2) {
m_commands.removeAll(actualCom);
return true;
}
return false;
}
if (command.size() == 1) {
actualCom = "-" + command;
} else {
......@@ -34,7 +49,7 @@ bool CommandLine::isSet(const QString& command)
m_index = m_commands.indexOf(actualCom);
if (m_index != -1) {
m_required.push_front(actualCom);
m_commands.removeAt(m_index);
return true;
}
......@@ -62,7 +77,7 @@ QStringList CommandLine::args()
foreach (const QString& c, m_commands) {
if (!c.startsWith("-")) {
result.append(c);
m_commands.removeOne(c);
}
}
......@@ -71,10 +86,8 @@ QStringList CommandLine::args()
void CommandLine::checkUnknownOptions()
{
foreach (const QString& c, m_commands) {
if (c.startsWith("-") && !m_required.contains(c)) {
throw UnknownOptionException(c);
}
if (!m_commands.isEmpty()) {
throw UnknownOptionException(m_commands.first());
}
}
......@@ -152,10 +165,11 @@ void PakabeiParser::parse()
* We look only for the acceptable operations
* all the others, if present, will be spotted later
*/
foreach (AkabeiOperation op, acceptedOperations.values(m_type)) {
foreach (AkabeiOperation op, acceptedOperations.values(m_type)) {
/*
* Saves up the commands for later inspection
*/
if (commandLine.isSet(op.commandShort()) || commandLine.isSet(op.commandLong())) {
m_operations.insert(op.name(), op);
found << op.commandShort();
......@@ -184,7 +198,7 @@ void PakabeiParser::parse()
QString commandName = (opt.commandShort().isEmpty()) ? opt.commandLong() : opt.commandShort();
/* Checks only the options that aren't already been recognized as operations (some of them share the same short command) */
if (!found.contains(commandName.toUtf8()) && commandLine.isSet(opt.commandShort()) || commandLine.isSet(opt.commandLong())) {
if ((!found.contains(commandName.toUtf8()) && commandLine.isSet(opt.commandShort())) || commandLine.isSet(opt.commandLong())) {
/* If at least one operation supports the option, it's fine */
bool supported = false;
......
......@@ -56,7 +56,6 @@ public:
private:
QStringList m_commands; /* the command line list */
QStringList m_required; /* stores what the parser required */
int m_index; /* current position in the list */
};
......
......@@ -47,15 +47,6 @@ CommandLineParser::CommandLineParser(int argc, char **argv, const KAboutData& da
m_argv.append(arg); /* everything else goes in the list as it is */
}
}
/*
* We immediately check if something is repeated twice
*/
foreach (const QString& c, m_argv) {
if (c.startsWith("-") && m_argv.count(c) > 1) {
throw CommandParsingException("Repetitions of options aren't allowed.");
}
}
}
void CommandLineUtils::printHelpMessage(QList<AkabeiOperation> m_acceptedOperations,
......
......@@ -37,7 +37,7 @@ class UnknownOptionException : public CommandParsingException
{
public:
UnknownOptionException(QString optName)
: CommandParsingException("unknown option \"" + optName + "\".")
: CommandParsingException("out-of-context option \"" + optName + "\".")
{}
};
......
......@@ -44,8 +44,7 @@ void QueryOperation::start()
switch (operation)
{
case APM::ShowInformation:
{
case APM::ShowInformation: {
if (m_options.contains(APM::QueryPackageFile)) {
Akabei::Package::List packages;
......@@ -61,16 +60,14 @@ void QueryOperation::start()
break;
}
case APM::ShowPackagesOfGroup:
{
case APM::ShowPackagesOfGroup: {
foreach (const QString& group, m_args) {
showGroup(group, localDatabase->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + group + "\""));
}
break;
}
case APM::ShowChangelog:
{
case APM::ShowChangelog: {
if (m_options.contains(APM::QueryPackageFile)) {
Akabei::Package::List packages;
......@@ -86,8 +83,7 @@ void QueryOperation::start()
}
case APM::ShowInstalledAsDeps:
case APM::ShowInstalledExplicitely:
{
case APM::ShowInstalledExplicitely: {
QString query = "SELECT * FROM packages WHERE";
if (!m_args.isEmpty()) {
query = query + " Name LIKE \"" + m_args.first() + "\" AND";
......@@ -104,8 +100,7 @@ void QueryOperation::start()
break;
}
case APM::CheckFiles:
{
case APM::CheckFiles: {
if (m_options.contains(APM::QueryPackageFile)) {
Akabei::Package::List packages;
......@@ -124,32 +119,32 @@ void QueryOperation::start()
* TODO: possibility of specifying more than one search argument, meaning the result should contain
* all the words specified?
*/
case APM::Search:
{
case APM::Search: {
showLocalQuery(localDatabase->searchPackages(m_args.first(), Akabei::SearchNameAndDescriptionLike));
break;
}
case APM::ShowOwner:
{
case APM::ShowOwner: {
showOwner(m_args);
break;
}
case APM::ShowNotRequired:
{
case APM::ShowNotRequired: {
showNotRequired();
break;
}
case APM::ShowUpgradeable:
{
case APM::ShowUpgradeable: {
showUpgradeable();
break;
}
default:
{
case APM::ShowInstalledPackages: {
showLocalQuery(localDatabase->packages());
break;
}
default: {
QTextStream err(stderr);
err << "akabei: Operation not supported yet" << endl;
QCoreApplication::instance()->quit();
......@@ -312,33 +307,6 @@ void QueryOperation::checkFiles(Akabei::Package::List packages)
nextOperation();
}
void QueryOperation::showLocalPackages(const QString &query)
{
QTextStream out(stdout);
Akabei::Package::List packages;
if (!query.isEmpty())
packages = Akabei::Backend::instance()->localDatabase()->searchPackages(query);
else
packages = Akabei::Backend::instance()->localDatabase()->packages();
foreach (Akabei::Package* pkg, packages) {
bool found = false;
foreach (Akabei::Database* db, Akabei::Backend::instance()->databases()) {
foreach (Akabei::Package* p, db->searchPackages(pkg->name())) {
if (p->name() == pkg->name()) {
found = true;
break;
}
}
if (found)
break;
}
if (!found)
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
}
out.flush();
nextOperation();
}
void QueryOperation::showOwner(const QStringList &queries)
{
QTextStream out(stdout);
......
......@@ -45,7 +45,6 @@ private:
void showChangelog(Akabei::Package::List packages);
void showInstalledAs(Akabei::Package::List);
void checkFiles(Akabei::Package::List);
void showLocalPackages(const QString &query);
void showOwner(const QStringList &queries);
void showLocalQuery(Akabei::Package::List);
void showNotRequired();
......
......@@ -11,7 +11,7 @@ _akabei()
{
COMPREPLY=()
current="${COMP_WORDS[COMP_CWORD]}"
commands="database changelog deps explicit check owner orphans new group info search remove clean install repo sync update upgrade newest perform get"
commands="database changelog deps explicit check owner orphans new group info search local remove clean install repo sync update upgrade newest perform get"
options="--file --asdeps --asexplicit --nodeps --force --downloadonly --needed --ignore --ignoregroup --dbonly --nosave --recursive --root --dbpath --cachedir --local"
# There is only one operation command per command line (and it doesn't have a fixed index in COMP_WORDS due to options)
......
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