rankmirror 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69987a6f2bf817b2ff3779548e775e3c86042b00
4
- data.tar.gz: fc92243a24cf327ada2a959163911ea6a968f8b2
3
+ metadata.gz: 4c0ef931391e3d8af93db3d5fb0a414ba38608c6
4
+ data.tar.gz: 81a3a3c891c9a191901e964994b9feee06c3b3c7
5
5
  SHA512:
6
- metadata.gz: 468c53d68cb63777996a305174670af8be0de74f155ac31330ed9389fa0349abf21a6bcb426b5eaac8524a0726b3b3d7c1a59b53654d6e0fb5d7a2872c5229de
7
- data.tar.gz: d71507f6738690b169adceb79e60d56570e6f717e97da0d6cec166d9c9547bdd75127aa71c236f77bf40ff9e762b3c2b3edfaa8fc1d2196978ad58fc20ab8efa
6
+ metadata.gz: 5fff68ae4d4124727c0fa0d4377171d57034328959e619e4c19c89c88ee79820dabd1818ed51e87235b1b72f858fa4acb93a8d05205b491219daa1ca6a3f464d
7
+ data.tar.gz: 4ec878e794686d8855b2da2ed24ea95de0373e69b976eeb4f8417143f28b1c51ddcc04196ec7f7f6afd9c7174df00debd5c0a529aaadf62a20a890efe479a8f3
data/Gemfile CHANGED
@@ -3,5 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in rankmirror.gemspec
4
4
  gemspec
5
5
  gem 'nokogiri', '>= 1.6.0'
6
- gem 'colorize', '>= 0.8.0'
7
6
  gem 'curb', '>= 0.9.0'
data/README.md CHANGED
@@ -10,12 +10,14 @@ RankMirror is a ruby implementation of `rankmirrors` in ArchLinux but for all mo
10
10
 
11
11
  $ rankmirror --help
12
12
 
13
- eg. `rankmirror -o opensuse --flavor tumbleweed --continent asia` will get you: the fastest Tumbleweed mirror located in Asia. Those 3 options
14
- are mandatory for openSUSE.
13
+ eg. `rankmirror -o opensuse --flavor tumbleweed --continent asia`, the fastest openSUSE Tumbleweed mirror in Asia.
14
+
15
+ `rankmirror -o fedora --flavor 25 --country cn`, the fastest Fedora 25 mirror in China.
16
+
17
+ `rankmirror -o epel --flavor 7 --country cn`, the fastest EPEL 7 mirror in China.
15
18
 
16
19
  `rankmirror -o packman -s` will get you: the fastest Packman mirror from the World. And save that to a packman.mirrorlist in your `~/.rankmirror`.
17
20
  Next time, just `rankmirror -l -o packman -s`, which is faster^2. Because most of the times, there're only a few mirrors that are fast to you.
18
- This technology applies to openSUSE too.
19
21
 
20
22
  ## License
21
23
 
data/TODO CHANGED
@@ -1,3 +1,2 @@
1
1
  * archlinux
2
- * fedora
3
2
  * ubuntu
@@ -4,9 +4,15 @@ $:.push(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
4
 
5
5
  require 'rankmirror'
6
6
  require 'optparse'
7
- require 'colorize'
8
7
 
9
8
  options = RankMirror::Options.new
9
+ options.local = false
10
+ options.os = "opensuse"
11
+ options.continent = "asia"
12
+ options.flavor = "leap4220"
13
+ options.quick = true
14
+ options.path = nil
15
+ options.file = "repomd.xml"
10
16
 
11
17
  parser = OptionParser.new do |opts|
12
18
  opts.banner = "Usage: rankmirror [options]"
@@ -19,21 +25,23 @@ parser = OptionParser.new do |opts|
19
25
  end
20
26
 
21
27
  opts.on("-o", "--os [Distribution]",
22
- "Check mirrors for this distro. Now supported: 'opensuse', 'packman'.") do |os|
28
+ "Check mirrors for this distro. Now supported: 'opensuse', 'packman', 'fedora', 'epel'.") do |os|
23
29
  case os
