6 # miscellaneous useful functions
9 def Utils.safe_exec(command, *args)
12 return p.readlines.join("\n")
18 puts "exec of #{command} led to exception: #{e}"
21 puts "exec of #{command} failed"
27 # returns a string containing the result of an HTTP GET on the uri
28 def Utils.http_get(uristr, readtimeout=8, opentimeout=4)
30 # ruby 1.7 or better needed for this (or 1.6 and debian unstable)
32 # (so we support the 1_1 api anyway, avoids problems)
34 uri = URI.parse uristr
37 query += "?#{uri.query}"
42 if(ENV['http_proxy'] && proxy_uri = URI.parse(ENV['http_proxy']))
43 proxy_host = proxy_uri.host
44 proxy_port = proxy_uri.port
48 http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port)
49 http.open_timeout = opentimeout
50 http.read_timeout = readtimeout
53 resp = http.get(query)
60 $stderr.puts "Utils.http_get exception: #{e}, while trying to get #{uristr}"