% vim set ft=prolog :- use_module(library(files)). :- use_module(library(format)). :- use_module(library(lists)). :- use_module(bgp, [ create_firewall/0]). print_warnings([]). print_warnings([W|Ws]) :- format("Warning: ~s~n", [W]), print_warnings(Ws). print_warnings :- findall(W, bgp:warning(W), BgpWs), findall(W, firewall:warning(W), FwWs), append(BgpWs, FwWs, Ws), length(Ws, L), ( L > 0 -> format("Found ~w warning(s):~n", [L]), print_warnings(Ws) ; format("No warnings!~n", []) ). rm_rf(Parents) :- path_segments(Dir, Parents), directory_files(Dir, Files), rm_rf_files(Parents, Files). rm_rf_files(_, []). rm_rf_files(Parents, [D|Dir]) :- % format("rm_rf_files Parents=~w, D=~w, Dir=~w~n", [Parents,D,Dir]), append(Parents, [D], PathS), path_segments(Path, PathS), ( directory_exists(Path) -> % format("down ~s~n", [Path]), directory_files(Path, Files), % format("files ~w~n", [Files]), rm_rf_files(PathS, Files), format("rmdir ~s~n", [Path]), delete_directory(Path) ; format("rm ~s~n", [Path]), delete_file(Path) ), rm_rf_files(Parents, Dir). main :- bgp:create_firewall, print_warnings, path_segments("host_vars", Path), rm_rf(Path), firewall:write(Path).