24
30
  when "opensuse"
25
31
  options.os = "opensuse"
26
- options.path = "tumbleweed/repo/oss/suse/repodata/"
32
+ options.path = "tumbleweed/repo/oss/suse/repodata/"
27
33
  when "packman"
28
34
  options.os = "packman"
29
35
  options.path = "openSUSE_Tumbleweed/Essentials/repodata/"
36
+ when "fedora"
37
+ options.os = "fedora"
38
+ when "epel"
39
+ options.os = "epel"
40
+ when nil
41
+ raise RankMirror::MandatoryOptionNotSpecified
30
42
  else
31
43
  raise RankMirror::DistributionNotImplemented
32
44
  end
33
-
34
- if options.os.nil?
35
- raise RankMirror::MandatoryOptionNotSpecified
36
- end
37
45
  end
38
46
 
39
47
  opts.on("--continent [Continent]", "Check mirrors on this continent. openSUSE ONLY.
@@ -41,15 +49,27 @@ parser = OptionParser.new do |opts|
41
49
  'southamerica', 'oceania'.") do |cont|
42
50
  unless options.os != "opensuse"
43
51
  options.continent = cont.downcase.delete("\s")
52
+ raise RankMirror::MandatoryOptionNotSpecified if options.continent.nil?
44
53
  else
45
- raise RankMirror::SuboptionNotSupported
54
+ raise RankMirror::DistributionNotImplemented
55
+ end
56
+ end
57
+
58
+ opts.on("--country [Country]", "Check mirrors in this country. Fedora/EPEL ONLY.") do |country|
59
+ case options.os
60
+ when "fedora","epel"
61
+ options.country = country.downcase
62
+ raise RankMirror::MandatoryOptionNotSpecified if options.country.nil?
63
+ else
64
+ raise RankMirror::DistributionNotImplemented
46
65
  end
47
66
  end
48
67
 
49
- opts.on("--flavor [Flavor]","Check mirrors for this flavor. openSUSE ONLY.
50
- Now supported: '4220', '4210', 'tumbleweed'.") do |flavor|
68
+ opts.on("--flavor [Flavor]","Check mirrors for this flavor.
69
+ Now supported: openSUSE: '4220', '4210', 'tumbleweed'; Fedora: 20-25 ; epel: 4-7.") do |flavor|
51
70
  case options.os
52
71
  when "opensuse","packman"
72
+ options.keys = ["name","continent","country","http","tumbleweed","leap4220","leap4210","leap4230"]
53
73
  case flavor
54
74
  when "4220"
55
75
  options.flavor = "leap4220"
@@ -57,15 +77,27 @@ parser = OptionParser.new do |opts|
57
77
  options.flavor = "leap4210"
58
78
  when "tumbleweed","tw"
59
79
  options.flavor = "tumbleweed"
80
+ when nil
81
+ raise RankMirror::MandatoryOptionNotSpecified
60
82
  else
61
83
  raise RankMirror::FlavorNotImplemented
62
84
  end
85
+ when "fedora"
86
+ options.flavor = "fedora" + flavor
87
+ options.path = "releases/" + flavor + "/Everything/x86_64/os/repodata/"
88
+ options.keys = ["name","country","http","fedora25","fedora24","fedora23","fedora22","fedora21","fedora20"]
89
+ raise RankMirror::MandatoryOptionNotSpecified if options.flavor.nil?
90
+ when "epel"
91
+ options.flavor = "epel" + flavor
92
+ options.path = flavor + "/x86_64/repodata/"
93
+ options.keys = ["name","country","http","epel7","epel6","epel5","epel4"]
94
+ raise RankMirror::MandatoryOptionNotSpecified if options.flavor.nil?
63
95
  else
64
96
  raise RankMirror::DistributionNotImplemented
65
97
  end
66
98
  end
67
99
 
68
- opts.on("-q", "--quick [1/0]", "Check mirrors quickly/slowly.
100
+ opts.on("-q", "--quick [1/0]", "Check mirrors quickly/slowly. openSUSE/Packman ONLY.
69
101
  The quick check will download a tiny file from the mirror, thus
70
102
  response quickly but the result will be less accurate. Default: 1") do |quick|
71
103
  unless quick.to_i > 0
@@ -122,6 +154,22 @@ when "packman"
122
154
  else
123
155
  local
124
156
  end
157
+ when "fedora"
158
+ local = RankMirror::LocalFedora.new(config.path,options).sort
159
+ mirrors = unless options.local
160
+ remote = RankMirror::RemoteFedora.new(options).fetch
161
+ remote.concat(local)
162
+ else
163
+ local
164
+ end
165
+ when "epel"
166
+ local = RankMirror::LocalEPEL.new(config.path,options).sort
167
+ mirrors = unless options.local
168
+ remote = RankMirror::RemoteFedora.new(options).fetch
169
+ remote.concat(local)
170
+ else
171
+ local
172
+ end
125
173
  else
126
174
  raise RankMirror::DistributionNotImplemented
127
175
  end
@@ -129,7 +177,7 @@ end
129
177
  sorted = RankMirror::Mirrors.new(mirrors).sort_by_speed(options).select {|k,v| v > 0}
130
178
 
131
179
  if options.save
132
- config.save(sorted.keys)
180
+ config.save(sorted.keys,options.keys)
133
181
  end
134
182
 
135
183
  i = 1
@@ -137,11 +185,11 @@ i = 1
137
185
  sorted.each do |k,v|
138
186
  speed = v.round(2)
139
187
  if i < 4
140
- puts "#{i}\t#{k}\t#{speed}\sKiB/s".green
188
+ puts "\033[0;32m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m"
141
189
  elsif i > 3 && i < 6
142
- puts "#{i}\t#{k}\t#{speed}\sKiB/s".yellow
190
+ puts "\033[1;33m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m"
143
191
  else
144
- puts "#{i}\t#{k}\t#{speed}\sKiB/s".red
192
+ puts "\033[0;31m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m"
145
193
  end
146
194
  i += 1
147
195
  end
@@ -4,11 +4,13 @@ require 'rankmirror/reachable'
4
4
  require 'rankmirror/speed'
5
5
  require 'rankmirror/options'
6
6
  require 'rankmirror/mirrors'
7
- require 'rankmirror/remoteoss'
8
- require 'rankmirror/localoss'
9
7
  require 'rankmirror/cache'
10
- require 'rankmirror/remotepackman'
11
- require 'rankmirror/localpackman'
12
8
  require 'rankmirror/status'
13
9
  require 'rankmirror/config'
14
-
10
+ require 'rankmirror/distro/remote/oss.rb'
11
+ require 'rankmirror/distro/remote/packman.rb'
12
+ require 'rankmirror/distro/remote/fedora.rb'
13
+ require 'rankmirror/distro/local/oss.rb'
14
+ require 'rankmirror/distro/local/packman.rb'
15
+ require 'rankmirror/distro/local/fedora.rb'
16
+ require 'rankmirror/distro/local/epel.rb'
@@ -9,23 +9,15 @@ module RankMirror
9
9
  @options = options
10
10
  @name = @options.os
11
11
  @file = @name + ".mirrorlist"
12
- @systempath = File.expand_path(File.dirname(__FILE__))
12
+ @systempath = File.expand_path(File.join(File.dirname(__FILE__),"mirrorlists"))
13
13
  @localpath = ENV['HOME'] + "/.rankmirror/"
14
14
  end
15
15
 
16
- def localconfig
17
- File.join(@localpath,@file)
18
- end
19
-
20
- def systemconfig
21
- File.join(@systempath,@file)
22
- end
23
-
24
16
  def path
25
17
  if File.exist?(systemconfig) && File.readable?(systemconfig)
26
18
  if File.exist?(localconfig)
27
19
  m = merge(systemconfig,localconfig)
28
- write(m,localconfig)
20
+ write(m,localconfig,@options.keys)
29
21
  localconfig
30
22
  else
31
23
  systemconfig
@@ -38,16 +30,53 @@ module RankMirror
38
30
  end
39
31
  end
40
32
  end
33
+
34
+ def save(array,header)
35
+ FileUtils.mkdir_p @localpath unless File.directory?(@localpath)
36
+ mirrors_array = array.map! do |uri|
37
+ mirror = RankMirror::Status.new(uri,@name).get
38
+ mirror.name = URI.parse(uri).host if mirror.name.nil?
39
+ mirror.continent = "world" if ["opensuse","packman"].include?(@name)
40
+ mirror.country = "world"
41
+ mirror.http = uri
42
+ mirror
43
+ end
44
+ write(mirrors_array,localconfig,header)
45
+ end
41
46
 
47
+ def parse(config,args)
48
+ f = open(config)
49
+ mirrors = f.readlines.map!{|l|
50
+ unless l.start_with?("#")
51
+ elements = l.strip.split("\t")
52
+ mirror = OpenStruct.new
53
+ args.each_with_index {|arg,index| mirror[arg] = elements[index] }
54
+ mirror
55
+ end
56
+ }.compact
57
+ f.close
58
+ return mirrors
59
+ end
60
+
61
+ private
62
+
63
+ def localconfig
64
+ File.join(@localpath,@file)
65
+ end
66
+
67
+ def systemconfig
68
+ File.join(@systempath,@file)
69
+ end
70
+
42
71
  def merge(systemconfig,localconfig)
43
- system_mirrors = parse(systemconfig)
44
- local_mirrors = parse(localconfig)
72
+ system_mirrors = parse(systemconfig,@options.keys)
73
+ local_mirrors = parse(localconfig,@options.keys)
45
74
  system_mirrors.each do |system_mirror|
46
75
  http_match = false
47
76
  local_mirrors.each do |local_mirror|
48
77
  if system_mirror.http == local_mirror.http
49
78
  http_match = true
50
- local_mirror.continent = system_mirror.continent
79
+ local_mirror.continent = system_mirror.continent if ["opensuse","packman"].include?(@name)
51
80
  local_mirror.country = system_mirror.country
52
81
  end
53
82
  end
@@ -58,50 +87,35 @@ module RankMirror
58
87
  return local_mirrors
59
88
  end
60
89
 
61
- def parse(config)
62
- f = open(config)
63
- mirrors = f.readlines.map!{|l|
64
- unless l.start_with?("#")
65
- elements = l.strip.split("\t")
66
- mirror = OpenStruct.new
67
- mirror.name = elements[0]
68
- mirror.continent = elements[1]
69
- mirror.country = elements[2]
70
- mirror.http = elements[3]
71
- mirror.tumbleweed = elements[4]
72
- mirror.leap4220 = elements[5]
73
- mirror.leap4210 = elements[6]
74
- mirror.leap4230 = elements[7]
75
- mirror
76
- end
77
- }.compact!
78
- f.close
79
- return mirrors
80
- end
81
-
82
- def write(mirrors_array,file)
90
+ def write(mirrors_array,file,header)
83
91
  f = open(file,'w')
84
- f.write "#sitename\tcontinent\tcountry\thttp\ttumbleweed\tleap4220\tleap4210\tleap4230\n"
85
- mirrors_array.each do |mirror_struct|
92
+ f.write process_header(header)
93
+ mirrors_array.each do |m|
86
94
  str = String.new
87
- m = mirror_struct
88
- str = m.name + "\t" + m.continent + "\t" + m.country + "\t" + m.http + "\t" + m.tumbleweed.to_s + "\t" + m.leap4220.to_s + "\t" + m.leap4210.to_s + "\t" + m.leap4230.to_s + "\n"
95
+ header.each do |item|
96
+ if header.index(item) == header.size - 1
97
+ str << m[item].to_s + "\n"
98
+ else
99
+ str << m[item].to_s + "\t"
100
+ end
101
+ end
89
102
  f.write str
90
103
  end
91
104
  f.close
92
105
  end
93
-
94
- def save(array)
95
- FileUtils.mkdir_p @localpath unless File.directory?(@localpath)
96
- mirrors_array = array.map! do |uri|
97
- mirror = RankMirror::Status.new(uri,@options.os).get
98
- mirror.name = URI.parse(uri).host if mirror.name.nil?
99
- mirror.continent = "world"
100
- mirror.country = "world"
101
- mirror
106
+
107
+ def process_header(header)
108
+ str = "#"
109
+ header.each do |title|
110
+ if title == header[header.size - 1]
111
+ str << title + "\n"
112
+ else
113
+ str << title + "\t"
114
+ end
102
115
  end
103
- write(mirrors_array,localconfig)
116
+ return str
104
117
  end
118
+
105
119
  end
106
- end
107
120
 
121
+ end
@@ -0,0 +1,15 @@
1
+ module RankMirror
2
+ class LocalEPEL
3
+ def initialize(mirrorlist,options)
4
+ @options = options
5
+ @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist,@options.keys)
6
+ end
7
+
8
+ def sort
9
+ sorted = @mirrorlist.map!{|m|
10
+ m.http if @options.country == m.country && m[@options.flavor] == "true"
11
+ }.compact
12
+ return sorted
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module RankMirror
2
+ class LocalFedora
3
+ def initialize(mirrorlist,options)
4
+ @options = options
5
+ @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist,@options.keys)
6
+ end
7
+
8
+ def sort
9
+ sorted = @mirrorlist.map!{|m|
10
+ m.http if @options.country == m.country && m[@options.flavor] == "true"
11
+ }.compact
12
+ return sorted
13
+ end
14
+ end
15
+ end
@@ -1,18 +1,15 @@
1
- require 'ostruct'
2
-
3
1
  module RankMirror
4
2
  class LocalOSS
5
3
  def initialize(mirrorlist,options)
6
4
  @options = options
7
- @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist)
5
+ @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist,@options.keys)
8
6
  end
9
7
 
10
8
  def sort
11
9
  sorted = @mirrorlist.map! { |m|
12
10
  m.http if @options.continent == m.continent && m[@options.flavor] == "true"
13
- }.compact!
11
+ }
14
12
  return sorted
