Changeset View
Changeset View
Standalone View
Standalone View
src/tools/experimental/baloodb/main.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 46 | QCommandLineOption{ | |||
---|---|---|---|---|---|
49 | "\n0 (default) does not filter and everything is printed." | 49 | "\n0 (default) does not filter and everything is printed." | ||
50 | "\nPositive numbers are including filters printing only the mentioned device id." | 50 | "\nPositive numbers are including filters printing only the mentioned device id." | ||
51 | "\nNegative numbers are excluding filters printing everything but the mentioned device id." | 51 | "\nNegative numbers are excluding filters printing everything but the mentioned device id." | ||
52 | "\nMay be given multiple times."), | 52 | "\nMay be given multiple times."), | ||
53 | i18n("integer"), | 53 | i18n("integer"), | ||
54 | 0 | 54 | 0 | ||
55 | }, | 55 | }, | ||
56 | QCommandLineOption{ | 56 | QCommandLineOption{ | ||
57 | QStringList{QStringLiteral("D"), QStringLiteral("dry-run")}, | | |||
58 | i18n("Print results of a prune operation, but do not change anything." | | |||
59 | "\nOnly applies to \"%1\" command", QStringLiteral("prune")) | | |||
60 | }, | | |||
61 | QCommandLineOption{ | | |||
62 | QStringList{QStringLiteral("m"), QStringLiteral("missing-only")}, | 57 | QStringList{QStringLiteral("m"), QStringLiteral("missing-only")}, | ||
63 | i18n("List only inaccessible entries.\nOnly applies to \"%1\"", QStringLiteral("list")) | 58 | i18n("List only inaccessible entries.\nOnly applies to \"%1\"", QStringLiteral("list")) | ||
64 | }, | 59 | }, | ||
65 | QCommandLineOption{ | 60 | QCommandLineOption{ | ||
66 | QStringList{QStringLiteral("u"), QStringLiteral("mounted-only")}, | 61 | QStringList{QStringLiteral("u"), QStringLiteral("mounted-only")}, | ||
67 | i18n("Act only on item on mounted devices") | 62 | i18n("Act only on item on mounted devices") | ||
63 | }, | ||||
64 | QCommandLineOption{ | ||||
65 | QStringList{QStringLiteral("D"), QStringLiteral("dry-run")}, | ||||
66 | i18n("Print results of a prune operation, but do not change anything." | ||||
67 | "\nOnly applies to \"%1\" command", QStringLiteral("prune")) | ||||
68 | } | 68 | } | ||
69 | }; | 69 | }; | ||
70 | 70 | | |||
71 | const auto commands = std::vector<Command>{ | 71 | const auto commands = std::vector<Command>{ | ||
72 | Command{ | 72 | Command{ | ||
73 | QStringLiteral("list"), | 73 | QStringLiteral("list"), | ||
74 | i18n("List database contents. Use a regular expression as argument to filter output"), | 74 | i18n("List database contents. Use a regular expression as argument to filter output"), | ||
75 | QStringList{ | 75 | QStringList{ | ||
76 | QStringLiteral("pattern") | 76 | QStringLiteral("pattern") | ||
77 | }, | 77 | }, | ||
78 | QStringList{ | 78 | QStringList{ | ||
79 | QStringLiteral("missing-only"), | 79 | QStringLiteral("missing-only"), | ||
80 | QStringLiteral("device-id") | 80 | QStringLiteral("device-id") | ||
81 | } | 81 | } | ||
82 | }, | 82 | }, | ||
83 | Command{ | ||||
84 | QStringLiteral("devices"), | ||||
85 | i18n("List devices"), | ||||
86 | QStringList{}, | ||||
87 | QStringList{QStringLiteral("missing-only")} | ||||
88 | }, | ||||
83 | /*TODO: | 89 | /*TODO: | ||
84 | Command{ | 90 | Command{ | ||
85 | QStringLiteral("check"), | 91 | QStringLiteral("check"), | ||
86 | i18n("Check database contents. " | 92 | i18n("Check database contents. " | ||
87 | "Beware this may take very long to execute"), | 93 | "Beware this may take very long to execute"), | ||
88 | QStringList{}, | 94 | QStringList{}, | ||
89 | QStringList{} | 95 | QStringList{} | ||
90 | }, | 96 | }, | ||
91 | */ | 97 | */ | ||
92 | /*TODO: | | |||
93 | Command{ | 98 | Command{ | ||
94 | QStringLiteral("prune"), | 99 | QStringLiteral("clean"), | ||
95 | i18n("Remove stale database entries"), | 100 | i18n("Remove stale database entries"), | ||
96 | QStringList{ | 101 | QStringList{ | ||
97 | QStringLiteral("pattern") | 102 | QStringLiteral("pattern") | ||
98 | }, | 103 | }, | ||
99 | QStringList{ | 104 | QStringList{ | ||
100 | QStringLiteral("dry-run"), | 105 | QStringLiteral("dry-run"), | ||
101 | QStringLiteral("device-id") | 106 | QStringLiteral("device-id"), | ||
107 | QStringLiteral("mounted-only") | ||||
102 | } | 108 | } | ||
103 | }, | | |||
104 | */ | | |||
105 | Command{ | | |||
106 | QStringLiteral("devices"), | | |||
107 | i18n("List devices"), | | |||
108 | QStringList{}, | | |||
109 | QStringList{QStringLiteral("missing-only"), QStringLiteral("mounted-only")} | | |||
110 | } | 109 | } | ||
111 | }; | 110 | }; | ||
bruns: remove empty line | |||||
112 | 111 | | |||
113 | const QStringList allowedCommands() | 112 | const QStringList allowedCommands() | ||
114 | { | 113 | { | ||
115 | QStringList names; | 114 | QStringList names; | ||
116 | for (const auto& c : commands) { | 115 | for (const auto& c : commands) { | ||
117 | names.append(c.name); | 116 | names.append(c.name); | ||
118 | } | 117 | } | ||
119 | return names; | 118 | return names; | ||
Show All 22 Lines | 132 | for (const auto& c: commands) { | |||
142 | } | 141 | } | ||
143 | 142 | | |||
144 | const QString commandStr = QStringLiteral("%1%2%3") | 143 | const QString commandStr = QStringLiteral("%1%2%3") | ||
145 | .arg(c.name) | 144 | .arg(c.name) | ||
146 | .arg(optionStr) | 145 | .arg(optionStr) | ||
147 | .arg(argumentStr); | 146 | .arg(argumentStr); | ||
148 | 147 | | |||
149 | const QString str = QStringLiteral("%1 %2") | 148 | const QString str = QStringLiteral("%1 %2") | ||
150 | .arg(commandStr, -48) | 149 | .arg(commandStr, -58) | ||
151 | .arg(c.description); | 150 | .arg(c.description); | ||
152 | 151 | | |||
153 | allowedcommands.append(str); | 152 | allowedcommands.append(str); | ||
154 | } | 153 | } | ||
155 | const QString allCommandsStr = allowedcommands.join(QStringLiteral("\n ")); | 154 | const QString allCommandsStr = allowedcommands.join(QStringLiteral("\n ")); | ||
156 | return i18n("\n\nCommands:\n %1", allCommandsStr); | 155 | return i18n("\n\nCommands:\n %1", allCommandsStr); | ||
157 | } | 156 | } | ||
158 | 157 | | |||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 241 | if (!db->open(Database::ReadOnlyDatabase)) { | |||
243 | err << i18n("Baloo Index could not be opened") << endl; | 242 | err << i18n("Baloo Index could not be opened") << endl; | ||
244 | return 1; | 243 | return 1; | ||
245 | } | 244 | } | ||
246 | DatabaseSanitizer san(db, Transaction::ReadOnly); | 245 | DatabaseSanitizer san(db, Transaction::ReadOnly); | ||
247 | err << i18n("Listing database contents...") << endl; | 246 | err << i18n("Listing database contents...") << endl; | ||
248 | san.printDevices(deviceIds, accessFilter); | 247 | san.printDevices(deviceIds, accessFilter); | ||
249 | 248 | | |||
250 | } else if (command == QStringLiteral("clean")) { | 249 | } else if (command == QStringLiteral("clean")) { | ||
251 | /* TODO: add prune command */ | 250 | auto dbMode = Database::ReadWriteDatabase; | ||
252 | parser.showHelp(1); | 251 | if (!db->open(dbMode)) { | ||
252 | err << i18n("Baloo Index could not be opened") << endl; | ||||
253 | return 1; | ||||
254 | } | ||||
255 | DatabaseSanitizer san(db, Transaction::ReadWrite); | ||||
256 | err << i18n("Removing stale database contents...") << endl; | ||||
257 | san.removeStaleEntries(deviceIds, accessFilter, parser.isSet(QStringLiteral("dry-run")), urlFilter); | ||||
253 | 258 | | |||
254 | } else if (command == QStringLiteral("check")) { | 259 | } else if (command == QStringLiteral("check")) { | ||
255 | parser.showHelp(1); | 260 | parser.showHelp(1); | ||
256 | /* TODO: After check methods are improved | 261 | /* TODO: After check methods are improved | ||
257 | Database *db = globalDatabaseInstance(); | 262 | Database *db = globalDatabaseInstance(); | ||
258 | if (!db->open(Database::ReadOnlyDatabase)) { | 263 | if (!db->open(Database::ReadOnlyDatabase)) { | ||
259 | err << i18n("Baloo Index could not be opened") << endl; | 264 | err << i18n("Baloo Index could not be opened") << endl; | ||
260 | return 1; | 265 | return 1; | ||
Show All 17 Lines |
remove empty line