rbsync 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/lib/rbsync.rb CHANGED
@@ -161,12 +161,6 @@ class RbSync
161
161
  ret = files.map{|e|
162
162
  FileTest.exist?(e[1])
163
163
  }
164
- #ret = target.map{|key|
165
- #e = src_files[key].first
166
- #FileUtils.copy( File.expand_path(e,src) , File.expand_path(e,dest),
167
- #{:preserve=>self.preserve?,:verbose=>self.verbose? })
168
- #FileTest.exist?(File.expand_path(e,dest))
169
- #}
170
164
  puts "同期が終りました" if ret.select{|e|!e}.size == 0 && self.debug?
171
165
  puts "同期に失敗したみたい" if ret.select{|e|!e}.size != 0 && self.debug?
172
166
  end
@@ -306,9 +300,40 @@ class RbSync
306
300
  end
307
301
  def copy_r(files)
308
302
  ##todo 進捗を調べる.
309
-
310
- files.each{|e|
311
- FileUtils.copy( e[0] , e[1] ,{:preserve=>self.preserve?,:verbose=>self.verbose? } )
303
+ if(@conf[:progress])
304
+ puts ("copy #{files.size} files")
305
+ $stdout.flush
306
+ end
307
+ files.each_with_index{|e,i|
308
+ #show
309
+ if(@conf[:progress])
310
+ puts ("start #{i+1}/#{files.size}")
311
+ $stdout.flush
312
+ end
313
+ #main
314
+ copy_thread = Thread.start{
315
+ FileUtils.copy( e[0] , e[1] ,{:preserve=>self.preserve?,:verbose=>self.verbose? } )
316
+ }
317
+ #progress of each file
318
+ progress_thread = nil
319
+ if(@conf[:progress])
320
+ progress_thread = Thread.start{
321
+ bar = ProgressBar.new
322
+ bar.size = 30
323
+ src_size = File.size(e[0])
324
+ dst_size = -1
325
+ bar.start("copying #{e[0]} to #{e[1]}")
326
+ while(src_size!=dst_size)
327
+ src_size = File.size(e[0]).to_f
328
+ dst_size = File.size(e[1]).to_f
329
+ bar.progress(((dst_size/src_size)*100).to_int)
330
+ sleep 0.2
331
+ end
332
+ bar.end("done")
333
+ }
334
+ end
335
+ copy_thread.join
336
+ progress_thread.join if progress_thread
312
337
  }
313
338
  end
314
339
  def sync(src,dest,options={})
@@ -405,14 +430,14 @@ class ProgressBar
405
430
  attr_accessor :size, :out, :bar_char_undone, :bar_char_done, :show_percent
406
431
  def initialize()
407
432
  @out = $stdout
408
- @size = 11
433
+ @size = 10
409
434
  @bar_char_undone = "_"
410
435
  @bar_char_done = "#"
411
436
  @show_percent = true
412
- @printend_max_size = @size
437
+ @printend_max_size = 0
413
438
  end
414
439
  def start(message="")
415
- out.print message
440
+ out.puts message
416
441
  out.print bar_char_undone * size
417
442
  out.flush
418
443
  end
@@ -442,62 +467,3 @@ class ProgressBar
442
467
  end
443
468
  end
444
469
 
445
- #require 'tmpdir'
446
- #require 'find'
447
- #require 'pp'
448
- #Dir.mktmpdir('goo') do |dir|
449
- #Dir.chdir dir do
450
- #Dir.mkdir("old")
451
- #Dir.mkdir("new")
452
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("test")}}
453
- #open("./new/test.txt", "w+"){|f| 10.times{f.puts("different")}}
454
- #rsync = RbSync.new
455
- #rsync.sync("old","new",{:overwrite=>false,:check_hash=>true})
456
- #p FileUtils.cmp("old/test.txt","new/test.txt") == false
457
- #end
458
- #end
459
-
460
-
461
- #require 'tmpdir'
462
- #require 'find'
463
- #require 'pp'
464
- #Dir.mktmpdir('goo') do |dir|
465
- #Dir.chdir dir do
466
- #Dir.mkdir("old")
467
- #Dir.mkdir("new")
468
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("test")}}
469
- #rsync = RbSync.new
470
- #rsync.sync("old","new")
471
- #p FileUtils.cmp("old/test.txt","new/test.txt") == true
472
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("changed")}}
473
- #rsync.sync("old","new",{:rename => true})
474
- #p FileUtils.cmp("old/test.txt","new/test.txt") == false
475
- #p FileUtils.cmp("old/test.txt","new/test(1).txt") == true
476
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("changed!!!")}}
477
- #rsync.sync("old","new",{:rename => true})
478
- #p FileUtils.cmp("old/test.txt","new/test(2).txt") == true
479
- #end
480
- #end
481
- #require 'tmpdir'
482
- #require 'find'
483
- #require 'pp'
484
- #Dir.mktmpdir('goo') do |dir|
485
- #Dir.chdir dir do
486
- #Dir.mkdir("old")
487
- #Dir.mkdir("new")
488
- ## 同名のファイルを作って
489
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("test")}}
490
- #old_content =open("./old/test.txt", "r").read
491
- ## ミラーして
492
- #rsync = RbSync.new
493
- #rsync.sync("old","new")
494
- #p FileUtils.cmp("old/test.txt","new/test.txt") == true
495
- #open("./old/test.txt", "w+"){|f| 10.times{f.puts("changed")}}
496
- ## バックアップ同期する
497
- #rsync.sync("old","new",{:backup => true})
498
- #p FileUtils.cmp("old/test.txt","new/test.txt") == true
499
- ## バックアップしたファイルがどうなっているか見る
500
- #files = Dir.glob "./new/**/*"
501
- #p old_content == open((files - ["./new/test.txt"]).first).read
502
- #end
503
- #end
data/rbsync.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbsync}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["takuya"]
@@ -25,10 +25,9 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/rbsync.rb",
28
- "new/test.txt",
29
- "old/test.txt",
30
28
  "rbsync.gemspec",