15
13
  end
16
14
  end
17
15
  end
18
-
@@ -1,10 +1,8 @@
1
- require 'ostruct'
2
-
3
1
  module RankMirror
4
2
  class LocalPackman
5
3
  def initialize(mirrorlist,options)
6
4
  @options = options
7
- @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist)
5
+ @mirrorlist = RankMirror::Config.new(@options).parse(mirrorlist,@options.keys)
8
6
  end
9
7
 
10
8
  def sort
@@ -0,0 +1,38 @@
1
+ require 'nokogiri'
2
+
3
+ module RankMirror
4
+ class RemoteFedora
5
+ def initialize(options)
6
+ @mirrors = Array.new
7
+ @options = options
8
+ end
9
+
10
+ def fetch
11
+ cache = RankMirror::Cache.new("https://admin.fedoraproject.org/mirrormanager/mirrors").fetch
12
+ doc = Nokogiri::HTML(open(cache))
13
+ doc.xpath("//tr").each do |tr|
14
+ country = tr.element_children[0].content.downcase!
15
+ unless country == "country" || @options.country != country
16
+ tr.element_children[3].element_children.each do |a|
17
+ if a.content == "http"
18
+ if @options.os == "fedora"
19
+ unless a["href"].index("epel")
20
+ status = RankMirror::Status.new(a["href"],@options.os).get
21
+ @mirrors << a["href"] if status[@options.flavor] == true
22
+ end
23
+ else
24
+ if a["href"].index("epel")
25
+ # neu.edu.cn has a wrong epel url on fedora mirror site
26
+ uri = a["href"].index("neu.edu.cn") ? a["href"].sub("fedora/epel","fedora-epel") : a["href"]
27
+ status = RankMirror::Status.new(uri,@options.os).get
28
+ @mirrors << a["href"] if status[@options.flavor] == true
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ return @mirrors
36
+ end
37
+ end
38
+ end
@@ -41,6 +41,7 @@ module RankMirror
41
41
  end
42
42
  end
43
43
  end
44
+
44
45
  return @mirrors
45
46
  end
46
47
  end
@@ -1,12 +1,6 @@
1
1
  module RankMirror
2
- class DistributionNotImplemented < StandardError
3
- end
4
- class MandatoryOptionNotSpecified < StandardError
5
- end
6
- class SuboptionNotSupported < StandardError
7
- end
8
- class FlavorNotImplemented < StandardError
9
- end
10
- class ConfigurationNotFound < StandardError
11
- end
2
+ DistributionNotImplemented = Class.new(StandardError)
3
+ MandatoryOptionNotSpecified = Class.new(StandardError)
4
+ FlavorNotImplemented = Class.new(StandardError)
5
+ ConfigurationNotFound = Class.new(StandardError)
12
6
  end
@@ -0,0 +1,13 @@
1
+ # sitename country http 7 6 5 4
2
+ Aliyun cn http://mirrors.aliyun.com/epel/ true true true true
3
+ Capital Online cn http://mirrors.yun-idc.com/epel/ true true true true
4
+ Northeastern University cn http://mirror.neu.edu.cn/fedora-epel true true true true
5
+ SJTU cn http://ftp.sjtu.edu.cn/fedora/epel/ true true true true
6
+ USTC cn http://mirrors.ustc.edu.cn/epel/ true true true true
7
+ Neusoft cn http://mirrors.neusoft.edu.cn/epel/ true true true true
8
+ Zhejiang University cn http://mirrors.zju.edu.cn/epel/ true true true true
9
+ Lanzhou University cn http://mirror.lzu.edu.cn/epel/ true true true true
10
+ Bit cn http://mirror.bit.edu.cn/fedora/epel/ true true true true
11
+ Hust cn http://mirrors.hust.edu.cn/epel/ true true true true
12
+ Chongqing University cn http://b.mirrors.lanunion.org/epel/ true true true true
13
+ Dalian University of Technology cn http://mirror.dlut.edu.cn/epel/ true true true true
@@ -0,0 +1,9 @@
1
+ # sitename country http 25 24 23 22 21 20
2
+ Aliyun cn http://mirrors.aliyun.com/fedora/ true true true true true true
3
+ Capital Online cn http://mirrors.yun-idc.com/fedora/ true true true true true true
4
+ Northeastern University cn http://mirror.neu.edu.cn/fedora/linux/ false false true true true true
5
+ SJTU cn http://ftp.sjtu.edu.cn/fedora/linux/ true true true true true true
6
+ USTC cn http://mirrors.ustc.edu.cn/fedora/ true true true true true true
7
+ Zhejiang University cn http://mirrors.zju.edu.cn/fedora/ true true true true true true
8
+ Lanzhou University cn http://mirror.lzu.edu.cn/fedora/ true true true true true true
9
+ Bit cn http://mirror.bit.edu.cn/fedora/linux/ true true true true true true
@@ -1,8 +1,12 @@
1
1
  # sitename continent country http tumbleweed leap-4220 leap-4210 leap 4230
