class PackerFiles::Debian::Mirrors

Attributes

best[R]
hosts[R]

accessors

proxy[R]

Public Class Methods

new() click to toggle source

Constructor

# File lib/PackerFiles/OS/Debian/Mirrors.rb, line 26
def initialize

   # A Single web page get more than this (in seconds) is SLOW
   limit   = 1 

   # No. of trials for a web page
   trials  = 4  
   
   # Get the name of the http proxy
   @proxy   = ENV['http_proxy'] 

   # Get the host list of mirrors for this country
   code     = Utils::AutoZone.new.country_code.downcase
   @hosts   = country_mirror(code)
   if @hosts.empty?
      @hosts   = [@@default] if @hosts.empty?
      @best    = URI::parse(@@default)
   else
      f        = Utils::FastestURL.new(limit, trials)
      all      = f.best_urls(@hosts).flatten
      begin 
         @best    = URI::parse(all.first)
      rescue Exception => e
         puts "Exception: #{e}, All: #{all.to_s}"
         raise e
      end
   end
end

Private Instance Methods

country_mirror(code) click to toggle source

Given the country code, get a list of mirror sites that match the country code.

# File lib/PackerFiles/OS/Debian/Mirrors.rb, line 58
def country_mirror(code)
  arr = []
  regex = 'href=\"(http://.+\.' + code + '\/.+)"'
  open(@@mirrors) {|f| 
    f.each_line do |line|
      if match = line.match(regex)
         arr.push(match[1])
      end
    end
  }
  return arr
end