-
Notifications
You must be signed in to change notification settings - Fork 43
/
registration.jl
35 lines (27 loc) · 953 Bytes
/
registration.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
# This file is a part of DataDeps.jl. License is MIT.
const registry = Dict{String, AbstractDataDep}()
"""
register(datadep::AbstractDataDep)
Registers the given datadep to be globally available to the program.
this makes `datadep"Name"` work.
`register` should be run within this `__init__` of your module.
"""
function register(datadep::AbstractDataDep)
name = datadep.name
if haskey(registry, name)
@warn("Over-writing registration of the datadep", name)
end
if !is_valid_name(name)
throw(ArgumentError(name, " is not a valid name for a datadep. Valid names must be legal foldernames on Windows."))
end
registry[name] = datadep
end
"""
is_valid_name(name)
This checks if a datadep name is valid.
This basically means it must be a valid folder name on windows.
"""
function is_valid_name(name)
namechars = collect(name)
!any( namechars .∈ "\\/:*?<>|") && !any(iscntrl.(namechars))
end