2
2
  Aliyun asia china http://mirrors.aliyun.com/opensuse true true true false
3
3
  Capital Online asia china http://mirrors.yun-idc.com/opensuse true true true true
4
- Beijing Institute of Techfalselogy asia china http://mirror.bit.edu.cn/opensuse true true true true
4
+ Beijing Institute of Technology asia china http://mirror.bit.edu.cn/opensuse true true true true
5
5
  Zhejiang University asia china http://mirrors.zju.edu.cn/opensuse true true true true
6
6
  Xiamen University asia china http://mirrors.xmu.edu.cn/opensuse true false true false
7
7
  Zhengzhou University asia china https://mirrors.zzu.edu.cn/opensuse true true true false
8
8
  Chongqing University asia china https://mirrors.cqu.edu.cn/opensuse true true true false
9
+ Lanzhou University asia china http://mirror.lzu.edu.cn/opensuse true true true false
10
+ BJTU asia china http://mirror.bjtu.edu.cn/opensuse true true true false
11
+ SJTU asia china http://ftp.sjtu.edu.cn/opensuse true true true true
12
+ SYSU asia china http://mirror.sysu.edu.cn/opensuse true true true true
@@ -1,2 +1,3 @@
1
1
  # sitename continent country http tumbleweed leap4220 leap4210 leap4230
