Changeset 425
- Timestamp:
- 02/13/2008 13:17:31 (7 months ago)
- Location:
- trunk/lib
- Files:
-
- 2 modified
-
shoes.rb (modified) (4 diffs)
-
shoes/shy.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/shoes.rb
r424 r425 30 30 31 31 class Shoes 32 VERSION = " 0.1"32 VERSION = "Raisins" 33 33 34 34 NotFound = proc do … … 42 42 stack :margin => 10 do 43 43 subtitle "ShyMaker", :margin => 0 44 tagline"for Shoes #{Shoes::VERSION}"44 inscription "for Shoes #{Shoes::VERSION}" 45 45 end 46 46 end 47 stack do47 stack :margin_left => 40 do 48 48 @done = 49 49 stack :margin => 20, :hidden => true do … … 52 52 @make = 53 53 stack :margin => 20, :hidden => true do 54 para "Making the Shy" 54 para "Making the Shy" 55 @make_text = para "Creating file..." 55 56 @prog = progress 56 57 end … … 87 88 88 89 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 90 93 @make.hide 91 94 @done.show -
trunk/lib/shoes/shy.rb
r134 r425 5 5 require 'zlib' 6 6 require 'shoes/minitar' 7 require 'find' 7 8 require 'tmpdir' 8 9 require 'yaml' … … 18 19 def self.launchable(d) 19 20 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) 21 51 end 22 52 end … … 24 54 def self.x(path, d = ".") 25 55 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) 29 57 inp = Zlib::GzipReader.new(f) 30 58 Archive::Tar::Minitar.unpack(inp, d) … … 33 61 end 34 62 35 def self.c(path, shy, d )63 def self.c(path, shy, d, &blk) 36 64 path = File.expand_path(path) 37 65 meta = shy.to_yaml 66 total = left = du(d) 38 67 Dir.chdir(d) do 39 68 File.open(path, "wb") do |f| … … 42 71 out = Zlib::GzipWriter.new(f) 43 72 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) 45 84 end 46 85 end
