Add db statistic output to CLI db-info command.

Closes #6920
This commit is contained in:
Geert Ijewski 2021-10-09 19:38:32 +02:00 committed by Jonathan White
parent 6c4a82bd51
commit d16fc2d62a
8 changed files with 294 additions and 126 deletions

View file

@ -18,7 +18,9 @@
#include "Info.h"
#include "Utils.h"
#include "core/DatabaseStats.h"
#include "core/Global.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include <QCommandLineParser>
@ -47,5 +49,25 @@ int Info::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
} else {
out << QObject::tr("Recycle bin is not enabled.") << endl;
}
DatabaseStats stats(database);
out << QObject::tr("Location") << ": " << database->filePath() << endl;
out << QObject::tr("Database created") << ": "
<< database->rootGroup()->timeInfo().creationTime().toString(Qt::DefaultLocaleShortDate) << endl;
out << QObject::tr("Last saved") << ": " << stats.modified.toString(Qt::DefaultLocaleShortDate) << endl;
out << QObject::tr("Unsaved changes") << ": " << (database->isModified() ? QObject::tr("yes") : QObject::tr("no"))
<< endl;
out << QObject::tr("Number of groups") << ": " << QString::number(stats.groupCount) << endl;
out << QObject::tr("Number of entries") << ": " << QString::number(stats.entryCount) << endl;
out << QObject::tr("Number of expired entries") << ": " << QString::number(stats.expiredEntries) << endl;
out << QObject::tr("Unique passwords") << ": " << QString::number(stats.uniquePasswords) << endl;
out << QObject::tr("Non-unique passwords") << ": " << QString::number(stats.reusedPasswords) << endl;
out << QObject::tr("Maximum password reuse") << ": " << QString::number(stats.maxPwdReuse()) << endl;
out << QObject::tr("Number of short passwords") << ": " << QString::number(stats.shortPasswords) << endl;
out << QObject::tr("Number of weak passwords") << ": " << QString::number(stats.weakPasswords) << endl;
out << QObject::tr("Entries excluded from reports") << ": " << QString::number(stats.excludedEntries) << endl;
out << QObject::tr("Average password length") << ": " << QObject::tr("%1 characters").arg(stats.averagePwdLength())
<< endl;
return EXIT_SUCCESS;
}