2
2
  Aliyun asia china http://mirrors.aliyun.com/packman/ true true true false
3
+ BJTU asia china http://mirror.bjtu.edu.cn/packman/suse/ true true true false
@@ -1,100 +1,4 @@
1
1
  require 'ostruct'
2
-
3
2
  module RankMirror
4
- class Options
5
- def initialize
6
- @options = OpenStruct.new
7
- @options.local = false
8
- @options.os = "opensuse"
9
- @options.continent = "asia"
10
- @options.flavor = "leap4220"
11
- @options.quick = true
12
- @options.path = nil
13
- @options.file = "repomd.xml"
14
- end
15
-
16
- def show
17
- return @options
18
- end
19
-
20
- def add(k,v)
21
- @options[k] = v
22
- return @options
23
- end
24
-
25
- def delete_by_key(key)
26
- @options.delete_field(key)
27
- return @options
28
- end
29
-
30
- def delete_by_value(value)
31
- h = @options.to_h
32
- @options.delete_field(h.key(value))
33
- return @options
34
- end
35
-
36
- def local=(v)
37
- @options.local = v
38
- end
39
-
40
- def local
41
- @local ||= @options.local
42
- end
43
-
44
- def os=(v)
45
- @options.os = v
46
- end
47
-
48
- def os
49
- @os ||= @options.os
50
- end
51
-
52
- def continent=(v)
53
- @options.continent = v
54
- end
55
-
56
- def continent
57
- @continent ||= @options.continent
58
- end
59
-
60
- def flavor=(v)
61
- @options.flavor = v
62
- end
63
-
64
- def flavor
65
- @flavor ||= @options.flavor
66
- end
67
-
68
- def quick=(v)
69
- @options.quick = v
70
- end
71
-
72
- def quick
73
- @quick ||= @options.quick
74
- end
75
-
76
- def path=(v)
77
- @options.path = v
78
- end
79
-
80
- def path
81
- @path ||= @options.path
82
- end
83
-
84
- def file=(v)
85
- @options.file = v
86
- end
87
-
88
- def file
89
- @file ||= @options.file
90
- end
91
-
92
- def save=(v)
93
- @options.save = v
94
- end
95
-
96
- def save
97
- @save ||= @options.save
98
- end
99
- end
3
+ Options = Class.new(OpenStruct)
100
4
  end
