Skip to content

Commit

Permalink
Better show
Browse files Browse the repository at this point in the history
  • Loading branch information
josePereiro committed Jun 18, 2024
1 parent cf6e98c commit 6547af5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
23 changes: 22 additions & 1 deletion src/Base/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,25 @@ function _deserialize(path::AbstractString; onerr = rethrow)
@info("READ ERROR: '", path, "'")
return onerr(e)
end
end
end

function _quoted_join(col, sep)
strs = String[]
for el in col
push!(strs, string("\"", el, "\""))
end
return join(strs, sep)
end


function _canonical_bytes(bytes)
bytes < 1024 && return (bytes, "bytes")
bytes /= 1024
bytes < 1024 && return (bytes, "kilobytes")
bytes /= 1024
bytes < 1024 && return (bytes, "Megabytes")
bytes /= 1024
bytes < 1024 && return (bytes, "Gigabytes")
bytes /= 1024
return (bytes, "Tb")
end
54 changes: 44 additions & 10 deletions src/BlobBatchBase/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,58 @@ BlobBatch(B::Bloberia, group::AbstractString) = BlobBatch(B, group, uuid_int())
BlobBatch(B::Bloberia) = BlobBatch(B, BLOBBATCH_DEFAULT_FRAME_NAME, uuid_int())

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
function _bb_show_file_sortby(ph)
name = basename(ph)
name == "uuid.blobs.jls" && return "."
name == "meta.jls" && return ".."
return name
end

import Base.show
function Base.show(io::IO, bb::BlobBatch)
_ondemand_loaduuids!(bb)
print(io, "BlobBatch(", repr(bb.uuid), ") with ", length(bb.uuids), " blob(s)...")
isempty(bb.frames) && return

print(io, "\nLoaded frames: ")
for (frame, _bb_frame) in bb.frames
isempty(_bb_frame) && continue
kT_pairs = Set()
for (_, _b_frame) in _bb_frame
for (key, val) in _b_frame
push!(kT_pairs, string(key) => typeof(val))
if !isempty(bb.frames)
print(io, "\nRam frames: ")
for (frame, _bb_frame) in bb.frames
isempty(_bb_frame) && continue
kT_pairs = Set()
for (_, _b_frame) in _bb_frame
for (key, val) in _b_frame
push!(kT_pairs, string(key) => typeof(val))
end
end
print(io, "\n \"", frame, "\" ")
_kv_print_type(io, kT_pairs; _typeof = identity)
end
end

if isdir(bb)
_bb_filesize = 0.0
print(io, "\nDisk frames: ")
b_files = readdir(batchpath(bb); join = true)
sort!(b_files; by = _bb_show_file_sortby)
for path in b_files
endswith(path, ".frame.jls") || continue
_filesize = filesize(path)
val, unit = _canonical_bytes(_filesize)
print(io, "\n \"", basename(path), "\" ")
print(io, "[")
printstyled(io, string(round(val; digits = 3), " ", unit);
color = :blue
)
print(io, "]")
_bb_filesize += _filesize
end
print(io, "\n \"", frame, "\" ")
_kv_print_type(io, kT_pairs; _typeof = identity)
val, unit = _canonical_bytes(_bb_filesize)
print(io, "\ndisk usage: ")
printstyled(io, string(round(val; digits = 3), " ", unit);
color = :blue
)

end

end

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
Expand Down
15 changes: 15 additions & 0 deletions src/BlobBatchBase/filesys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ function dat_framepath(bb::BlobBatch, frame)
isempty(dir) && return ""
return _dat_framepath(dir, frame)
end

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
import Base.isdir
Base.isdir(bb::BlobBatch) = isdir(batchpath(bb))

import Base.filesize
function Base.filesize(bb::BlobBatch)
fsize = 0.0;
for fn in readdir(batchpath(bb); join = true)
isfile(fn) || continue
endswith(basename(fn), ".jls") || continue
fsize += filesize(fn)
end
return fsize
end
14 changes: 14 additions & 0 deletions src/BloberiaBase/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function Base.show(io::IO, B::Bloberia)
count = batchcount(B)
print(io, "Bloberia with ", count, " batch(es)")
print(io, "\nfilesys: ", B.root)
val, unit = _canonical_bytes(filesize(B))
print(io, "\ndisk usage: ", round(val; digits = 3), " ", unit)
else
print(io, "Bloberia: filesys not found...")
end
Expand Down Expand Up @@ -57,6 +59,18 @@ import Base.rm
Base.rm(B::Bloberia; force = true, recursive = true) =
_hasfilesys(B) && rm(B.root; force, recursive)

import Base.mkpath
Base.mkpath(B::Bloberia; kwargs...) = mkpath(B.root; kwargs...)

import Base.filesize
function Base.filesize(B::Bloberia)
fsize = 0.0;
foreach_batch(B) do bb
fsize += filesize(bb)
end
return fsize
end

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# Use, uuids
# function blobcount(B::Bloberia)
Expand Down

0 comments on commit 6547af5

Please sign in to comment.