-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathpopulate_registry.jl
98 lines (80 loc) · 3.25 KB
/
populate_registry.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# This file updates `docs/src/registry.md` (it does not build documentation in general)
module RegistryMD
using FileIO: FileIO, LOAD, SAVE, OSX, OS, DataFormat, @format_str, MimeWriter
using UUIDs
using Pkg
const ctx = Pkg.Types.Context()
try
ctx.registries
catch
error("this file must be run on Julia 1.6 or higher")
end
function pkg_url(uuid)
for reg in ctx.registries
entry = get(reg.pkgs, uuid, nothing)
entry === nothing && continue
info = Pkg.Registry.init_package_info!(entry)
base, ext = splitext(info.repo)
return ext == ".git" ? base : info.repo
end
end
library2string(x::Pair{<:Any,UUID}) = "[$(x.first)]($(pkg_url(x.second)))"
library2string(x::Module) = string(nameof(x))
extension2string(x) = join(map(string, x), ", ")
extension2string(x::AbstractString) = x
os2string(x::Vector) = isempty(x) ? "all platforms " : join(map(os2string, x), ", ")
os2string(os::Type{O}) where {O <: OS} = "$(O.name.name)"
magic2string(x::Function) = "has detection function"
magic2string(x::Tuple) = isempty(x) ? "only extension" : string(x)
magic2string(x::AbstractString) = '"' * escape_string(x, ['_']) * '"'
magic2string(x) = string(x)
function loadsave2string(load_save_libraries)
io = IOBuffer()
loader_str, saver_str = " ", " "
for (i, predicates) in enumerate(load_save_libraries)
library = popfirst!(predicates)
os, loadsave = FileIO.split_predicates(predicates)
if isempty(loadsave)
print(io, "loads and saves on all platforms with ", library2string(library), " ")
elseif (LOAD in loadsave)
print(io, "loads with ", library2string(library), " on ", os2string(os), " ")
elseif (SAVE in loadsave)
print(io, "saves with ", library2string(library), " on ", os2string(os), " ")
end
i < length(load_save_libraries) && print(io, '\n')
end
split(String(take!(io)), '\n')
end
fs = open(joinpath(pkgdir(FileIO), "docs", "src", "registry.md"), "w")
println(fs, "# Registry table")
println(fs)
println(fs, "The following formats are registered with FileIO:")
println(fs)
function add_format(::Type{DataFormat{Sym}}, magic, extension, io_libs...) where Sym
liblinks = loadsave2string(io_libs)
for (i, lib) in enumerate(liblinks)
if i == 1
println(fs, "| $(Sym) | $(extension2string(extension)) | $lib | $(magic2string(magic)) |")
else
println(fs, "| | | $lib | |")
end
end
end
function add_format(fmt::Type{DataFormat{sym}}, magic::Union{Tuple,AbstractVector,String}, extension) where sym
println(sym)
end
# for multiple magic bytes
function add_format(sym::Symbol, magics::Vector{Vector{UInt8}}, extension)
println(sym)
end
# For when "magic" is supplied as a function (see the HDF5 example in
# registry.jl)
function add_format(fmt::Type{DataFormat{sym}}, magic, extension) where sym
println(sym)
end
println(fs, """
| Format Name | extensions | IO library | detection or magic number |
| ----------- | ---------- | ---------- | ------------------------- |""")
include(joinpath(pkgdir(FileIO), "src", "registry.jl"))
close(fs)
end # module RegistryMD