Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: distfiles_mirrors/, /, experimental_mirrors/, releases_mirrors/, rsync_mirrors/
Date: Tue, 28 Apr 2020 17:27:46
Message-Id: 1588094850.cc533641381eda01900675f3b265d939b44ba2ea.robbat2@gentoo
1 commit: cc533641381eda01900675f3b265d939b44ba2ea
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Tue Apr 28 17:27:30 2020 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 28 17:27:30 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=cc533641
7
8 refactor mirror list generation
9
10 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
11
12 distfiles_mirrors/get-mirror-list-distfiles.rb | 18 ----------------
13 .../get-mirror-list-experimental.rb | 18 ----------------
14 get-mirrors-from-distfiles-xml.rb | 24 ++++++++++++++++++++++
15 get-mirrors-from-rsync-xml.rb | 24 ++++++++++++++++++++++
16 mirmon-distfiles.sh | 2 +-
17 mirmon-experimental.sh | 2 +-
18 mirmon-releases.sh | 2 +-
19 mirmon-rsync.sh | 2 +-
20 releases_mirrors/get-mirror-list-releases.rb | 18 ----------------
21 rsync_mirrors/get-mirror-list-rsync.rb | 18 ----------------
22 10 files changed, 52 insertions(+), 76 deletions(-)
23
24 diff --git a/distfiles_mirrors/get-mirror-list-distfiles.rb b/distfiles_mirrors/get-mirror-list-distfiles.rb
25 deleted file mode 100755
26 index 0794df3..0000000
27 --- a/distfiles_mirrors/get-mirror-list-distfiles.rb
28 +++ /dev/null
29 @@ -1,18 +0,0 @@
30 -#!/usr/bin/ruby
31 -
32 -MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
33 -
34 -%w[ rexml/document open-uri ].each {|lib| require lib }
35 -
36 -m = URI.parse(MIRROR_DATA).read
37 -x = REXML::Document.new(m)
38 -
39 -REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
40 - country = el.attributes['country']
41 -
42 - el.each_element('mirror/uri/') do |mirror|
43 - puts "#{country.downcase} #{mirror[0].to_s}"
44 - end
45 -
46 -}
47 -
48
49 diff --git a/experimental_mirrors/get-mirror-list-experimental.rb b/experimental_mirrors/get-mirror-list-experimental.rb
50 deleted file mode 100755
51 index 0794df3..0000000
52 --- a/experimental_mirrors/get-mirror-list-experimental.rb
53 +++ /dev/null
54 @@ -1,18 +0,0 @@
55 -#!/usr/bin/ruby
56 -
57 -MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
58 -
59 -%w[ rexml/document open-uri ].each {|lib| require lib }
60 -
61 -m = URI.parse(MIRROR_DATA).read
62 -x = REXML::Document.new(m)
63 -
64 -REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
65 - country = el.attributes['country']
66 -
67 - el.each_element('mirror/uri/') do |mirror|
68 - puts "#{country.downcase} #{mirror[0].to_s}"
69 - end
70 -
71 -}
72 -
73
74 diff --git a/get-mirrors-from-distfiles-xml.rb b/get-mirrors-from-distfiles-xml.rb
75 new file mode 100755
76 index 0000000..02b9418
77 --- /dev/null
78 +++ b/get-mirrors-from-distfiles-xml.rb
79 @@ -0,0 +1,24 @@
80 +#!/usr/bin/ruby
81 +require 'rexml/document'
82 +require 'open-uri'
83 +
84 +MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
85 +
86 +m = URI.parse(MIRROR_DATA).read
87 +x = REXML::Document.new(m)
88 +
89 +def normalize_mirror(xml_elem)
90 + return xml_elem.texts().join(' ').sub(/\/+$/, '') + '/'
91 +end
92 +
93 +def select_mirror(xml_elem)
94 + 1
95 +end
96 +
97 +REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
98 + country = el.attributes['country']
99 +
100 + el.each_element('mirror/uri/') do |uri_elem|
101 + puts "#{country.downcase} #{normalize_mirror(uri_elem)}" if select_mirror(uri_elem)
102 + end
103 +}
104
105 diff --git a/get-mirrors-from-rsync-xml.rb b/get-mirrors-from-rsync-xml.rb
106 new file mode 100755
107 index 0000000..100dffc
108 --- /dev/null
109 +++ b/get-mirrors-from-rsync-xml.rb
110 @@ -0,0 +1,24 @@
111 +#!/usr/bin/ruby
112 +require 'rexml/document'
113 +require 'open-uri'
114 +
115 +MIRROR_DATA="https://api.gentoo.org/mirrors/rsync.xml"
116 +
117 +m = URI.parse(MIRROR_DATA).read
118 +x = REXML::Document.new(m)
119 +
120 +def normalize_mirror(xml_elem)
121 + return xml_elem.texts().join(' ').sub(/\/+$/, '') + '/'
122 +end
123 +
124 +def select_mirror(xml_elem)
125 + xml_elem.texts().join(' ') =~ /rsync\d+\./
126 +end
127 +
128 +REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
129 + country = el.attributes['country']
130 +
131 + el.each_element('mirror/uri/') do |uri_elem|
132 + puts "#{country.downcase} #{normalize_mirror(uri_elem)}" if select_mirror(uri_elem)
133 + end
134 +}
135
136 diff --git a/mirmon-distfiles.sh b/mirmon-distfiles.sh
137 index 3e14e87..fedefdc 100755
138 --- a/mirmon-distfiles.sh
139 +++ b/mirmon-distfiles.sh
140 @@ -3,7 +3,7 @@
141 cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors
142 # Grab mirrors from the web
143 [[ -d ./var ]] || mkdir ./var
144 -./get-mirror-list-distfiles.rb > ./var/g.mirrors
145 +../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
146 # fatal if the state file is NOT present.
147 [[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
148 # run mirmon
149
150 diff --git a/mirmon-experimental.sh b/mirmon-experimental.sh
151 index f76a3d3..fae7df6 100755
152 --- a/mirmon-experimental.sh
153 +++ b/mirmon-experimental.sh
154 @@ -3,7 +3,7 @@
155 cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/experimental_mirrors
156 # Grab mirrors from the web
157 [[ -d ./var ]] || mkdir ./var
158 -./get-mirror-list-experimental.rb > ./var/g.mirrors
159 +../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
160 # fatal if the state file is NOT present.
161 [[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
162 # run mirmon
163
164 diff --git a/mirmon-releases.sh b/mirmon-releases.sh
165 index a6bf5fd..6790756 100755
166 --- a/mirmon-releases.sh
167 +++ b/mirmon-releases.sh
168 @@ -3,7 +3,7 @@
169 cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/releases_mirrors
170 # Grab mirrors from the web
171 [[ -d ./var ]] || mkdir ./var
172 -./get-mirror-list-releases.rb > ./var/g.mirrors
173 +../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
174 # fatal if the state file is NOT present.
175 [[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
176 # run mirmon
177
178 diff --git a/mirmon-rsync.sh b/mirmon-rsync.sh
179 index 900832d..93f76b2 100755
180 --- a/mirmon-rsync.sh
181 +++ b/mirmon-rsync.sh
182 @@ -12,7 +12,7 @@ swan
183 cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors
184 # Grab mirrors from the web
185 [[ -d ./var ]] || mkdir ./var
186 -./get-mirror-list-rsync.rb > ./var/g.mirrors
187 +../get-mirrors-from-rsync-xml.rb > ./var/g.mirrors
188 # infra mirrors, "manually added" to list to check
189 for i in ${INFRA}; do
190 echo "gentoo rsync://$i.gentoo.org" >> ./var/g.mirrors
191
192 diff --git a/releases_mirrors/get-mirror-list-releases.rb b/releases_mirrors/get-mirror-list-releases.rb
193 deleted file mode 100755
194 index 0794df3..0000000
195 --- a/releases_mirrors/get-mirror-list-releases.rb
196 +++ /dev/null
197 @@ -1,18 +0,0 @@
198 -#!/usr/bin/ruby
199 -
200 -MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
201 -
202 -%w[ rexml/document open-uri ].each {|lib| require lib }
203 -
204 -m = URI.parse(MIRROR_DATA).read
205 -x = REXML::Document.new(m)
206 -
207 -REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
208 - country = el.attributes['country']
209 -
210 - el.each_element('mirror/uri/') do |mirror|
211 - puts "#{country.downcase} #{mirror[0].to_s}"
212 - end
213 -
214 -}
215 -
216
217 diff --git a/rsync_mirrors/get-mirror-list-rsync.rb b/rsync_mirrors/get-mirror-list-rsync.rb
218 deleted file mode 100755
219 index 252bfd2..0000000
220 --- a/rsync_mirrors/get-mirror-list-rsync.rb
221 +++ /dev/null
222 @@ -1,18 +0,0 @@
223 -#!/usr/bin/ruby
224 -
225 -MIRROR_DATA="https://api.gentoo.org/mirrors/rsync.xml"
226 -
227 -%w[ rexml/document open-uri ].each {|lib| require lib }
228 -
229 -m = URI.parse(MIRROR_DATA).read
230 -x = REXML::Document.new(m)
231 -
232 -REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
233 - country = el.attributes['country']
234 -
235 - el.each_element('mirror/uri/') do |mirror|
236 - puts "#{country.downcase} #{mirror[0].to_s}" if mirror[0].to_s =~ /rsync\d+/
237 - end
238 -
239 -}
240 -