31
29
  "test/helper.rb",
30
+ "test/test_progressbar.rb",
32
31
  "test/test_rbsync.rb"
33
32
  ]
34
33
  s.homepage = %q{http://github.com/takuya/rbsync}
@@ -0,0 +1,85 @@
1
+ require 'helper'
2
+
3
+
4
+ require 'stringio'
5
+ class TestProgressBar < Test::Unit::TestCase
6
+ def test_progress_bar_start
7
+ io = StringIO.new
8
+ prg= ProgressBar.new
9
+ prg.out = io
10
+ prg.show_percent = true
11
+ prg.size = 5
12
+ prg.start("downloading")
13
+ io.rewind
14
+ assert io.read == "downloading\n_____"
15
+ end
16
+ def test_progress_bar_end
17
+ io = StringIO.new
18
+ prg= ProgressBar.new
19
+ prg.out = io
20
+ prg.size = 10
21
+ prg.show_percent = true
22
+ prg.end("done")
23
+ io.rewind
24
+ assert io.read =="\r \r########## 100% done\n"
25
+ end
26
+ def test_progress_bar_progress_twice
27
+ io = StringIO.new
28
+ prg= ProgressBar.new
29
+ prg.out = io
30
+ prg.show_percent = true
31
+ prg.size = 10
32
+ prg.progress(40, "40/100")
33
+ prg.progress(50, "50/100")
34
+ io.rewind
35
+ assert io.read == "\r \r####______ 40% 40/100\r \r#####_____ 50% 50/100"
36
+ end
37
+ def test_progress_bar_progress_change_done_char
38
+ io = StringIO.new
39
+ prg= ProgressBar.new
40
+ prg.out = io
41
+ prg.bar_char_done = "="
42
+ prg.show_percent = true
43
+ prg.size = 10
44
+ prg.progress(40, "40/100")
45
+ prg.progress(50, "50/100")
46
+ io.rewind
47
+ assert io.read == "\r \r====______ 40% 40/100\r \r=====_____ 50% 50/100"
48
+ end
49
+ def test_progress_bar_progress_change_undone_char
50
+ io = StringIO.new
51
+ prg= ProgressBar.new
52
+ prg.out = io
53
+ prg.bar_char_done = "="
54
+ prg.bar_char_undone = "-"
55
+ prg.show_percent = true
56
+ prg.size = 10
57
+ prg.progress(40, "40/100")
58
+ prg.progress(50, "50/100")
59
+ io.rewind
60
+ assert io.read == "\r \r====------ 40% 40/100\r \r=====----- 50% 50/100"
61
+ end
62
+ def test_progress_bar_progress_out_range
63
+ begin
64
+ io = StringIO.new
65
+ prg= ProgressBar.new
66
+ prg.out = io
67
+ prg.progress(110, "110/100")
68
+ rescue => e
69
+ assert e.class == ArgumentError
70
+ end
71
+ end
72
+ def test_progress_bar_100_percent
73
+ io = StringIO.new
74
+ prg= ProgressBar.new
75
+ prg.out = io
76
+ prg.bar_char_done = "="
77
+ prg.bar_char_undone = "-"
78
+ prg.show_percent = true
79
+ prg.size = 5
80
+ prg.progress(100, "100/100")
81
+ io.rewind
82
+ assert io.read == "\r \r===== 100% 100/100"
83
+ end
84
+ end
85
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbsync
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - takuya
@@ -96,10 +96,9 @@ files:
96
96
  - Rakefile
97
97
  - VERSION
98
98
  - lib/rbsync.rb
99
- - new/test.txt
100
- - old/test.txt
101
99
  - rbsync.gemspec
102
100
  - test/helper.rb
101
+ - test/test_progressbar.rb
103
102
  - test/test_rbsync.rb
104
103
  has_rdoc: true
105
104
  homepage: http://github.com/takuya/rbsync
data/new/test.txt DELETED
@@ -1,10 +0,0 @@
1
- test
2
- test
3
- test
4
- test
5
- test
6
- test
7
- test
8
- test
9
- test
10
- test
data/old/test.txt DELETED
@@ -1,10 +0,0 @@
1
- test
2
- test
3
- test
4
- test
5
- test
6
- test
7
- test
8
- test
9
- test
10
- test