summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2020-04-28 10:27:30 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2020-04-28 10:27:30 -0700
commitcc533641381eda01900675f3b265d939b44ba2ea (patch)
tree69591a4679acd7e4e1fbc2a312ea9b07d598549b
parentprobe-mirmon: fix rsync case (diff)
downloadgentoo-mirrorstats-cc533641381eda01900675f3b265d939b44ba2ea.tar.gz
gentoo-mirrorstats-cc533641381eda01900675f3b265d939b44ba2ea.tar.bz2
gentoo-mirrorstats-cc533641381eda01900675f3b265d939b44ba2ea.zip
refactor mirror list generation
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rwxr-xr-xdistfiles_mirrors/get-mirror-list-distfiles.rb18
-rwxr-xr-xexperimental_mirrors/get-mirror-list-experimental.rb18
-rwxr-xr-xget-mirrors-from-distfiles-xml.rb24
-rwxr-xr-xget-mirrors-from-rsync-xml.rb24
-rwxr-xr-xmirmon-distfiles.sh2
-rwxr-xr-xmirmon-experimental.sh2
-rwxr-xr-xmirmon-releases.sh2
-rwxr-xr-xmirmon-rsync.sh2
-rwxr-xr-xreleases_mirrors/get-mirror-list-releases.rb18
-rwxr-xr-xrsync_mirrors/get-mirror-list-rsync.rb18
10 files changed, 52 insertions, 76 deletions
diff --git a/distfiles_mirrors/get-mirror-list-distfiles.rb b/distfiles_mirrors/get-mirror-list-distfiles.rb
deleted file mode 100755
index 0794df3..0000000
--- a/distfiles_mirrors/get-mirror-list-distfiles.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/ruby
-
-MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
-
-%w[ rexml/document open-uri ].each {|lib| require lib }
-
-m = URI.parse(MIRROR_DATA).read
-x = REXML::Document.new(m)
-
-REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
- country = el.attributes['country']
-
- el.each_element('mirror/uri/') do |mirror|
- puts "#{country.downcase} #{mirror[0].to_s}"
- end
-
-}
-
diff --git a/experimental_mirrors/get-mirror-list-experimental.rb b/experimental_mirrors/get-mirror-list-experimental.rb
deleted file mode 100755
index 0794df3..0000000
--- a/experimental_mirrors/get-mirror-list-experimental.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/ruby
-
-MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
-
-%w[ rexml/document open-uri ].each {|lib| require lib }
-
-m = URI.parse(MIRROR_DATA).read
-x = REXML::Document.new(m)
-
-REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
- country = el.attributes['country']
-
- el.each_element('mirror/uri/') do |mirror|
- puts "#{country.downcase} #{mirror[0].to_s}"
- end
-
-}
-
diff --git a/get-mirrors-from-distfiles-xml.rb b/get-mirrors-from-distfiles-xml.rb
new file mode 100755
index 0000000..02b9418
--- /dev/null
+++ b/get-mirrors-from-distfiles-xml.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/ruby
+require 'rexml/document'
+require 'open-uri'
+
+MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
+
+m = URI.parse(MIRROR_DATA).read
+x = REXML::Document.new(m)
+
+def normalize_mirror(xml_elem)
+ return xml_elem.texts().join(' ').sub(/\/+$/, '') + '/'
+end
+
+def select_mirror(xml_elem)
+ 1
+end
+
+REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
+ country = el.attributes['country']
+
+ el.each_element('mirror/uri/') do |uri_elem|
+ puts "#{country.downcase} #{normalize_mirror(uri_elem)}" if select_mirror(uri_elem)
+ end
+}
diff --git a/get-mirrors-from-rsync-xml.rb b/get-mirrors-from-rsync-xml.rb
new file mode 100755
index 0000000..100dffc
--- /dev/null
+++ b/get-mirrors-from-rsync-xml.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/ruby
+require 'rexml/document'
+require 'open-uri'
+
+MIRROR_DATA="https://api.gentoo.org/mirrors/rsync.xml"
+
+m = URI.parse(MIRROR_DATA).read
+x = REXML::Document.new(m)
+
+def normalize_mirror(xml_elem)
+ return xml_elem.texts().join(' ').sub(/\/+$/, '') + '/'
+end
+
+def select_mirror(xml_elem)
+ xml_elem.texts().join(' ') =~ /rsync\d+\./
+end
+
+REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
+ country = el.attributes['country']
+
+ el.each_element('mirror/uri/') do |uri_elem|
+ puts "#{country.downcase} #{normalize_mirror(uri_elem)}" if select_mirror(uri_elem)
+ end
+}
diff --git a/mirmon-distfiles.sh b/mirmon-distfiles.sh
index 3e14e87..fedefdc 100755
--- a/mirmon-distfiles.sh
+++ b/mirmon-distfiles.sh
@@ -3,7 +3,7 @@
cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors
# Grab mirrors from the web
[[ -d ./var ]] || mkdir ./var
-./get-mirror-list-distfiles.rb > ./var/g.mirrors
+../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
# fatal if the state file is NOT present.
[[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
# run mirmon
diff --git a/mirmon-experimental.sh b/mirmon-experimental.sh
index f76a3d3..fae7df6 100755
--- a/mirmon-experimental.sh
+++ b/mirmon-experimental.sh
@@ -3,7 +3,7 @@
cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/experimental_mirrors
# Grab mirrors from the web
[[ -d ./var ]] || mkdir ./var
-./get-mirror-list-experimental.rb > ./var/g.mirrors
+../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
# fatal if the state file is NOT present.
[[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
# run mirmon
diff --git a/mirmon-releases.sh b/mirmon-releases.sh
index a6bf5fd..6790756 100755
--- a/mirmon-releases.sh
+++ b/mirmon-releases.sh
@@ -3,7 +3,7 @@
cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/releases_mirrors
# Grab mirrors from the web
[[ -d ./var ]] || mkdir ./var
-./get-mirror-list-releases.rb > ./var/g.mirrors
+../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors
# fatal if the state file is NOT present.
[[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state
# run mirmon
diff --git a/mirmon-rsync.sh b/mirmon-rsync.sh
index 900832d..93f76b2 100755
--- a/mirmon-rsync.sh
+++ b/mirmon-rsync.sh
@@ -12,7 +12,7 @@ swan
cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors
# Grab mirrors from the web
[[ -d ./var ]] || mkdir ./var
-./get-mirror-list-rsync.rb > ./var/g.mirrors
+../get-mirrors-from-rsync-xml.rb > ./var/g.mirrors
# infra mirrors, "manually added" to list to check
for i in ${INFRA}; do
echo "gentoo rsync://$i.gentoo.org" >> ./var/g.mirrors
diff --git a/releases_mirrors/get-mirror-list-releases.rb b/releases_mirrors/get-mirror-list-releases.rb
deleted file mode 100755
index 0794df3..0000000
--- a/releases_mirrors/get-mirror-list-releases.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/ruby
-
-MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"
-
-%w[ rexml/document open-uri ].each {|lib| require lib }
-
-m = URI.parse(MIRROR_DATA).read
-x = REXML::Document.new(m)
-
-REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
- country = el.attributes['country']
-
- el.each_element('mirror/uri/') do |mirror|
- puts "#{country.downcase} #{mirror[0].to_s}"
- end
-
-}
-
diff --git a/rsync_mirrors/get-mirror-list-rsync.rb b/rsync_mirrors/get-mirror-list-rsync.rb
deleted file mode 100755
index 252bfd2..0000000
--- a/rsync_mirrors/get-mirror-list-rsync.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/ruby
-
-MIRROR_DATA="https://api.gentoo.org/mirrors/rsync.xml"
-
-%w[ rexml/document open-uri ].each {|lib| require lib }
-
-m = URI.parse(MIRROR_DATA).read
-x = REXML::Document.new(m)
-
-REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
- country = el.attributes['country']
-
- el.each_element('mirror/uri/') do |mirror|
- puts "#{country.downcase} #{mirror[0].to_s}" if mirror[0].to_s =~ /rsync\d+/
- end
-
-}
-