print_all_profiles_db_size = { label = "Print all profiles database sizes" shortcut = "padb" description = "This print to the standard output stream the size of the database folder (/main/) for each profile" requires_profile = false parameters = { } expression = ` # This returns the size of a single file or directory. If it's a directory, it recurses into it to get the total size in bytes. subroutine(file_size(string pathname), ( #echo("file_info(); pathname=" . pathname); v.fileinfo = ''; get_file_info(pathname, 'v.fileinfo'); if (@'v.fileinfo'{'type'} eq 'directory') then ( #echo("Recursing " . pathname); # v.dircontents = ''; node dircontents = new_node(); get_directory_contents(pathname, dircontents); #echo("direcontents: " . node_as_string(dircontents)); int total_file_size = 0; node diritem; foreach diritem dircontents total_file_size += file_size(@diritem{"pathname"}); delete_node(dircontents); total_file_size; ); else @'v.fileinfo'{'size'}; )); # file_size() subroutine(format_bytes(int bytes), ( if (bytes > 1024) then )); # Get the profile node node n; foreach n 'profiles' ( string profile_name = node_name(n); node profile_node = 'profiles'{profile_name}; string profile_label = @'profiles'{profile_name}{'label'}; include "lib.database"; string database_directory = get_database_directory(profile_node); string total_size = format(file_size(database_directory), 'bandwidth'); v.extra = ""; if (length(total_size) == 3) then v.extra = " "; else if (length(total_size) == 6) then v.extra = " "; else if (length(total_size) == 7) then v.extra = " "; else if (length(total_size) == 8) then v.extra = " "; echo(v.extra . total_size . " -- " . profile_label); ); # foreach profile ` } # print_all_profiles_db_size