1 #ifndef CASM_DB_Remove_impl
2 #define CASM_DB_Remove_impl
4 #include <boost/filesystem/fstream.hpp>
21 template <
typename _ConfigType>
26 template <
typename _ConfigType>
29 std::vector<std::string> fail;
30 for (
const auto &val : selection.
data()) {
31 if (!has_existing_data_or_files(val.first)) {
32 db_config<ConfigType>().erase(val.first);
34 log() <<
"skipping " << val.first <<
": has existing data or files"
36 fail.push_back(val.first);
44 log() <<
" See " << fs::path(m_report_dir) /
"remove_fail" << std::endl;
46 db_config<ConfigType>().commit();
50 template <
typename _ConfigType>
54 for (
const auto &val : selection.
data()) {
55 for (
auto it = db_props().find_via_to(val.first); it != db_props().end();
56 it = db_props().find_via_to(val.first)) {
59 auto it = db_props().find_via_origin(
61 if (it != db_props().end()) {
64 rm_files(val.first, dry_run);
76 template <
typename _ConfigType>
80 erase_data(selection, dry_run);
83 erase(selection, dry_run);
86 template <
typename _ConfigType>
88 std::string prefix{
"remove_"};
90 fs::ofstream file(fs::path(m_report_dir) / (prefix +
"_fail"));
91 for (
const auto &val : fail) {
92 file << val << std::endl;
99 template <
typename ConfigType>
103 template <
typename ConfigType>
106 "Remove enumerated configurations and calculation results: \n\n"
108 " 'casm remove --type " +
112 " - Configurations to be erased can be specified with the --names and \n"
113 " --selection options.\n"
114 " - Use without additional options to only remove enumerated "
116 " that do not have any associated files or data.\n"
117 " - Use --data (-d) to remove data only, not enumerated configurations. "
119 " - Use --force (-f) to remove data and enumerated configurations. \n"
120 " - Use --dry-run (-n) to do a \"dry-run\". \n\n"
122 " After removing a configuration it may be re-enumerated but will have "
124 " index because indices will not be repeated.\n\n";
129 template <
typename ConfigType>
140 std::stringstream msg;
141 msg <<
"Invalid Configuration name: " <<
name;
148 std::string report_dir =
149 (
primclex.dir().root_dir() /
"remove_report").
string();
157 }
else if (opt.
data()) {
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
const std::vector< std::string > & name_strs() const
static std::string desc()
Remove(const PrimClex &primclex, std::string report_dir)
static int run(const PrimClex &, const Completer::RmOption &opt)
Generic ConfigType-dependent part of Remove.
void erase(const DB::Selection< ConfigType > &selection, bool dry_run)
Erase Configurations that have no data.
void erase_data(const DB::Selection< ConfigType > &selection, bool dry_run)
Erase data and files (permanently), but not Configuration.
void _erase_report(const std::vector< std::string > &fail)
void erase_all(const DB::Selection< ConfigType > &selection, bool dry_run)
Removes Configurations and data and files (permanently)
RemoveT(const PrimClex &primclex, std::string report_dir)
PrimClex is the top-level data structure for a CASM project.
std::string create_report_dir(std::string report_dir)
Create a new report directory to avoid overwriting existing results.
std::string calc_properties_path(const ConfigType &config, std::string calctype="")
GenericDatumFormatter< std::string, DataObject > name()