Skip to content

Commit

Permalink
Merge pull request #190 from cserteGT3/cst-better-statusmsg
Browse files Browse the repository at this point in the history
Add nicer status messages when something printed meanwhile
  • Loading branch information
tlienart authored Jul 11, 2019
2 parents 7010217 + c8750f1 commit 9e49323
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
14 changes: 9 additions & 5 deletions src/manager/judoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function serve(; clear::Bool=true, verb::Bool=false, port::Int=8000, single::Boo
start = time()
sig = jd_fullpass(watched_files; clear=clear, verb=verb, prerender=prerender, isoptim=isoptim)
sig < 0 && return sig
verb && (print(rpad("\n✔ full pass...", 40)); time_it_took(start); println(""))
fmsg = rpad("✔ full pass...", 40)
verb && (println(""); print(fmsg); print_final(fmsg, start); println(""))

# start the continuous loop
if !single
Expand Down Expand Up @@ -179,24 +180,27 @@ function jd_loop(cycle_counter::Int, ::LiveServer.FileWatcher, watched_files::Na
cur_t = mtime(fpath)
cur_t <= t && continue
# if there was then the file has been modified and should be re-processed + copied
verb && print(rpad("→ file $(fpath[length(FOLDER_PATH[])+1:end]) was modified ", 30))
fmsg = rpad("→ file $(fpath[length(FOLDER_PATH[])+1:end]) was modified ", 30)
verb && print(fmsg)
dict[fpair] = cur_t
# if it's an infra_file
if haskey(watched_files[:infra], fpair)
#TODO: couldn't test this branch
verb && println("→ full pass...")
start = time()
jd_fullpass(watched_files; clear=false, verb=false, prerender=false)
verb && (print(rpad("\n✔ full pass...", 15)); time_it_took(start); println(""))
verb && (print_final(rpad("✔ full pass...", 15), start); println(""))
else
verb && print(rpad("→ updating... ", 15))
fmsg = fmsg * rpad("→ updating... ", 15)
verb && print("\r" * fmsg)
start = time()
# TODO, ideally these would only be read if they've changed. Not super important
# but just not necessary. (Fixing may be a bit of a pain though)
head = read(joinpath(PATHS[:src_html], "head.html"), String)
pg_foot = read(joinpath(PATHS[:src_html], "page_foot.html"), String)
foot = read(joinpath(PATHS[:src_html], "foot.html"), String)
process_file(case, fpair, head, pg_foot, foot, cur_t; clear=false, prerender=false)
verb && time_it_took(start)
verb && print_final(fmsg, start)
end
end
end
Expand Down
27 changes: 16 additions & 11 deletions src/manager/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,28 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false,
end
# re-do a (silent) full pass
start = time()
print("→ Full pass")
withpre = ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24))
fmsg = "\r→ Full pass"
print(fmsg)
withpre = fmsg * ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24))
print(withpre)
succ = (serve(single=true, prerender=prerender, nomess=true, isoptim=true) === nothing)
time_it_took(start)
print_final(withpre, start)

#
# Minification
#
if minify && succ
if JD_CAN_MINIFY
start = time()
print(rpad("→ Minifying *.[html|css] files...", 35))
mmsg = rpad("→ Minifying *.[html|css] files...", 35)
print(mmsg)
# copy the script to the current dir
cp(joinpath(dirname(pathof(JuDoc)), "scripts", "minify.py"), JD_PY_MIN_NAME; force=true)
# run it
succ = success(`$([e for e in split(PY)]) $JD_PY_MIN_NAME`)
# remove the script file
rm(JD_PY_MIN_NAME)
time_it_took(start)
print_final(mmsg, start)
else
@warn "I didn't find css_html_js_minify, you can install it via pip the output will "*
"not be minified."
Expand Down Expand Up @@ -82,12 +84,13 @@ function publish(; prerender::Bool=true, minify::Bool=true, nopass::Bool=false,
end
if succ
start = time()
print(rpad("→ Pushing updates with git...", 35))
pubmsg = rpad("→ Pushing updates with git...", 35)
print(pubmsg)
try
run(`git add -A `)
run(`git commit -m "jd-update" --quiet`)
run(`git push --quiet`)
time_it_took(start)
print_final(pubmsg, start)
catch e
println("✘ Could not push updates, verify your connection and try manually.\n")
@show e
Expand All @@ -109,14 +112,16 @@ function cleanpull()::Nothing
FOLDER_PATH[] = pwd()
set_paths!()
if isdir(PATHS[:pub])
print(rpad("→ Removing local output dir...", 35))
rmmsg = rpad("→ Removing local output dir...", 35)
print(rmmsg)
rm(PATHS[:pub], force=true, recursive=true)
println(" [done ✔ ]")
println("\r" * rmmsg * " [done ✔ ]")
end
try
print(rpad("→ Retrieving updates from the repository...", 35))
pmsg = rpad("→ Retrieving updates from the repository...", 35)
print(pmsg)
run(`git pull --quiet`)
println(" [done ✔ ]")
println("\r" * pmsg * " [done ✔ ]")
catch e
println("✘ Could not pull updates, verify your connection and try manually.\n")
@show e
Expand Down
15 changes: 12 additions & 3 deletions src/misc_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,22 @@ $(SIGNATURES)
Convenience function to display a time since `start`.
"""
function time_it_took(start::Float64)::Nothing
function time_it_took(start::Float64)
comp_time = time() - start
mess = comp_time > 60 ? "$(round(comp_time/60; digits=1))m" :
comp_time > 1 ? "$(round(comp_time; digits=1))s" :
"$(round(comp_time*1000; digits=1))ms"
println("[done $(lpad(mess, 6))]")
return nothing
return "[done $(lpad(mess, 6))]"
end

```
$(SIGNATURES)
Nicer printing of processes.
```
function print_final(startmsg::AbstractString, starttime::Float64)::Nothing
tit = time_it_took(starttime)
println("\r$startmsg$tit")
end


Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ end
f = joinpath(d, "a.txt")
open(f, "w") do outf
redirect_stdout(outf) do
J.time_it_took(start)
J.print_final("elapsing",start)
end
end
r = read(f, String)
Expand Down

0 comments on commit 9e49323

Please sign in to comment.