From 168958ce2b2e1a0f7cbdd02e31a2477044e2a866 Mon Sep 17 00:00:00 2001 From: Austin Wagner Date: Fri, 29 Nov 2013 11:47:08 -0500 Subject: [PATCH] Remove wget dependency in build script --- build_cmder.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/build_cmder.rb b/build_cmder.rb index 2d171f2..f18c617 100644 --- a/build_cmder.rb +++ b/build_cmder.rb @@ -7,22 +7,28 @@ # conemu-maximus5. Correct files are beeing picked by using labels. # I will move the script for getting files by labels from php to here as soon I feel like it -require 'FileUtils' +require 'fileutils' +require 'open-uri' +require 'uri' def get_file project, query - # Should be changed to integrated downloader - urlToFile = 'wget -q -O - "http://samuelvasko.tk/gcode/?project='+project+'&query='+query+'"' - urlToFile = `#{urlToFile}` - urlToFile = urlToFile.split("\n").first + urlToFile = URI.escape('http://samuelvasko.tk/gcode/?project='+project+'&query='+query) + open(urlToFile) do |resp| + urlToFile = URI.escape(resp.read.split(/\r?\n/).first) + end extension = urlToFile.split('.').last filename = project+'.'+extension - puts "\n ------ Downloading #{project} ------- \n \n" - get_file = system("wget -O #{filename} #{urlToFile}") - - unless get_file - puts "Failied to download #{project} from #{urlToFile}" + puts "\n ------ Downloading #{project} from #{urlToFile} ------- \n \n" + begin + open(urlToFile, 'rb') do |infile| + open(filename, 'wb') do |outfile| + outfile.write(infile.read) + end + end + rescue IOError => error + puts error FileUtils.rm(filename) if File.exists?(filename) exit(1) end @@ -39,7 +45,6 @@ def get_file project, query FileUtils.mv(Dir.glob("#{temp_name}/*")[0], project) FileUtils.rm_r(temp_name) end - end puts '