lib/delphivm/dsl.rb in delphivm-0.7.7 vs lib/delphivm/dsl.rb in delphivm-0.8.0
- old
+ new
@@ -1,6 +1,6 @@
-# encoding: UTF-8
+
class Delphivm
module DSL
extend self
@@ -40,23 +40,19 @@
def download(source_uri, dowonlad_root_path, file_name)
full_url = source_uri + '/' + file_name
to_here = dowonlad_root_path + file_name
pb = nil
- puts "Downloading: #{full_url}"
+ puts "\nDownloading: #{full_url}"
start = lambda do |length, hint=''|
- pb = ProgressBar.new("#{file_name}", length);
- pb.instance_variable_set "@title_width", file_name.length + 2
- pb.format = "\s\s%-s #{hint} %3d%% %s %s"
- pb.clear
- pb.send :show
+ pb = ProgressBar.create(:title => "#{hint}", :format => "%t %E %w");
end
- progress = lambda {|s| pb.set(s)}
+ progress = lambda {|s| pb.progress = s; pb.refresh}
if Pathname(to_here).exist?
- start.call(0, "(cached)")
+ start.call(0, "(cached) ")
else
begin
content = open(full_url, "rb", content_length_proc: start, progress_proc: progress).read
File.open(to_here, "wb") do |wfile|
wfile.write(content)
@@ -72,18 +68,15 @@
pb.finish if pb
end
def unzip(file, destination)
Zip::ZipFile.open(file) do |zip_file|
- pb = ProgressBar.new("", zip_file.size)
- pb.format = "\s\s\s\sextracting: %3d%% %s file: %-34s"
- pb.format_arguments = [:percentage, :bar, :title]
+ pb = ProgressBar.create(:total => zip_file.size, :format => "extracting %c/%C %B %t")
zip_file.each do |f|
f_path = destination + f.name
next if Pathname(f_path).directory?
f_path.dirname.mkpath
- pb.instance_variable_set "@title", "#{f_path.basename}"
- pb.inc
+ pb.title = "#{f_path.basename}"
Pathname(f_path).delete if File.exist?(f_path)
zip_file.extract(f, f_path)
end
pb.finish
end
\ No newline at end of file