Changeset 425

Show
Ignore:
Timestamp:
02/13/2008 13:17:31 (7 months ago)
Author:
why
Message:
  • lib/shoes/shy.rb: working on shy progress meter.
Location:
trunk/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/shoes.rb

    r424 r425  
    3030 
    3131class Shoes 
    32   VERSION = "0.1" 
     32  VERSION = "Raisins" 
    3333 
    3434  NotFound = proc do 
     
    4242        stack :margin => 10 do 
    4343          subtitle "ShyMaker", :margin => 0 
    44           tagline "for Shoes #{Shoes::VERSION}" 
     44          inscription "for Shoes #{Shoes::VERSION}" 
    4545        end 
    4646      end 
    47       stack do 
     47      stack :margin_left => 40 do 
    4848        @done = 
    4949          stack :margin => 20, :hidden => true do 
     
    5252        @make = 
    5353          stack :margin => 20, :hidden => true do 
    54             para "Making the Shy" 
     54            para "Making the Shy"  
     55            @make_text = para "Creating file..." 
    5556            @prog = progress 
    5657          end 
     
    8788 
    8889                Thread.start do 
    89                   Shy.c(shy_save, shy, s) 
     90                  Shy.c(shy_save, shy, s) do |_name, _perc, _left| 
     91                    @make_text.replace "Adding #{_name}" 
     92                  end 
    9093                  @make.hide 
    9194                  @done.show 
  • trunk/lib/shoes/shy.rb

    r134 r425  
    55require 'zlib' 
    66require 'shoes/minitar' 
     7require 'find' 
    78require 'tmpdir' 
    89require 'yaml' 
     
    1819  def self.launchable(d) 
    1920    Dir["#{d}/**/*.rb"].map do |path| 
    20       path.gsub(%r!#{Regexp::quote(path)}/!, '') 
     21      path.gsub(%r!#{Regexp::quote(d)}/!, '') 
     22    end 
     23  end 
     24 
     25  def self.__hdr__(f) 
     26    hdr = f.read(10).unpack(LAYOUT) 
     27    raise IOError, "Invalid header" if hdr[0] != MAGIC and hdr[1] > VERSION 
     28    YAML.load(f.read(hdr[2])) 
     29  end 
     30 
     31 
     32  def self.du(root) 
     33    size = 0 
     34    Find.find(root) do |path| 
     35      if FileTest.directory?(path) 
     36        if File.basename(path)[0] == ?. 
     37          Find.prune 
     38        else 
     39          next 
     40        end 
     41      else 
     42        size += FileTest.size(path) 
     43      end 
     44    end 
     45    size 
     46  end 
     47 
     48  def self.meta(path, d = ".") 
     49    File.open(path, 'rb') do |f| 
     50      shy = __hdr__(f) 
    2151    end 
    2252  end 
     
    2454  def self.x(path, d = ".") 
    2555    File.open(path, 'rb') do |f| 
    26       hdr = f.read(10).unpack(LAYOUT) 
    27       raise IOError, "Invalid header" if hdr[0] != MAGIC and hdr[1] > VERSION 
    28       shy = YAML.load(f.read(hdr[2])) 
     56      shy = __hdr__(f) 
    2957      inp = Zlib::GzipReader.new(f) 
    3058      Archive::Tar::Minitar.unpack(inp, d) 
     
    3361  end 
    3462 
    35   def self.c(path, shy, d) 
     63  def self.c(path, shy, d, &blk) 
    3664    path = File.expand_path(path) 
    3765    meta = shy.to_yaml 
     66    total = left = du(d) 
    3867    Dir.chdir(d) do 
    3968      File.open(path, "wb") do |f| 
     
    4271        out = Zlib::GzipWriter.new(f) 
    4372        files = ["."] 
    44         Archive::Tar::Minitar.pack(files, out) 
     73 
     74        tarblk = nil 
     75        if blk 
     76          tarblk = proc do |action, name, stats| 
     77            if action == :file_progress 
     78              left -= stats[:currinc] 
     79              blk[name, 100.0 - (left.to_f / total.to_f), left] 
     80            end 
     81          end 
     82        end 
     83        Archive::Tar::Minitar.pack(files, out, &tarblk) 
    4584      end 
    4685    end