8#include "experimental/databasesanitizer.h"
11#include <KLocalizedString>
13#include <QCoreApplication>
14#include <QCommandLineOption>
15#include <QCommandLineParser>
16#include <QStandardPaths>
19#include <QElapsedTimer>
32 QStringList{QStringLiteral(
"i"), QStringLiteral(
"device-id")},
33 i18n(
"Filter by device id."
34 "\n0 (default) does not filter and everything is printed."
35 "\nPositive numbers are including filters printing only the mentioned device id."
36 "\nNegative numbers are excluding filters printing everything but the mentioned device id."
37 "\nMay be given multiple times."),
42 QStringList{QStringLiteral(
"m"), QStringLiteral(
"missing-only")},
43 i18n(
"List only inaccessible entries.\nOnly applies to \"%1\"", QStringLiteral(
"list"))
46 QStringList{QStringLiteral(
"u"), QStringLiteral(
"mounted-only")},
47 i18n(
"Act only on item on mounted devices")
50 QStringList{QStringLiteral(
"D"), QStringLiteral(
"dry-run")},
51 i18n(
"Print results of a cleaning operation, but do not change anything."
52 "\nOnly applies to \"%1\" command", QStringLiteral(
"clean"))
56const auto commands = std::vector<Command>{
58 QStringLiteral(
"list"),
59 i18n(
"List database contents. Use a regular expression as argument to filter output"),
61 QStringLiteral(
"pattern")
64 QStringLiteral(
"missing-only"),
65 QStringLiteral(
"device-id")
69 QStringLiteral(
"devices"),
84 QStringLiteral(
"clean"),
85 i18n(
"Remove stale database entries"),
87 QStringLiteral(
"pattern")
90 QStringLiteral(
"dry-run"),
91 QStringLiteral(
"device-id"),
92 QStringLiteral(
"mounted-only")
100 for (
const auto& c : commands) {
107 for (
const auto& c : commands) {
108 if (c.name == name) {
117 for (
const auto& c: commands) {
118 auto options = getOptions(c.name);
121 : QStringLiteral(
" [--%1]").arg(options.join(
QLatin1String(
"] [--")));
124 if (!c.args.isEmpty() ) {
125 argumentStr = QStringLiteral(
" [%1]").arg(c.args.join(QStringLiteral(
"] [")));
146 KAboutData aboutData(QStringLiteral(
"baloodb"),
147 i18n(
"Baloo Database Sanitizer"),
149 i18n(
"The Baloo Database Lister & Sanitizer"),
151 i18n(
"(c) 2018, Michael Heidelbach"));
152 aboutData.addAuthor(
i18n(
"Michael Heidelbach"),
i18n(
"Maintainer"), QStringLiteral(
"ottwolt@gmail.com"));
156 parser.addOptions(options);
157 parser.addPositionalArgument(QStringLiteral(
"command"),
158 i18n(
"The command to execute"),
161 parser.addPositionalArgument(QStringLiteral(
"pattern"),
162 i18nc(
"Command",
"A regular expression applied to the URL of database items"
164 ,
"baloodb list '^/media/videos/series'"
168 "===\nPlease note: This is an experimental tool. Command line switches or their meaning may change.\n===");
171 parser.addVersionOption();
180 auto args =
parser.positionalArguments();
181 auto command = args.
at(0);
184 if(!allowedCommands().contains(command)) {
185 qDebug() <<
"Unknown command" << command;
193 for (
const auto&
dev :
parser.values(QStringLiteral(
"device-id"))) {
197 parser.isSet(QStringLiteral(
"missing-only"))
198 ? DatabaseSanitizer::IgnoreAvailable
199 : DatabaseSanitizer::IgnoreNone
201 parser.isSet(QStringLiteral(
"mounted-only"))
202 ? DatabaseSanitizer::IgnoreUnmounted
203 : DatabaseSanitizer::IgnoreNone
212 auto db = globalDatabaseInstance();
218 if (!db->open(Database::ReadOnlyDatabase)) {
219 err <<
i18n(
"Baloo Index could not be opened") <<
endl;
223 err <<
i18n(
"Listing database contents...") <<
endl;
226 if (!db->open(Database::ReadOnlyDatabase)) {
227 err <<
i18n(
"Baloo Index could not be opened") <<
endl;
231 err <<
i18n(
"Listing database contents...") <<
endl;
235 auto dbMode = Database::ReadWriteDatabase;
237 err <<
i18n(
"Baloo Index could not be opened") <<
endl;
241 err <<
i18n(
"Removing stale database contents...") <<
endl;
263 err <<
i18n(
"Elapsed: %1 secs",
timer.nsecsElapsed() / 1000000000.0) <<
endl;
An Abstract class from which all other balooctl commands can inherit from.
Provide methods to show database problems and sanitize them.
static void setApplicationData(const KAboutData &aboutData)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
bool isEmpty() const const
bool isEmpty() const const
QTextStream & endl(QTextStream &stream)