Granular.jl

Julia package for granular dynamics simulation
git clone git://src.adamsgaard.dk/Granular.jl
Log | Files | Refs | README | LICENSE

commit 4d1b91ffd0efa214cf3f3507122d6a31a7c58c1b
parent 75a33e825a40f7c8727dd833b14b2a305b5eabe3
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Thu, 22 Jun 2017 20:23:14 -0400

loop status in function if requested

Diffstat:
Mseaice-status.sh | 11++++-------
Msrc/io.jl | 96++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
2 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/seaice-status.sh b/seaice-status.sh @@ -4,14 +4,11 @@ # simulations. You may want to add this to your shell's PATH variable. set -e -cmd='julia --color=yes -e "import SeaIce; SeaIce.status()"' +cmd_sing='julia --color=yes -e "import SeaIce; SeaIce.status()"' +cmd_loop='julia --color=yes -e "import SeaIce; SeaIce.status(loop=true, t_int=10)"' if [[ "$1" == "loop" ]]; then - while true; do - date - eval $cmd - sleep 10 - done + eval $cmd_loop else - eval $cmd + eval $cmd_sing fi diff --git a/src/io.jl b/src/io.jl @@ -117,11 +117,12 @@ export status Shows the status of all simulations with output files written under the specified `folder`, which is the current working directory by default. """ -function status(folder::String=".", colored_output::Bool=true, +function status(folder::String="."; + loop::Bool=false, + t_int::Int=10, + colored_output::Bool=true, write_header::Bool=true) - status_files = String[] - if colored_output id_color_complete = :green id_color_in_progress = :yellow @@ -136,51 +137,66 @@ function status(folder::String=".", colored_output::Bool=true, lastfile_color = :default end - for (root, dirs, files) in walkdir(folder, follow_symlinks=false) + repeat = true + while repeat + + status_files = String[] + println(Dates.format(round(DateTime(now()), Dates.Minute(15)), + Dates.RFC1123Format)) - for file in files - if contains(file, ".status.txt") - push!(status_files, joinpath(root, file)) + for (root, dirs, files) in walkdir(folder, follow_symlinks=false) + + for file in files + if contains(file, ".status.txt") + push!(status_files, joinpath(root, file)) + end end end - end - if length(status_files) > 0 - if write_header - println("--------------------------------------" * - "--------------------------------------") - print_with_color(:default, "simulation folder \t") - print_with_color(time_color, " time \t") - print_with_color(percentage_color, " completed ") - print_with_color(lastfile_color, "last file \n") - println("--------------------------------------" * - "--------------------------------------") - end + if length(status_files) > 0 + if write_header + println("--------------------------------------" * + "--------------------------------------") + print_with_color(:default, "simulation folder \t") + print_with_color(time_color, " time \t") + print_with_color(percentage_color, " completed ") + print_with_color(lastfile_color, "last file \n") + println("--------------------------------------" * + "--------------------------------------") + end - for file in status_files - data = readdlm(file) - id = replace(file, ".status.txt", "") - id = replace(id, "./", "") - id = replace(id, r".*/", "") - time_s = @sprintf "%6.2fs" data[1] - time_h = @sprintf "%5.1fh" data[1]/(60.*60.) - percentage = @sprintf "%3.0f%%" data[2] - lastfile = @sprintf "%5d" data[3] - if data[2] < 99. - print_with_color(id_color_in_progress, "$id \t") - else - print_with_color(id_color_complete, "$id \t") + for file in status_files + data = readdlm(file) + id = replace(file, ".status.txt", "") + id = replace(id, "./", "") + id = replace(id, r".*/", "") + time_s = @sprintf "%6.2fs" data[1] + time_h = @sprintf "%5.1fh" data[1]/(60.*60.) + percentage = @sprintf "%3.0f%%" data[2] + lastfile = @sprintf "%5d" data[3] + if data[2] < 99. + print_with_color(id_color_in_progress, "$id \t") + else + print_with_color(id_color_complete, "$id \t") + end + print_with_color(time_color, "$time_s ($time_h) \t") + print_with_color(percentage_color, "$percentage \t") + print_with_color(lastfile_color, "$lastfile \n") + end + if write_header + println("--------------------------------------" * + "--------------------------------------") end - print_with_color(time_color, "$time_s ($time_h) \t") - print_with_color(percentage_color, "$percentage \t") - print_with_color(lastfile_color, "$lastfile \n") + else + warn("no simulations found in $(pwd())/$folder") end - if write_header - println("--------------------------------------" * - "--------------------------------------") + + if loop && t_int > 0 + sleep(t_int) + end + if !loop + repeat = false end - else - warn("no simulations found in $(pwd())/$folder") end end