bin/rankmirror in rankmirror-1.0.0 vs bin/rankmirror in rankmirror-1.1.0

- old
+ new

@@ -2,13 +2,19 @@ $:.push(File.expand_path(File.dirname(__FILE__) + "/../lib")) require 'rankmirror' require 'optparse' -require 'colorize' options = RankMirror::Options.new +options.local = false +options.os = "opensuse" +options.continent = "asia" +options.flavor = "leap4220" +options.quick = true +options.path = nil +options.file = "repomd.xml" parser = OptionParser.new do |opts| opts.banner = "Usage: rankmirror [options]" opts.separator "" opts.separator "Specific options:" @@ -17,57 +23,83 @@ "Check mirrors in your local mirrorlist file ONLY.") do |local| options.local = true end opts.on("-o", "--os [Distribution]", - "Check mirrors for this distro. Now supported: 'opensuse', 'packman'.") do |os| + "Check mirrors for this distro. Now supported: 'opensuse', 'packman', 'fedora', 'epel'.") do |os| case os when "opensuse" options.os = "opensuse" - options.path = "tumbleweed/repo/oss/suse/repodata/" + options.path = "tumbleweed/repo/oss/suse/repodata/" when "packman" options.os = "packman" options.path = "openSUSE_Tumbleweed/Essentials/repodata/" + when "fedora" + options.os = "fedora" + when "epel" + options.os = "epel" + when nil + raise RankMirror::MandatoryOptionNotSpecified else raise RankMirror::DistributionNotImplemented end - - if options.os.nil? - raise RankMirror::MandatoryOptionNotSpecified - end end opts.on("--continent [Continent]", "Check mirrors on this continent. openSUSE ONLY. Available Continents: 'africa', 'asia', 'europe', 'northamerica', 'southamerica', 'oceania'.") do |cont| unless options.os != "opensuse" options.continent = cont.downcase.delete("\s") + raise RankMirror::MandatoryOptionNotSpecified if options.continent.nil? else - raise RankMirror::SuboptionNotSupported + raise RankMirror::DistributionNotImplemented end end - opts.on("--flavor [Flavor]","Check mirrors for this flavor. openSUSE ONLY. - Now supported: '4220', '4210', 'tumbleweed'.") do |flavor| + opts.on("--country [Country]", "Check mirrors in this country. Fedora/EPEL ONLY.") do |country| case options.os + when "fedora","epel" + options.country = country.downcase + raise RankMirror::MandatoryOptionNotSpecified if options.country.nil? + else + raise RankMirror::DistributionNotImplemented + end + end + + opts.on("--flavor [Flavor]","Check mirrors for this flavor. + Now supported: openSUSE: '4220', '4210', 'tumbleweed'; Fedora: 20-25 ; epel: 4-7.") do |flavor| + case options.os when "opensuse","packman" + options.keys = ["name","continent","country","http","tumbleweed","leap4220","leap4210","leap4230"] case flavor when "4220" options.flavor = "leap4220" when "4210" options.flavor = "leap4210" when "tumbleweed","tw" options.flavor = "tumbleweed" + when nil + raise RankMirror::MandatoryOptionNotSpecified else raise RankMirror::FlavorNotImplemented end + when "fedora" + options.flavor = "fedora" + flavor + options.path = "releases/" + flavor + "/Everything/x86_64/os/repodata/" + options.keys = ["name","country","http","fedora25","fedora24","fedora23","fedora22","fedora21","fedora20"] + raise RankMirror::MandatoryOptionNotSpecified if options.flavor.nil? + when "epel" + options.flavor = "epel" + flavor + options.path = flavor + "/x86_64/repodata/" + options.keys = ["name","country","http","epel7","epel6","epel5","epel4"] + raise RankMirror::MandatoryOptionNotSpecified if options.flavor.nil? else raise RankMirror::DistributionNotImplemented end end - opts.on("-q", "--quick [1/0]", "Check mirrors quickly/slowly. + opts.on("-q", "--quick [1/0]", "Check mirrors quickly/slowly. openSUSE/Packman ONLY. The quick check will download a tiny file from the mirror, thus response quickly but the result will be less accurate. Default: 1") do |quick| unless quick.to_i > 0 options.quick = false case options.os @@ -120,28 +152,44 @@ remote = RankMirror::RemotePackman.new.fetch remote.concat(local) else local end +when "fedora" + local = RankMirror::LocalFedora.new(config.path,options).sort + mirrors = unless options.local + remote = RankMirror::RemoteFedora.new(options).fetch + remote.concat(local) + else + local + end +when "epel" + local = RankMirror::LocalEPEL.new(config.path,options).sort + mirrors = unless options.local + remote = RankMirror::RemoteFedora.new(options).fetch + remote.concat(local) + else + local + end else raise RankMirror::DistributionNotImplemented end sorted = RankMirror::Mirrors.new(mirrors).sort_by_speed(options).select {|k,v| v > 0} if options.save - config.save(sorted.keys) + config.save(sorted.keys,options.keys) end i = 1 sorted.each do |k,v| speed = v.round(2) if i < 4 - puts "#{i}\t#{k}\t#{speed}\sKiB/s".green + puts "\033[0;32m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m" elsif i > 3 && i < 6 - puts "#{i}\t#{k}\t#{speed}\sKiB/s".yellow + puts "\033[1;33m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m" else - puts "#{i}\t#{k}\t#{speed}\sKiB/s".red + puts "\033[0;31m#{i}\t#{k}\t#{speed}\sKiB/s\033[0m" end i += 1 end