@@ -11,12 +11,13 @@ module RankMirror
11
11
  r = Curl::Easy.new(@uri)
12
12
  r.perform
13
13
  return r.download_speed / 1024.0
14
- #else
14
+ else
15
15
  # usually in this case, the mirror is online but:
16
16
  # 1. has bad repodata. eg. not fully rsync the origin, or even empty.
17
17
  # 2. volatile. sometimes at good speed, sometimes unreachable.
18
18
  # 3. too slow. takes more than 5 seconds to start a download.
19
19
  # not break here because we're about to find out the good mirrors, not the bad ones.
20
+ return 0
20
21
  end
21
22
  end
22
23
  end
@@ -19,7 +19,6 @@ module RankMirror
19
19
 
20
20
  checklist = {"tumbleweed"=>tumbleweed,"leap4220"=>leap4220,"leap4210"=>leap4210,"leap4230"=>leap4230}
21
21
  mirror = OpenStruct.new
22
- mirror.http = @uri
23
22
 
24
23
  checklist.each do |k,v|
25
24
  if RankMirror::Reachable.new(@uri + v,500).reachable?
@@ -37,7 +36,6 @@ module RankMirror
37
36
  checklist = {"tumbleweed"=>tumbleweed,"leap4220"=>leap4220,"leap4210"=>leap4210,"leap4230"=>leap4230}
38
37
 
39
38
  mirror = OpenStruct.new
40
- mirror.http = @uri
41
39
 
42
40
  checklist.each do |k,v|
43
41
  if RankMirror::Reachable.new(@uri + "openSUSE_" + v + "/Essentials/repodata/",500).reachable?
@@ -47,6 +45,28 @@ module RankMirror
47
45
  end
48
46
  end
49
47
  return mirror
48
+ when "fedora"
49
+ mirror = OpenStruct.new
50
+ check = ["20","21","22","23","24","25"]
51
+ check.each do |k|
52
+ if RankMirror::Reachable.new(@uri + "releases/" + k + "/Everything/x86_64/os/repodata/repomd.xml",500).reachable?
53
+ mirror["fedora" + k] = true
54
+ else
55
+ mirror["fedora" + k] = false
56
+ end
57
+ end
58
+ return mirror
59
+ when "epel"
60
+ mirror = OpenStruct.new
61
+ check = ["4","5","6","7"]
62
+ check.each do |k|
63
+ if RankMirror::Reachable.new(@uri + "/" + k + "/x86_64/repodata/repomd.xml",500).reachable?
64
+ mirror["epel" + k] = true
65
+ else
66
+ mirror["epel" + k] = false
67
+ end
68
+ end
69
+ return mirror
50
70
  else
51
71
  end
52
72
  else
@@ -1,3 +1,3 @@
1
1
  module RankMirror
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_runtime_dependency "nokogiri", ">= 1.6.0"
34
- spec.add_runtime_dependency "colorize", ">= 0.8.0"
35
34
  spec.add_runtime_dependency "curb", ">= 0.9.0"
36
35
  spec.add_development_dependency "bundler", "~> 1.13"
37
36
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rankmirror
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - marguerite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
- - !ruby/object:Gem::Dependency
28
- name: colorize
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 0.8.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: curb
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -116,16 +102,21 @@ files:
116
102
  - lib/rankmirror.rb
117
103
  - lib/rankmirror/cache.rb
118
104
  - lib/rankmirror/config.rb
105
+ - lib/rankmirror/distro/local/epel.rb
106
+ - lib/rankmirror/distro/local/fedora.rb
107
+ - lib/rankmirror/distro/local/oss.rb
108
+ - lib/rankmirror/distro/local/packman.rb
109
+ - lib/rankmirror/distro/remote/fedora.rb
110
+ - lib/rankmirror/distro/remote/oss.rb
111
+ - lib/rankmirror/distro/remote/packman.rb
119
112
  - lib/rankmirror/exception.rb
120
- - lib/rankmirror/localoss.rb
121
- - lib/rankmirror/localpackman.rb
113
+ - lib/rankmirror/mirrorlists/epel.mirrorlist
114
+ - lib/rankmirror/mirrorlists/fedora.mirrorlist
115
+ - lib/rankmirror/mirrorlists/opensuse.mirrorlist
116
+ - lib/rankmirror/mirrorlists/packman.mirrorlist
122
117
  - lib/rankmirror/mirrors.rb
123
- - lib/rankmirror/opensuse.mirrorlist
124
118
  - lib/rankmirror/options.rb
125
- - lib/rankmirror/packman.mirrorlist
126
119
  - lib/rankmirror/reachable.rb
127
- - lib/rankmirror/remoteoss.rb
128
- - lib/rankmirror/remotepackman.rb
129
120
  - lib/rankmirror/speed.rb
130
121
  - lib/rankmirror/status.rb
131
122
  - lib/rankmirror/version.rb