chillfile 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -3
- data/bin/chillfile +3 -3
- data/chillfile.gemspec +9 -1
- data/lib/chillfile/cli.rb +8 -3
- data/lib/chillfile/sync.rb +49 -28
- data/lib/chillfile.rb +8 -3
- data/spec/filesystem_after/baz.modified.single +2 -0
- data/spec/filesystem_after/modified/biz.0.modified.multi +2 -0
- data/spec/filesystem_after/modified/biz.1.modified.multi +2 -0
- data/spec/filesystem_before/baz.modified.single +2 -0
- data/spec/filesystem_before/modified/biz.0.modified.multi +2 -0
- data/spec/fixtures/filesystem_after.json +10 -1
- data/spec/fixtures/filesystem_before.json +7 -1
- data/version.yml +1 -1
- metadata +28 -10
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,9 +11,9 @@ GIT
|
|
11
11
|
|
12
12
|
GIT
|
13
13
|
remote: git://github.com/dpree/treedisha.git
|
14
|
-
revision:
|
14
|
+
revision: bce76bfcb419b7308d6d1b062c607ecbcf9f8e37
|
15
15
|
specs:
|
16
|
-
treedisha (0.0.
|
16
|
+
treedisha (0.0.2)
|
17
17
|
|
18
18
|
GEM
|
19
19
|
remote: http://rubygems.org/
|
@@ -72,6 +72,7 @@ GEM
|
|
72
72
|
rspec-expectations (2.3.0)
|
73
73
|
diff-lcs (~> 1.1.2)
|
74
74
|
rspec-mocks (2.3.0)
|
75
|
+
ruby-progressbar (0.0.9)
|
75
76
|
thor (0.14.6)
|
76
77
|
tzinfo (0.3.23)
|
77
78
|
|
@@ -84,5 +85,6 @@ DEPENDENCIES
|
|
84
85
|
jeweler
|
85
86
|
json
|
86
87
|
rspec
|
88
|
+
ruby-progressbar
|
87
89
|
thor
|
88
|
-
treedisha!
|
90
|
+
treedisha (~> 0.0.2)!
|
data/bin/chillfile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require "rubygems"
|
4
|
-
require "chillfile"
|
3
|
+
#require "rubygems"
|
4
|
+
#require "chillfile"
|
5
5
|
|
6
|
-
|
6
|
+
require File.join(File.dirname(__FILE__), "../lib/chillfile")
|
7
7
|
|
8
8
|
Chillfile::CLI.start
|
data/chillfile.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{chillfile}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["dpree"]
|
@@ -39,13 +39,18 @@ Gem::Specification.new do |s|
|
|
39
39
|
"spec/filesystem_after/bar.1.moved.untouched",
|
40
40
|
"spec/filesystem_after/bar.2.moved.copy",
|
41
41
|
"spec/filesystem_after/bar.3.moved.copy",
|
42
|
+
"spec/filesystem_after/baz.modified.single",
|
42
43
|
"spec/filesystem_after/foo.fx.copy",
|
43
44
|
"spec/filesystem_after/foo.untouched",
|
45
|
+
"spec/filesystem_after/modified/biz.0.modified.multi",
|
46
|
+
"spec/filesystem_after/modified/biz.1.modified.multi",
|
44
47
|
"spec/filesystem_after/moo.new",
|
45
48
|
"spec/filesystem_after/subdir_b/bar.4.moved.copy",
|
46
49
|
"spec/filesystem_before/bar.0.moved.deleted",
|
47
50
|
"spec/filesystem_before/bar.1.moved.untouched",
|
51
|
+
"spec/filesystem_before/baz.modified.single",
|
48
52
|
"spec/filesystem_before/foo.untouched",
|
53
|
+
"spec/filesystem_before/modified/biz.0.modified.multi",
|
49
54
|
"spec/filesystem_before/subdir/mii.deleted",
|
50
55
|
"spec/filesystem_before/wuu.deleted",
|
51
56
|
"spec/fixtures/filesystem_after.json",
|
@@ -83,6 +88,7 @@ Gem::Specification.new do |s|
|
|
83
88
|
s.add_runtime_dependency(%q<treedisha>, ["~> 0.0.2"])
|
84
89
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
85
90
|
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
91
|
+
s.add_runtime_dependency(%q<ruby-progressbar>, [">= 0"])
|
86
92
|
s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
|
87
93
|
s.add_runtime_dependency(%q<couchrest>, ["~> 1.0.1"])
|
88
94
|
s.add_runtime_dependency(%q<treedisha>, ["~> 0.0.2"])
|
@@ -93,6 +99,7 @@ Gem::Specification.new do |s|
|
|
93
99
|
s.add_dependency(%q<treedisha>, ["~> 0.0.2"])
|
94
100
|
s.add_dependency(%q<json>, [">= 0"])
|
95
101
|
s.add_dependency(%q<thor>, [">= 0"])
|
102
|
+
s.add_dependency(%q<ruby-progressbar>, [">= 0"])
|
96
103
|
s.add_dependency(%q<thor>, ["~> 0.14.6"])
|
97
104
|
s.add_dependency(%q<couchrest>, ["~> 1.0.1"])
|
98
105
|
s.add_dependency(%q<treedisha>, ["~> 0.0.2"])
|
@@ -104,6 +111,7 @@ Gem::Specification.new do |s|
|
|
104
111
|
s.add_dependency(%q<treedisha>, ["~> 0.0.2"])
|
105
112
|
s.add_dependency(%q<json>, [">= 0"])
|
106
113
|
s.add_dependency(%q<thor>, [">= 0"])
|
114
|
+
s.add_dependency(%q<ruby-progressbar>, [">= 0"])
|
107
115
|
s.add_dependency(%q<thor>, ["~> 0.14.6"])
|
108
116
|
s.add_dependency(%q<couchrest>, ["~> 1.0.1"])
|
109
117
|
s.add_dependency(%q<treedisha>, ["~> 0.0.2"])
|
data/lib/chillfile/cli.rb
CHANGED
@@ -14,12 +14,12 @@ module Chillfile
|
|
14
14
|
|
15
15
|
class_option "couchdb_database",
|
16
16
|
:default => "chillfile",
|
17
|
-
:aliases => '-
|
17
|
+
:aliases => '-d',
|
18
18
|
:banner => "CouchDB Database name"
|
19
19
|
|
20
20
|
class_option "couchdb_type_key",
|
21
21
|
:default => "type",
|
22
|
-
:aliases => '-
|
22
|
+
:aliases => '-k',
|
23
23
|
:banner => "Attribute name of a CouchDB doc to describe its type"
|
24
24
|
|
25
25
|
class_option "version",
|
@@ -47,7 +47,12 @@ module Chillfile
|
|
47
47
|
|
48
48
|
desc 'sync', 'sync filesystem into db'
|
49
49
|
def sync
|
50
|
-
|
50
|
+
progressbar = lambda do |info, notifier|
|
51
|
+
pbar = ::ProgressBar.new("#{info[:name]} (#{info[:size]})", info[:size])
|
52
|
+
notifier.call(lambda{ pbar.inc })
|
53
|
+
pbar.finish
|
54
|
+
end
|
55
|
+
Chillfile.sync!(progressbar)
|
51
56
|
end
|
52
57
|
|
53
58
|
desc 'fslist', 'json list of files in the filesystem'
|
data/lib/chillfile/sync.rb
CHANGED
@@ -1,49 +1,54 @@
|
|
1
1
|
module Chillfile
|
2
2
|
module Sync
|
3
3
|
class << self
|
4
|
-
def process!(comparator)
|
4
|
+
def process!(comparator, progressbar = nil)
|
5
|
+
@progressbar = progressbar
|
5
6
|
|
6
|
-
#
|
7
|
-
comparator.
|
7
|
+
# deleted
|
8
|
+
process_list(comparator.deleted, "Delete") do |checksum, path|
|
8
9
|
for_doc_with(checksum) do |doc|
|
9
|
-
if doc
|
10
|
-
|
10
|
+
if doc.paths.size > 1
|
11
|
+
update_doc_paths(doc, [path])
|
11
12
|
else
|
12
|
-
|
13
|
+
delete_doc(doc)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
# moved files
|
18
|
-
comparator.moved
|
19
|
+
process_list(comparator.moved, "Move") do |checksum, paths|
|
19
20
|
for_doc_with(checksum) do |doc|
|
20
21
|
update_doc_paths(doc, paths[:old_paths], paths[:new_paths])
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
# modified files
|
25
|
-
comparator.modified
|
26
|
+
process_list(comparator.modified, "Modify") do |path, checksums|
|
26
27
|
for_doc_with(checksums[:old_checksum]) do |doc|
|
27
|
-
|
28
|
+
|
28
29
|
# split it up if there is more than one path
|
29
30
|
if doc.paths.size > 1
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
|
32
|
+
# remove the old path from the list
|
33
|
+
base_doc = update_doc_paths(doc, [path])
|
34
|
+
|
35
|
+
# new forked doc
|
36
|
+
fork_doc = create_doc(checksums[:new_checksum], path)
|
37
|
+
|
38
|
+
[base_doc, fork_doc]
|
34
39
|
else
|
35
|
-
update_doc_attachment(doc)
|
40
|
+
update_doc_attachment(doc, checksums[:new_checksum])
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
39
|
-
|
40
|
-
#
|
41
|
-
comparator.
|
44
|
+
|
45
|
+
# created files
|
46
|
+
process_list(comparator.created, "Create") do |checksum, path|
|
42
47
|
for_doc_with(checksum) do |doc|
|
43
|
-
if doc
|
44
|
-
|
48
|
+
if doc
|
49
|
+
update_doc_add_path(doc, path)
|
45
50
|
else
|
46
|
-
|
51
|
+
create_doc(checksum, path)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -66,12 +71,10 @@ module Chillfile
|
|
66
71
|
|
67
72
|
# COPIED
|
68
73
|
def update_doc_add_path(doc, path)
|
69
|
-
doc
|
70
|
-
|
71
|
-
doc
|
74
|
+
update_doc_paths(doc, [], [path])
|
72
75
|
end
|
73
76
|
|
74
|
-
# MOVED
|
77
|
+
# MOVED/COPIED
|
75
78
|
def update_doc_paths(doc, del_paths = [], add_paths = [])
|
76
79
|
# del old paths
|
77
80
|
del_paths.each do |path|
|
@@ -85,8 +88,8 @@ module Chillfile
|
|
85
88
|
end
|
86
89
|
|
87
90
|
# MODIFIED
|
88
|
-
def update_doc_attachment(doc)
|
89
|
-
doc.checksum =
|
91
|
+
def update_doc_attachment(doc, new_checksum)
|
92
|
+
doc.checksum = new_checksum
|
90
93
|
begin
|
91
94
|
file = File.open(doc.paths.first)
|
92
95
|
doc.update_attachment(:file => file, :name => "master")
|
@@ -101,7 +104,25 @@ module Chillfile
|
|
101
104
|
doc.deleted = true
|
102
105
|
doc.paths = []
|
103
106
|
doc
|
104
|
-
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# wrapper outer
|
110
|
+
def process_list(list, title, &block)
|
111
|
+
return true if list.empty?
|
112
|
+
|
113
|
+
list_iterator = lambda do |notifier|
|
114
|
+
list.each do |args|
|
115
|
+
block.call(*args)
|
116
|
+
end
|
117
|
+
notifier.call if notifier
|
118
|
+
end
|
119
|
+
|
120
|
+
if @progressbar
|
121
|
+
@progressbar.call({:name => title, :size => list.size}, list_iterator)
|
122
|
+
else
|
123
|
+
list_iterator.call(nil)
|
124
|
+
end
|
125
|
+
end
|
105
126
|
|
106
127
|
# wrapper
|
107
128
|
def for_doc_with(checksum, &block)
|
data/lib/chillfile.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require "yaml"
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
|
5
|
+
# LIB
|
4
6
|
require "couchrest"
|
5
7
|
require 'couchrest_model'
|
6
8
|
require "treedisha"
|
7
9
|
require "json"
|
10
|
+
|
11
|
+
# CLI
|
8
12
|
require "thor"
|
13
|
+
require "progressbar"
|
9
14
|
|
10
15
|
require File.join(File.dirname(__FILE__), "chillfile/config")
|
11
16
|
require File.join(File.dirname(__FILE__), "chillfile/cli")
|
@@ -27,7 +32,7 @@ module Chillfile
|
|
27
32
|
Chillfile::Model.load!
|
28
33
|
true
|
29
34
|
end
|
30
|
-
|
35
|
+
|
31
36
|
def config
|
32
37
|
@@config
|
33
38
|
end
|
@@ -35,12 +40,12 @@ module Chillfile
|
|
35
40
|
@@dbserver.default_database
|
36
41
|
end
|
37
42
|
|
38
|
-
def sync!
|
43
|
+
def sync!(progressbar = nil)
|
39
44
|
fs = fs_list
|
40
45
|
db = db_list
|
41
46
|
comparator = Treedisha::Comparator.new(fs_list, db_list)
|
42
47
|
|
43
|
-
Chillfile::Sync.process!(comparator)
|
48
|
+
Chillfile::Sync.process!(comparator, progressbar)
|
44
49
|
end
|
45
50
|
|
46
51
|
# filesystem
|
@@ -1 +1,10 @@
|
|
1
|
-
[["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./bar.1.moved.untouched"],
|
1
|
+
[["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./bar.1.moved.untouched"],
|
2
|
+
["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./bar.2.moved.copy"],
|
3
|
+
["da39a3ee5e6b4b0d3255bfef95601890afd80709", "./bar.3.moved.copy"],
|
4
|
+
["83a4f6db0964dd03480be5f781eec6c5c2f7f5f2", "./foo.fx.copy"],
|
5
|
+
["83a4f6db0964dd03480be5f781eec6c5c2f7f5f2", "./foo.untouched"],
|
6
|
+
["cd84598b6fcb747a2b1954934b964e5a5c27836e", "./moo.new"],
|
7
|
+
["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./subdir_b/bar.4.moved.copy"],
|
8
|
+
["33772e8f45b1afd7b0cefa5bc39912a1e782c343", "./baz.modified.single"],
|
9
|
+
["08a7dd9727c92398f3259a677c2b7e821606db4c", "./modified/biz.0.modified.multi"],
|
10
|
+
["08a7dd9727c92398f3259a677c2b7e821606db4c", "./modified/biz.1.modified.multi"]]
|
@@ -1 +1,7 @@
|
|
1
|
-
[["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./bar.0.moved.deleted"],
|
1
|
+
[["ab4b262b83ad979d10a2c3c633242bb222ba74e7", "./bar.0.moved.deleted"],
|
2
|
+
["da39a3ee5e6b4b0d3255bfef95601890afd80709", "./bar.1.moved.untouched"],
|
3
|
+
["83a4f6db0964dd03480be5f781eec6c5c2f7f5f2", "./foo.untouched"],
|
4
|
+
["5ab7aa2b4aaa458fd89089ce4384102a33bf7765", "./subdir/mii.deleted"],
|
5
|
+
["c0ae0100acd4b0063535dd8fbbdf87919741e320", "./wuu.deleted"],
|
6
|
+
["236788602d9b00710e4ece24dc202165c28b7dc4", "./baz.modified.single"],
|
7
|
+
["4e719bc39c20b4c2633265406a1074db39e88c65", "./modified/biz.0.modified.multi"]]
|
data/version.yml
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- dpree
|
@@ -85,8 +85,21 @@ dependencies:
|
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: *id005
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
88
|
+
name: ruby-progressbar
|
89
89
|
requirement: &id006 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
type: :runtime
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: *id006
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: thor
|
102
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
90
103
|
none: false
|
91
104
|
requirements:
|
92
105
|
- - ~>
|
@@ -98,10 +111,10 @@ dependencies:
|
|
98
111
|
version: 0.14.6
|
99
112
|
type: :runtime
|
100
113
|
prerelease: false
|
101
|
-
version_requirements: *
|
114
|
+
version_requirements: *id007
|
102
115
|
- !ruby/object:Gem::Dependency
|
103
116
|
name: couchrest
|
104
|
-
requirement: &
|
117
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
105
118
|
none: false
|
106
119
|
requirements:
|
107
120
|
- - ~>
|
@@ -113,10 +126,10 @@ dependencies:
|
|
113
126
|
version: 1.0.1
|
114
127
|
type: :runtime
|
115
128
|
prerelease: false
|
116
|
-
version_requirements: *
|
129
|
+
version_requirements: *id008
|
117
130
|
- !ruby/object:Gem::Dependency
|
118
131
|
name: treedisha
|
119
|
-
requirement: &
|
132
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
120
133
|
none: false
|
121
134
|
requirements:
|
122
135
|
- - ~>
|
@@ -128,10 +141,10 @@ dependencies:
|
|
128
141
|
version: 0.0.2
|
129
142
|
type: :runtime
|
130
143
|
prerelease: false
|
131
|
-
version_requirements: *
|
144
|
+
version_requirements: *id009
|
132
145
|
- !ruby/object:Gem::Dependency
|
133
146
|
name: rspec
|
134
|
-
requirement: &
|
147
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
135
148
|
none: false
|
136
149
|
requirements:
|
137
150
|
- - ~>
|
@@ -143,7 +156,7 @@ dependencies:
|
|
143
156
|
version: 2.0.0
|
144
157
|
type: :development
|
145
158
|
prerelease: false
|
146
|
-
version_requirements: *
|
159
|
+
version_requirements: *id010
|
147
160
|
description: Let your files chill on the couch
|
148
161
|
email: whiterabbit.init@gmail.com
|
149
162
|
executables:
|
@@ -174,13 +187,18 @@ files:
|
|
174
187
|
- spec/filesystem_after/bar.1.moved.untouched
|
175
188
|
- spec/filesystem_after/bar.2.moved.copy
|
176
189
|
- spec/filesystem_after/bar.3.moved.copy
|
190
|
+
- spec/filesystem_after/baz.modified.single
|
177
191
|
- spec/filesystem_after/foo.fx.copy
|
178
192
|
- spec/filesystem_after/foo.untouched
|
193
|
+
- spec/filesystem_after/modified/biz.0.modified.multi
|
194
|
+
- spec/filesystem_after/modified/biz.1.modified.multi
|
179
195
|
- spec/filesystem_after/moo.new
|
180
196
|
- spec/filesystem_after/subdir_b/bar.4.moved.copy
|
181
197
|
- spec/filesystem_before/bar.0.moved.deleted
|
182
198
|
- spec/filesystem_before/bar.1.moved.untouched
|
199
|
+
- spec/filesystem_before/baz.modified.single
|
183
200
|
- spec/filesystem_before/foo.untouched
|
201
|
+
- spec/filesystem_before/modified/biz.0.modified.multi
|
184
202
|
- spec/filesystem_before/subdir/mii.deleted
|
185
203
|
- spec/filesystem_before/wuu.deleted
|
186
204
|
- spec/fixtures/filesystem_after.json
|