[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [baloo] src/tools/balooctl: Balooctl: Move 'status' command to its own class
From: Vishesh Handa <me () vhanda ! in>
Date: 2015-10-14 23:09:00
Message-ID: E1ZmVAK-0004OD-MZ () scm ! kde ! org
[Download RAW message or body]
Git commit 0094368bb1c5a791c794687da69da18584ae0b03 by Vishesh Handa.
Committed on 14/10/2015 at 23:07.
Pushed by vhanda into branch 'master'.
Balooctl: Move 'status' command to its own class
This cleans up the code a little, and makes it easier for us to make the
status command far more powerful in the feature. Specially when we want
it to be async.
M +1 -0 src/tools/balooctl/CMakeLists.txt
M +3 -88 src/tools/balooctl/main.cpp
A +138 -0 src/tools/balooctl/statuscommand.cpp [License: LGPL (v2.1+)]
A +38 -0 src/tools/balooctl/statuscommand.h [License: LGPL (v2.1+)]
http://commits.kde.org/baloo/0094368bb1c5a791c794687da69da18584ae0b03
diff --git a/src/tools/balooctl/CMakeLists.txt b/src/tools/balooctl/CMakeLists.txt
index b29eb4c..8c51aed 100644
--- a/src/tools/balooctl/CMakeLists.txt
+++ b/src/tools/balooctl/CMakeLists.txt
@@ -5,6 +5,7 @@ set(SRCS
indexer.cpp
command.cpp
configcommand.cpp
+ statuscommand.cpp
monitorcommand.cpp
${CMAKE_SOURCE_DIR}/src/file/extractor/result.cpp
)
diff --git a/src/tools/balooctl/main.cpp b/src/tools/balooctl/main.cpp
index 6f7444d..a195b07 100644
--- a/src/tools/balooctl/main.cpp
+++ b/src/tools/balooctl/main.cpp
@@ -52,6 +52,7 @@
#include "maininterface.h"
#include "indexerstate.h"
#include "configcommand.h"
+#include "statuscommand.h"
using namespace Baloo;
@@ -111,94 +112,8 @@ int main(int argc, char* argv[])
}
if (command == QLatin1String("status")) {
-
- IndexerConfig cfg;
- if (!cfg.fileIndexingEnabled()) {
- out << i18n("Baloo is currently disabled. To enable, please run \
\"balooctl enable\"") << endl;
- return 1;
- }
-
- Database *db = globalDatabaseInstance();
- if (!db->open(Database::OpenDatabase)) {
- out << "Baloo Index could not be opened\n";
- return 1;
- }
-
- Transaction tr(db, Transaction::ReadOnly);
-
- if (parser.positionalArguments().length() == 1) {
-
- bool running = mainInterface.isValid();
-
- if (running) {
- out << "Baloo File Indexer is running\n";
- out << "Indexer state: " << stateString(schedulerinterface.state()) \
<< endl;
- }
- else {
- out << "Baloo File Indexer is NOT running\n";
- }
-
- uint phaseOne = tr.phaseOneSize();
- uint total = tr.size();
-
- out << "Indexed " << total - phaseOne << " / " << total << " files\n";
-
- const QString path = fileIndexDbPath();
-
- QFileInfo indexInfo(path + QLatin1String("/index"));
- quint32 size = indexInfo.size();
- KFormat format(QLocale::system());
- if (size) {
- out << "Current size of index is " << format.formatByteSize(size, 2) \
<< endl;
- } else {
- out << "Index does not exist yet\n";
- }
- } else {
- FileIndexerConfig m_config;
-
- for (int i = 1; i < parser.positionalArguments().length(); ++i) {
- QString url = \
QFileInfo(parser.positionalArguments().at(i)).absoluteFilePath();
- quint64 id = filePathToId(QFile::encodeName(url));
-
- out << "File: " << url << endl;
-
- out << "Basic indexing: ";
- if (tr.hasDocument(id)) {
- out << "done\n";
- } else if (m_config.shouldBeIndexed(url)) {
- out << "scheduled\n";
- return 0;
- } else {
- out << "disbabled\n";
- return 0;
- }
-
- out << "Content indexing: ";
- if (tr.inPhaseOne(id)) {
- out << "scheduled\n";
- } else if (!tr.documentData(id).isEmpty()) {
- out << "done\n";
- } else if (tr.hasFailed(id)) {
- out << "failed\n";
- } else {
- out << "disabled\n";
- }
- }
- }
-
- /*
- if (failed) {
- out << "Failed to index " << failed << " files\n";
- out << "File IDs: ";
- Xapian::MSetIterator iter = mset.begin();
- for (; iter != mset.end(); ++iter) {
- out << *iter << " ";
- }
- out << "\n";
- }
- */
-
- return 0;
+ StatusCommand command;
+ return command.exec(parser);
}
if (command == QLatin1String("enable") || command == QLatin1String("disable")) {
diff --git a/src/tools/balooctl/statuscommand.cpp \
b/src/tools/balooctl/statuscommand.cpp new file mode 100644
index 0000000..93c5b61
--- /dev/null
+++ b/src/tools/balooctl/statuscommand.cpp
@@ -0,0 +1,138 @@
+/*
+ * This file is part of the KDE Baloo project.
+ * Copyright (C) 2015 Vishesh Handa <vhanda@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "statuscommand.h"
+#include "indexerconfig.h"
+
+#include "global.h"
+#include "database.h"
+#include "transaction.h"
+#include "idutils.h"
+
+#include "schedulerinterface.h"
+#include "maininterface.h"
+#include "indexerstate.h"
+
+#include <KLocalizedString>
+#include <KFormat>
+
+using namespace Baloo;
+
+QString StatusCommand::command()
+{
+ return QStringLiteral("status");
+}
+
+QString StatusCommand::description()
+{
+ return i18n("Print the status of the Indexer");
+}
+
+int StatusCommand::exec(const QCommandLineParser& parser)
+{
+ QTextStream out(stdout);
+
+ IndexerConfig cfg;
+ if (!cfg.fileIndexingEnabled()) {
+ out << i18n("Baloo is currently disabled. To enable, please run \"balooctl \
enable\"") << endl; + return 1;
+ }
+
+ Database *db = globalDatabaseInstance();
+ if (!db->open(Database::OpenDatabase)) {
+ out << i18n("Baloo Index could not be opened") << endl;
+ return 1;
+ }
+
+ Transaction tr(db, Transaction::ReadOnly);
+
+ QStringList args = parser.positionalArguments();
+ args.pop_front();
+
+ if (args.isEmpty()) {
+ org::kde::baloo::main mainInterface(QStringLiteral("org.kde.baloo"),
+ QStringLiteral("/"),
+ QDBusConnection::sessionBus());
+
+ org::kde::baloo::scheduler \
schedulerinterface(QStringLiteral("org.kde.baloo"), + \
QStringLiteral("/scheduler"), + \
QDBusConnection::sessionBus()); +
+ bool running = mainInterface.isValid();
+
+ if (running) {
+ out << i18n("Baloo File Indexer is running") << endl;
+ out << i18n("Indexer state: %1", \
stateString(schedulerinterface.state())) << endl; + }
+ else {
+ out << i18n("Baloo File Indexer is not running") << endl;
+ }
+
+ uint phaseOne = tr.phaseOneSize();
+ uint total = tr.size();
+
+ out << i18n("Indexed %1 / %2 files", total - phaseOne, total) << endl;
+
+ const QString path = fileIndexDbPath();
+
+ QFileInfo indexInfo(path + QLatin1String("/index"));
+ quint32 size = indexInfo.size();
+ KFormat format(QLocale::system());
+ if (size) {
+ out << "Current size of index is " << format.formatByteSize(size, 2) << \
endl; + } else {
+ out << "Index does not exist yet\n";
+ }
+ } else {
+ IndexerConfig config;
+
+ for (const QString& arg : args) {
+ QString filePath = QFileInfo(arg).absoluteFilePath();
+ quint64 id = filePathToId(QFile::encodeName(filePath));
+
+ out << i18n("File: %1", filePath) << endl;
+
+ out << "Basic Indexing: ";
+ if (tr.hasDocument(id)) {
+ out << "Done\n";
+ } else if (config.shouldBeIndexed(filePath)) {
+ out << "Scheduled\n";
+ return 0;
+ } else {
+ // FIXME: Add why it is not being indexed!
+ out << "Disbabled\n";
+ return 0;
+ }
+
+ out << "Content Indexing: ";
+ if (tr.inPhaseOne(id)) {
+ out << "Scheduled\n";
+ } else if (!tr.documentData(id).isEmpty()) {
+ out << "Done\n";
+ } else if (tr.hasFailed(id)) {
+ out << "Failed\n";
+ } else {
+ out << "Disabled\n";
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/src/tools/balooctl/statuscommand.h b/src/tools/balooctl/statuscommand.h
new file mode 100644
index 0000000..2c888d7
--- /dev/null
+++ b/src/tools/balooctl/statuscommand.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the KDE Baloo project.
+ * Copyright (C) 2015 Vishesh Handa <vhanda@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef BALOO_STATUSCOMMAND_H
+#define BALOO_STATUSCOMMAND_H
+
+#include "command.h"
+
+namespace Baloo {
+
+class StatusCommand : public Command
+{
+public:
+ QString command() Q_DECL_OVERRIDE;
+ QString description() Q_DECL_OVERRIDE;
+
+ int exec(const QCommandLineParser& parser) Q_DECL_OVERRIDE;
+};
+}
+
+#endif // BALOO_STATUSCOMMAND_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic