mirror of
https://gitea.home.endeavr.de/Marcel/Tarstats-pp.git
synced 2025-12-10 00:39:01 +01:00
this added json output to stdout, to file and global json stats to file. tarstats is feature complete.
This commit is contained in:
41
main.cpp
41
main.cpp
@@ -128,11 +128,24 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
gzclose(gzIn);
|
||||
global_sizeofallfiles += std::filesystem::file_size(archiveName);
|
||||
tar::consolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems);
|
||||
|
||||
if(toJSON){
|
||||
if(!toFile) {
|
||||
tar::jsonconsolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName, "gzarchive");
|
||||
}
|
||||
if(toFile) {
|
||||
tar::jsonfilestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName, "gzarchive");
|
||||
}
|
||||
}
|
||||
if(!toJSON) {
|
||||
if(toFile)
|
||||
tar::txtfilestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName);
|
||||
if(!toFile)
|
||||
tar::consolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,16 +190,32 @@ int main(int argc, char** argv) {
|
||||
file.close();
|
||||
global_sizeofallfiles += std::filesystem::file_size(archiveName);
|
||||
|
||||
std::cout << toJSON << '\n';
|
||||
tar::consolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems);
|
||||
if(toJSON){
|
||||
if(!toFile) {
|
||||
tar::jsonconsolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName, "archive");
|
||||
}
|
||||
if(toFile) {
|
||||
tar::jsonfilestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName, "archive");
|
||||
}
|
||||
}
|
||||
if(!toJSON) {
|
||||
if(toFile)
|
||||
tar::txtfilestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems, archiveName);
|
||||
if(!toFile)
|
||||
tar::consolestats(typecount, std::filesystem::file_size(archiveName),
|
||||
sizeof_allitems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tar::consoleglobalstats(globaltypecount, global_sizeofallfiles, global_sizeofallitems, archiveFilename);
|
||||
if(toFile && toJSON)
|
||||
tar::jsonglobalfile(globaltypecount, global_sizeofallfiles,
|
||||
global_sizeofallitems, archiveFilename.size());
|
||||
|
||||
tar::consoleglobalstats(globaltypecount, global_sizeofallfiles,
|
||||
global_sizeofallitems, archiveFilename.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
39
tarfunc.cpp
39
tarfunc.cpp
@@ -87,9 +87,9 @@ void tar::consolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t t
|
||||
}
|
||||
|
||||
void tar::consoleglobalstats (std::map<std::string, uintmax_t> &typecount, uintmax_t filesize,
|
||||
uintmax_t itemsize, std::vector<std::string> &files) {
|
||||
uintmax_t itemsize, size_t fileamount) {
|
||||
std::cout << "GLOBAL STATS" << '\n';
|
||||
std::cout << "File amount: " << files.size() << '\n';
|
||||
std::cout << "File amount: " << fileamount << '\n';
|
||||
std::cout << "Size of all archives: " << filesize << " Bytes" << '\n';
|
||||
std::cout << "Size of all items: " << itemsize << " Bytes" << '\n';
|
||||
for (auto &i : typecount) {
|
||||
@@ -98,6 +98,41 @@ void tar::consoleglobalstats (std::map<std::string, uintmax_t> &typecount, uintm
|
||||
std::cout << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonconsolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type) {
|
||||
std::cout << "{\"type\": \"" << type << "\", \"name\": \"" << filename << "\", \"size\": " << tarfilesize
|
||||
<< ", \"itemsize\": " << sizeofall << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": " << typecount[tarconstant::typeSym]
|
||||
<< ", \"hardlinks\": " << typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonfilestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type) {
|
||||
std::string jsnname = filename + ".json";
|
||||
std::ofstream jsonfile(jsnname);
|
||||
jsonfile << "{\"type\": \"" << type << "\", \"name\": \"" << filename << "\", \"size\": " << tarfilesize
|
||||
<< ", \"itemsize\": " << sizeofall << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": " << typecount[tarconstant::typeSym]
|
||||
<< ", \"hardlinks\": " << typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n';
|
||||
jsonfile.close();
|
||||
std::cout << "Stats written to " << jsnname << '\n' << '\n';
|
||||
}
|
||||
|
||||
void tar::jsonglobalfile (std::map<std::string, uintmax_t> &typecount, uintmax_t itemsize,
|
||||
uintmax_t filesize, size_t fileamount) {
|
||||
std::ofstream jsonfile("global.json");
|
||||
jsonfile << "{\"itemamount\": " << fileamount << ", \"itemsize\": " << itemsize << ", \"filesize\": "
|
||||
<< filesize << ", \"files\": " << typecount[tarconstant::typeFile]
|
||||
<< ", \"dir\": " << typecount[tarconstant::typeDir] << ", \"symlinks\": "
|
||||
<< typecount[tarconstant::typeSym] << ", \"hardlinks\": "
|
||||
<< typecount[tarconstant::typeHard] << ", \"other\": "
|
||||
<< typecount[tarconstant::typeOther] << "}" << '\n';
|
||||
jsonfile.close();
|
||||
std::cout << "Global stats written to global.json" << '\n' << '\n';
|
||||
}
|
||||
|
||||
// writes default console output to txt file
|
||||
void tar::txtfilestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string archiveName) {
|
||||
|
||||
12
tarfunc.h
12
tarfunc.h
@@ -33,8 +33,16 @@ namespace tar {
|
||||
|
||||
// to write global stats to stdout
|
||||
void consoleglobalstats (std::map<std::string, uintmax_t> &typecount, uintmax_t itemfilesize,
|
||||
uintmax_t szfiles, std::vector<std::string> &files);
|
||||
|
||||
uintmax_t szfiles, size_t fileamount);
|
||||
// to write JSON stats of a file to stdout
|
||||
void jsonconsolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type);
|
||||
// to write JSON stats to file
|
||||
void jsonfilestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string &filename, std::string type);
|
||||
// to write global stats to JSON file
|
||||
void jsonglobalfile (std::map<std::string, uintmax_t> &typecount, uintmax_t itemsize,
|
||||
uintmax_t filesize, size_t fileamount);
|
||||
// to write default console output to txt file
|
||||
void txtfilestats(std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall,
|
||||
std::string archiveName);
|
||||
|
||||
Reference in New Issue
Block a user