-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.jl
executable file
·84 lines (68 loc) · 2.06 KB
/
update.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
#!/usr/bin/env julia
module MirrorUpdater
### Blacklisted Packages. ###
const BLACKLIST = [
]
### Constants. ###
const METADATA = Pkg.dir("METADATA")
const ORG_NAME = "JuliaPackageMirrors"
const PACKAGES = readdir(METADATA)
const TOTAL = length(PACKAGES)
### Functions. ###
function rename_url(url)
url = replace(url, "git://", "https://")
url = replace(url, ".git", "")
end
function print_header(name, number, width)
println("[$(lpad(number, width)) / $(lpad(TOTAL, width))] $name")
println("="^Base.tty_size()[2])
end
function update(name)
dir = joinpath(METADATA, name)
if isdir(dir)
file = joinpath(dir, "url")
if isfile(file)
url = strip(readall(file))
isdir(name) || run(`git clone --mirror $(url) $(name)`)
cd(name) do
update_local(url)
update_mirror(name, rename_url(url))
end
end
end
end
function update_local(url)
try
info("fetching from origin: '$url'")
run(`git fetch -p origin`)
catch
warn("could not fetch from '$(url)'")
end
end
function update_mirror(name, url)
# Check if mirror exists already.
if !success(`git ls-remote [email protected]:$(ORG_NAME)/$(name).jl.git`)
info("creating new repo: '$name'")
run(`hub create $(ORG_NAME)/$(name).jl -d 'Julia package mirror.' -h $url`)
end
success(`git remote add $(ORG_NAME) [email protected]:$(ORG_NAME)/$(name).jl.git`)
# Update the mirrored repo.
info("updating mirror: '$name'")
success(`git push $(ORG_NAME) --mirror`)
end
### Main. ###
function main()
# Update METADATA repo first to find newly added packages.
Pkg.update()
info("updating Julia package mirrors...")
cd(joinpath(dirname(@__FILE__), "..")) do
width = length(digits(length(PACKAGES)))
for (number, name) in enumerate(PACKAGES)
name in BLACKLIST && (warn("skipping $name"); continue)
print_header(name, number, width)
update(name)
println()
end
end
end
end