Cleaned up sqlite file generation.
This commit is contained in:
1 parent
9e1f72df94
commit
8df3bf38cd
1 file changed
+22
-4
@@ -17,6 +17,7 @@
|
||||
#include "lib/utils/overloaded.h"
|
||||
|
||||
#include <Pcap++/PcapFileDevice.h>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/date_time/posix_time/conversion.hpp>
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
#include <boost/process.hpp>
|
||||
@@ -721,12 +722,29 @@ find_icebergs(std::string const &pcap) {
|
||||
|
||||
int to_sql(std::string const &pcap, std::string const &out_dir) {
|
||||
if (to_csv(pcap, out_dir) == 0) {
|
||||
auto drop_extensions = [](auto const &str) {
|
||||
size_t lastindex = str.find_last_of(".");
|
||||
return str.substr(0, lastindex);
|
||||
};
|
||||
|
||||
auto init_script = os::sparkd_wd() + "/data_files/spartan/md.sql";
|
||||
auto abs_out_dir = boost::filesystem::absolute(out_dir);
|
||||
std::cout << "Importing CSVs..." << init_script << std::endl;
|
||||
return boost::process::system("sqlite3 -echo md.sqlite",
|
||||
boost::process::std_in < init_script,
|
||||
boost::process::start_dir = abs_out_dir);
|
||||
auto db_file = drop_extensions(drop_extensions(pcap)) + ".sqlite";
|
||||
auto abs_out_path =
|
||||
abs_out_dir / boost::filesystem::path(db_file).filename();
|
||||
|
||||
std::cout << "Importing CSVs to " << abs_out_path << std::endl;
|
||||
auto result =
|
||||
boost::process::system(fmt::format("sqlite3 {}", abs_out_path),
|
||||
boost::process::std_in < init_script,
|
||||
boost::process::start_dir = abs_out_dir);
|
||||
|
||||
if (result == 0)
|
||||
for (auto f : boost::filesystem::directory_iterator(abs_out_dir))
|
||||
if (boost::algorithm::ends_with(f.path().string(), ".csv"))
|
||||
boost::filesystem::remove(f);
|
||||
|
||||
return result;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user