pho 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +21 -0
- data/README +1 -2
- data/Rakefile +1 -1
- data/bin/talis_store +13 -22
- data/doc/rdoc/classes/Pho/CommandLine.html +162 -124
- data/doc/rdoc/classes/Pho/DatatypeProperty.html +12 -12
- data/doc/rdoc/classes/Pho/Enrichment/StoreEnricher.html +29 -29
- data/doc/rdoc/classes/Pho/Etags.html +36 -36
- data/doc/rdoc/classes/Pho/Facet/Results.html +19 -19
- data/doc/rdoc/classes/Pho/Facet/Term.html +6 -6
- data/doc/rdoc/classes/Pho/FieldPredicateMap.html +102 -102
- data/doc/rdoc/classes/Pho/FieldWeighting.html +12 -12
- data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +262 -103
- data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +34 -14
- data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +10 -5
- data/doc/rdoc/classes/Pho/Job.html +64 -64
- data/doc/rdoc/classes/Pho/Jobs.html +60 -60
- data/doc/rdoc/classes/Pho/OAI/Record.html +6 -6
- data/doc/rdoc/classes/Pho/OAI/Records.html +24 -24
- data/doc/rdoc/classes/Pho/OAI/Statistics.html +12 -12
- data/doc/rdoc/classes/Pho/QueryProfile.html +66 -66
- data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +36 -36
- data/doc/rdoc/classes/Pho/ResourceHash/SetAlgebra.html +12 -12
- data/doc/rdoc/classes/Pho/Snapshot.html +35 -35
- data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +74 -74
- data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +78 -78
- data/doc/rdoc/classes/Pho/Status.html +26 -26
- data/doc/rdoc/classes/Pho/Store.html +215 -215
- data/doc/rdoc/classes/Pho/StoreSparqlClient.html +12 -12
- data/doc/rdoc/classes/Pho/Update/Changeset.html +63 -63
- data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +24 -24
- data/doc/rdoc/classes/Pho/Update/ChangesetHelper.html +6 -6
- data/doc/rdoc/classes/Pho/Update/Changesets.html +12 -12
- data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +18 -18
- data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +24 -24
- data/doc/rdoc/classes/Pho/Update/Statement.html +24 -24
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +34 -1
- data/doc/rdoc/files/README.html +3 -4
- data/doc/rdoc/files/lib/pho/command_line_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_management_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_manager_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +1 -1
- data/doc/rdoc/fr_method_index.html +212 -205
- data/lib/pho/command_line.rb +29 -11
- data/lib/pho/file_management.rb +85 -29
- data/lib/pho/file_manager.rb +10 -11
- data/lib/pho/rdf_collection.rb +8 -3
- data/tests/tc_file_manager.rb +144 -26
- data/tests/tc_rdf_collection.rb +76 -68
- metadata +4 -4
data/lib/pho/command_line.rb
CHANGED
@@ -149,10 +149,12 @@ module Pho
|
|
149
149
|
resp = @store.store_file( f )
|
150
150
|
end
|
151
151
|
elsif @opts["dir"]
|
152
|
+
if @opts["dir"] = "."
|
153
|
+
@opts["dir"] = File.expand_path(".")
|
154
|
+
end
|
152
155
|
puts "Storing contents of directory: #{@opts["dir"]}"
|
153
|
-
collection = Pho::RDFCollection.new(@store, @opts["dir"])
|
154
|
-
collection
|
155
|
-
puts collection.summary()
|
156
|
+
collection = Pho::RDFCollection.new(@store, @opts["dir"])
|
157
|
+
store_collection(collection)
|
156
158
|
else
|
157
159
|
#noop
|
158
160
|
end
|
@@ -177,15 +179,11 @@ module Pho
|
|
177
179
|
puts "Uploading file: #{ @opts["file"] } to /items/#{ uri } as #{mime}"
|
178
180
|
resp = @store.upload_item( f , mime , uri )
|
179
181
|
elsif @opts["dir"]
|
180
|
-
|
182
|
+
if @opts["dir"] = "."
|
183
|
+
@opts["dir"] = File.expand_path(".")
|
184
|
+
end
|
181
185
|
collection = Pho::FileManagement::FileManager.new(@store, @opts["dir"], @opts["base"])
|
182
|
-
|
183
|
-
collection.store(:traverse)
|
184
|
-
puts collection.summary(:traverse)
|
185
|
-
else
|
186
|
-
collection.store()
|
187
|
-
puts collection.summary()
|
188
|
-
end
|
186
|
+
store_collection(collection)
|
189
187
|
else
|
190
188
|
#noop
|
191
189
|
end
|
@@ -200,6 +198,26 @@ module Pho
|
|
200
198
|
end
|
201
199
|
end
|
202
200
|
|
201
|
+
def store_collection(collection)
|
202
|
+
if @opts["force"]
|
203
|
+
puts "Resetting tracking files for directory #{@opts["dir"]}"
|
204
|
+
collection.reset( @opts["traverse"] ? true : false )
|
205
|
+
end
|
206
|
+
if @opts["retry"]
|
207
|
+
puts "Retrying failures in: #{@opts["dir"]}"
|
208
|
+
collection.retry_failures( @opts["traverse"] ? true : false )
|
209
|
+
puts collection.summary( @opts["traverse"] ? true : false )
|
210
|
+
elsif @opts["updates"]
|
211
|
+
puts "Uploading updates in: #{@opts["dir"]}"
|
212
|
+
collection.store_updates( @opts["traverse"] ? true : false )
|
213
|
+
puts collection.summary( @opts["traverse"] ? true : false )
|
214
|
+
else
|
215
|
+
puts "Uploading contents of directory: #{@opts["dir"]}"
|
216
|
+
collection.store( @opts["traverse"] ? true : false )
|
217
|
+
puts collection.summary( @opts["traverse"] ? true : false )
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
203
221
|
def fpmap(out=$stdout)
|
204
222
|
|
205
223
|
if @opts["raw"]
|
data/lib/pho/file_management.rb
CHANGED
@@ -2,19 +2,18 @@ module Pho
|
|
2
2
|
|
3
3
|
module FileManagement
|
4
4
|
|
5
|
-
#TODO: move files into hidden directory
|
6
5
|
class AbstractFileManager
|
7
6
|
|
8
7
|
attr_reader :dir
|
9
8
|
attr_reader :store
|
10
9
|
|
11
|
-
OK = "ok"
|
12
|
-
FAIL = "fail"
|
10
|
+
OK = "ok"
|
11
|
+
FAIL = "fail"
|
12
|
+
TRACKING_DIR = ".pho"
|
13
13
|
|
14
|
-
def initialize(store, dir, ok_suffix=OK, fail_suffix=FAIL
|
14
|
+
def initialize(store, dir, ok_suffix=OK, fail_suffix=FAIL)
|
15
15
|
@store = store
|
16
16
|
@dir = dir
|
17
|
-
@sleep = sleep
|
18
17
|
@ok_suffix = ok_suffix
|
19
18
|
@fail_suffix = fail_suffix
|
20
19
|
end
|
@@ -29,8 +28,8 @@ module Pho
|
|
29
28
|
end
|
30
29
|
|
31
30
|
#Retry anything known to have failed
|
32
|
-
def retry_failures()
|
33
|
-
retries = failures()
|
31
|
+
def retry_failures(recursive=false)
|
32
|
+
retries = failures(recursive)
|
34
33
|
retries.each do |filename|
|
35
34
|
File.delete( get_fail_file_for(filename) )
|
36
35
|
#store it
|
@@ -38,28 +37,85 @@ module Pho
|
|
38
37
|
store_file(file, filename)
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
40
|
+
|
41
|
+
def store_changes(recursive=false)
|
42
|
+
changes = changed_files(recursive)
|
43
|
+
changes.each do |filename|
|
44
|
+
#cleanup tracking files
|
45
|
+
f = get_fail_file_for(filename)
|
46
|
+
File.delete( f ) if File.exists?(f)
|
47
|
+
f = get_ok_file_for(filename)
|
48
|
+
File.delete( f ) if File.exists?(f)
|
49
|
+
file = File.new(filename)
|
50
|
+
store_file(file, filename)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
42
54
|
#Reset the directory to clear out any previous statuses
|
43
|
-
def reset()
|
44
|
-
|
55
|
+
def reset(recursive=false)
|
56
|
+
if recursive
|
57
|
+
pattern = "**/#{TRACKING_DIR}/*"
|
58
|
+
else
|
59
|
+
pattern = "/#{TRACKING_DIR}/*"
|
60
|
+
end
|
61
|
+
Dir.glob( File.join(@dir, "#{pattern}.#{@fail_suffix}") ).each do |file|
|
45
62
|
File.delete(file)
|
46
63
|
end
|
47
|
-
Dir.glob( File.join(@dir, "
|
64
|
+
Dir.glob( File.join(@dir, "#{pattern}.#{@ok_suffix}") ).each do |file|
|
48
65
|
File.delete(file)
|
49
66
|
end
|
50
67
|
end
|
51
|
-
|
68
|
+
|
69
|
+
#returns true if there is a fail or ok file, false otherwise
|
70
|
+
def stored?(file)
|
71
|
+
ok_file = get_ok_file_for(file)
|
72
|
+
fail_file = get_fail_file_for(file)
|
73
|
+
if ( File.exists?(ok_file) or File.exists?(fail_file) )
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
|
79
|
+
#Has this file changed (i.e have a newer mtime) than its tracking file
|
80
|
+
#Allows files that have been updated in a collection to be easily identified
|
81
|
+
#New files (i.e untracked) are always considered to be changed
|
82
|
+
def changed?(file)
|
83
|
+
if !stored?(file)
|
84
|
+
return true
|
85
|
+
end
|
86
|
+
ok_file = get_ok_file_for(file)
|
87
|
+
fail_file = get_fail_file_for(file)
|
88
|
+
f = File.new(file)
|
89
|
+
if (
|
90
|
+
( File.exists?(ok_file) && f.stat.mtime > File.new(ok_file).stat.mtime ) or
|
91
|
+
( File.exists?(fail_file) && f.stat.mtime > File.new(fail_file).stat.mtime )
|
92
|
+
)
|
93
|
+
return true
|
94
|
+
end
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
|
98
|
+
def stored_files(recursive=false)
|
99
|
+
stored = Array.new
|
100
|
+
list(recursive).each do |file|
|
101
|
+
stored << file if stored?(file)
|
102
|
+
end
|
103
|
+
return stored
|
104
|
+
end
|
105
|
+
|
106
|
+
def changed_files(recursive=false)
|
107
|
+
changed = Array.new
|
108
|
+
list(recursive).each do |file|
|
109
|
+
changed << file if changed?(file)
|
110
|
+
end
|
111
|
+
return changed
|
112
|
+
end
|
113
|
+
|
52
114
|
#List any new files in the directory
|
53
115
|
def new_files(recursive=false)
|
54
116
|
newfiles = Array.new
|
55
117
|
list(recursive).each do |file|
|
56
|
-
|
57
|
-
ok_file = get_ok_file_for(file)
|
58
|
-
fail_file = get_fail_file_for(file)
|
59
|
-
if !( File.exists?(ok_file) or File.exists?(fail_file) )
|
60
|
-
newfiles << file
|
61
|
-
end
|
62
|
-
|
118
|
+
newfiles << file if !stored?(file)
|
63
119
|
end
|
64
120
|
return newfiles
|
65
121
|
end
|
@@ -68,9 +124,7 @@ module Pho
|
|
68
124
|
def failures(recursive=false)
|
69
125
|
fails = Array.new
|
70
126
|
list(recursive).each do |file|
|
71
|
-
|
72
|
-
fails << file if File.exists?( get_fail_file_for(file) )
|
73
|
-
end
|
127
|
+
fails << file if File.exists?( get_fail_file_for(file) )
|
74
128
|
end
|
75
129
|
return fails
|
76
130
|
end
|
@@ -79,9 +133,7 @@ module Pho
|
|
79
133
|
def successes(recursive=false)
|
80
134
|
successes = Array.new
|
81
135
|
list(recursive).each do |file|
|
82
|
-
|
83
|
-
successes << file if File.exists?( get_ok_file_for(file) )
|
84
|
-
end
|
136
|
+
successes << file if File.exists?( get_ok_file_for(file) )
|
85
137
|
end
|
86
138
|
return successes
|
87
139
|
end
|
@@ -98,13 +150,17 @@ module Pho
|
|
98
150
|
end
|
99
151
|
|
100
152
|
def get_fail_file_for(filename)
|
101
|
-
|
102
|
-
|
153
|
+
relative_path = filename.gsub(@dir, "")
|
154
|
+
base = File.basename(filename)
|
155
|
+
relative_path = relative_path.gsub(base, "#{TRACKING_DIR}/#{base}")
|
156
|
+
return "#{@dir}#{relative_path}.#{@fail_suffix}"
|
103
157
|
end
|
104
158
|
|
105
159
|
def get_ok_file_for(filename)
|
106
|
-
|
107
|
-
|
160
|
+
relative_path = filename.gsub(@dir, "")
|
161
|
+
base = File.basename(filename)
|
162
|
+
relative_path = relative_path.gsub(base, "#{TRACKING_DIR}/#{base}")
|
163
|
+
return "#{@dir}#{relative_path}.#{@ok_suffix}"
|
108
164
|
end
|
109
165
|
|
110
166
|
end
|
data/lib/pho/file_manager.rb
CHANGED
@@ -8,25 +8,19 @@ module Pho
|
|
8
8
|
|
9
9
|
attr_reader :base
|
10
10
|
|
11
|
-
def initialize(store, dir, base = nil, ok_suffix=OK, fail_suffix=FAIL
|
12
|
-
super(store, dir, ok_suffix, fail_suffix
|
11
|
+
def initialize(store, dir, base = nil, ok_suffix=OK, fail_suffix=FAIL)
|
12
|
+
super(store, dir, ok_suffix, fail_suffix)
|
13
13
|
@base = base
|
14
14
|
end
|
15
15
|
|
16
16
|
#List files being managed, i.e. everything not .ok or .fail
|
17
17
|
def list(recursive=false)
|
18
|
-
files = []
|
19
18
|
if recursive
|
20
|
-
pattern = "
|
19
|
+
pattern = "**/*.*"
|
21
20
|
else
|
22
|
-
pattern = "
|
21
|
+
pattern = "*.*"
|
23
22
|
end
|
24
|
-
Dir.glob( File.join(@dir, pattern) )
|
25
|
-
if File.extname(file) != ".#{@ok_suffix}" && File.extname(file) != ".#{@fail_suffix}" && !File.directory?(file)
|
26
|
-
files << file
|
27
|
-
end
|
28
|
-
end
|
29
|
-
return files
|
23
|
+
return Dir.glob( File.join(@dir, pattern) )
|
30
24
|
end
|
31
25
|
|
32
26
|
def FileManager.name_for_file(dir, file, base=nil)
|
@@ -40,6 +34,7 @@ module Pho
|
|
40
34
|
def store_file(file, filename)
|
41
35
|
uri = FileManager.name_for_file(@dir, file, @base)
|
42
36
|
response = @store.upload_item(file, MIME::Types.type_for(filename)[0].to_s, uri )
|
37
|
+
create_tracking_dir(filename)
|
43
38
|
if (response.status < 300 )
|
44
39
|
File.open(get_ok_file_for(filename), "w") do |file|
|
45
40
|
file.print( "OK" )
|
@@ -51,6 +46,10 @@ module Pho
|
|
51
46
|
end
|
52
47
|
end
|
53
48
|
|
49
|
+
def create_tracking_dir(filename)
|
50
|
+
path = filename.split("/")[0..-2].join("/")
|
51
|
+
Dir.mkdir("#{path}/#{TRACKING_DIR}") unless File.exists?("#{path}/#{TRACKING_DIR}")
|
52
|
+
end
|
54
53
|
end
|
55
54
|
|
56
55
|
end
|
data/lib/pho/rdf_collection.rb
CHANGED
@@ -14,14 +14,19 @@ module Pho
|
|
14
14
|
|
15
15
|
ALL_RDF = [RDF, TTL, NT]
|
16
16
|
|
17
|
-
def initialize(store, dir, rdf_suffixes=ALL_RDF, ok_suffix=OK, fail_suffix=FAIL
|
18
|
-
super(store, dir, ok_suffix, fail_suffix
|
17
|
+
def initialize(store, dir, rdf_suffixes=ALL_RDF, ok_suffix=OK, fail_suffix=FAIL)
|
18
|
+
super(store, dir, ok_suffix, fail_suffix)
|
19
19
|
@rdf_suffixes = rdf_suffixes
|
20
20
|
end
|
21
21
|
|
22
22
|
#List files being managed
|
23
23
|
def list(recursive=false)
|
24
|
-
|
24
|
+
if recursive
|
25
|
+
pattern = "**/*.\{#{ @rdf_suffixes.join(",") }\}"
|
26
|
+
else
|
27
|
+
pattern = "*.\{#{ @rdf_suffixes.join(",") }\}"
|
28
|
+
end
|
29
|
+
return Dir.glob( File.join(@dir, pattern) )
|
25
30
|
end
|
26
31
|
|
27
32
|
protected
|
data/tests/tc_file_manager.rb
CHANGED
@@ -6,33 +6,40 @@ require 'mocha'
|
|
6
6
|
class FileManagerTest < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def setup()
|
9
|
-
Dir.mkdir("/tmp/pho") unless File.exists?("/tmp/pho")
|
10
|
-
Dir.mkdir("/tmp/pho
|
11
|
-
|
9
|
+
Dir.mkdir("/tmp/pho") unless File.exists?("/tmp/pho")
|
10
|
+
Dir.mkdir("/tmp/pho/.pho") unless File.exists?("/tmp/pho/.pho")
|
11
|
+
|
12
|
+
Dir.mkdir("/tmp/pho/a") unless File.exists?("/tmp/pho/a")
|
13
|
+
Dir.mkdir("/tmp/pho/b") unless File.exists?("/tmp/pho/b")
|
14
|
+
|
15
|
+
#/tmp/pho/[0-6].css
|
12
16
|
7.times do |i|
|
13
17
|
file = File.new( File.join("/tmp/pho", "#{i}.css"), "w" )
|
14
18
|
file.write("CSS#{i}")
|
15
19
|
file.close()
|
16
20
|
end
|
21
|
+
#/tmp/pho/[7-9].js
|
17
22
|
3.times do |i|
|
18
23
|
num = i + 7
|
19
24
|
file = File.new( File.join("/tmp/pho", "#{num}.js"), "w" )
|
20
25
|
file.write("JS#{num}")
|
21
26
|
file.close()
|
22
27
|
end
|
28
|
+
#/tmp/pho/.pho/[0-3].ok
|
23
29
|
4.times do |i|
|
24
|
-
file = File.new( File.join("/tmp/pho", "#{i}.ok"), "w" )
|
30
|
+
file = File.new( File.join("/tmp/pho/.pho", "#{i}.css.ok"), "w" )
|
25
31
|
file.write("OK")
|
26
32
|
file.close()
|
27
33
|
end
|
34
|
+
#/tmp/pho/.pho/[4-6].fail
|
28
35
|
3.times do |i|
|
29
36
|
num = 4 + i
|
30
|
-
file = File.new( File.join("/tmp/pho", "#{num}.fail"), "w" )
|
37
|
+
file = File.new( File.join("/tmp/pho/.pho", "#{num}.css.fail"), "w" )
|
31
38
|
file.write("FAIL")
|
32
39
|
file.close()
|
33
40
|
end
|
34
41
|
|
35
|
-
#/tmp/pho/a
|
42
|
+
#/tmp/pho/a/[0-1].txt
|
36
43
|
2.times do |i|
|
37
44
|
num = i
|
38
45
|
file = File.new( File.join("/tmp/pho/a", "#{num}.txt"), "w" )
|
@@ -40,7 +47,7 @@ class FileManagerTest < Test::Unit::TestCase
|
|
40
47
|
file.close()
|
41
48
|
end
|
42
49
|
|
43
|
-
#/tmp/pho/b
|
50
|
+
#/tmp/pho/b/0.txt
|
44
51
|
1.times do |i|
|
45
52
|
num = i
|
46
53
|
file = File.new( File.join("/tmp/pho/b", "#{num}.txt"), "w" )
|
@@ -51,23 +58,101 @@ class FileManagerTest < Test::Unit::TestCase
|
|
51
58
|
end
|
52
59
|
|
53
60
|
def teardown()
|
54
|
-
Dir.glob("/tmp/pho
|
61
|
+
Dir.glob("/tmp/pho/*.*") do |file|
|
55
62
|
File.delete(file)
|
56
63
|
end
|
57
|
-
Dir.glob("/tmp/pho
|
64
|
+
Dir.glob("/tmp/pho/.pho/*.*") do |file|
|
58
65
|
File.delete(file)
|
59
|
-
end
|
60
|
-
Dir.glob("/tmp/pho
|
66
|
+
end
|
67
|
+
Dir.glob("/tmp/pho/a/.pho/*.*") do |file|
|
61
68
|
File.delete(file)
|
62
69
|
end
|
63
|
-
Dir.glob("/tmp/pho
|
70
|
+
Dir.glob("/tmp/pho/b/.pho/*.*") do |file|
|
64
71
|
File.delete(file)
|
65
72
|
end
|
66
|
-
Dir.glob("/tmp/pho
|
73
|
+
Dir.glob("/tmp/pho/a/*.*") do |file|
|
67
74
|
File.delete(file)
|
68
|
-
end
|
75
|
+
end
|
76
|
+
Dir.glob("/tmp/pho/b/*.*") do |file|
|
77
|
+
File.delete(file)
|
78
|
+
end
|
79
|
+
|
80
|
+
delete("/tmp/pho/a/.pho")
|
81
|
+
delete("/tmp/pho/b/.pho")
|
82
|
+
delete("/tmp/pho/a")
|
83
|
+
delete("/tmp/pho/b")
|
84
|
+
delete("/tmp/pho/.pho")
|
85
|
+
delete("/tmp/pho")
|
69
86
|
end
|
70
87
|
|
88
|
+
def delete(dir)
|
89
|
+
Dir.delete(dir) if File.exists?(dir)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_get_ok_file_for()
|
93
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
94
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
95
|
+
assert_equal( "/tmp/pho/.pho/0.css.ok", collection.get_ok_file_for("/tmp/pho/0.css") )
|
96
|
+
assert_equal( "/tmp/pho/a/.pho/0.txt.ok", collection.get_ok_file_for("/tmp/pho/a/0.txt") )
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_get_fail_file_for()
|
100
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
101
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
102
|
+
assert_equal( "/tmp/pho/.pho/0.css.fail", collection.get_fail_file_for("/tmp/pho/0.css") )
|
103
|
+
assert_equal( "/tmp/pho/a/.pho/0.txt.fail", collection.get_fail_file_for("/tmp/pho/a/0.txt") )
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_stored()
|
107
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
108
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
109
|
+
7.times do |i|
|
110
|
+
assert_equal( true, collection.stored?("/tmp/pho/#{i}.css"), "#{i}.css should be stored" )
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_changed()
|
116
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
117
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
118
|
+
7.times do |i|
|
119
|
+
assert_equal( false, collection.changed?("/tmp/pho/#{i}.css"), "#{i}.css should not be changed" )
|
120
|
+
end
|
121
|
+
|
122
|
+
sleep(1)
|
123
|
+
#check we're not creating it with the touch
|
124
|
+
assert_equal( true, File.exists?("/tmp/pho/0.css") )
|
125
|
+
FileUtils.touch( "/tmp/pho/0.css")
|
126
|
+
assert_equal( true, collection.changed?("/tmp/pho/0.css") )
|
127
|
+
#other files are unchanged
|
128
|
+
6.times do |i|
|
129
|
+
assert_equal( false, collection.changed?("/tmp/pho/#{i+1}.css"), "#{i+1}.css should not be changed" )
|
130
|
+
end
|
131
|
+
#untracked files are also changed
|
132
|
+
3.times do |i|
|
133
|
+
assert_equal( true, collection.changed?("/tmp/pho/#{i+7}.js"), "#{i+7}.js should not be changed" )
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_changed_files()
|
139
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
140
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
141
|
+
changed = collection.changed_files()
|
142
|
+
assert_equal( 3, changed.size )
|
143
|
+
|
144
|
+
sleep(1)
|
145
|
+
#check we're not creating it with the touch
|
146
|
+
assert_equal( true, File.exists?("/tmp/pho/0.css") )
|
147
|
+
FileUtils.touch( "/tmp/pho/0.css")
|
148
|
+
|
149
|
+
changed = collection.changed_files()
|
150
|
+
changed.sort!
|
151
|
+
assert_equal( 4, changed.size )
|
152
|
+
assert_equal( "/tmp/pho/0.css", changed[0] )
|
153
|
+
|
154
|
+
end
|
155
|
+
|
71
156
|
def test_new_files()
|
72
157
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
73
158
|
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
@@ -110,9 +195,9 @@ class FileManagerTest < Test::Unit::TestCase
|
|
110
195
|
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
111
196
|
collection.store()
|
112
197
|
|
113
|
-
assert_equal(true, File.exists?("/tmp/pho/7.ok") )
|
114
|
-
assert_equal(true, File.exists?("/tmp/pho/8.ok") )
|
115
|
-
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
198
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/7.js.ok") )
|
199
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/8.js.ok") )
|
200
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/9.js.ok") )
|
116
201
|
|
117
202
|
end
|
118
203
|
|
@@ -128,9 +213,9 @@ class FileManagerTest < Test::Unit::TestCase
|
|
128
213
|
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho", "assets")
|
129
214
|
collection.store()
|
130
215
|
|
131
|
-
assert_equal(true, File.exists?("/tmp/pho/7.ok") )
|
132
|
-
assert_equal(true, File.exists?("/tmp/pho/8.ok") )
|
133
|
-
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
216
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/7.js.ok") )
|
217
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/8.js.ok") )
|
218
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/9.js.ok") )
|
134
219
|
|
135
220
|
end
|
136
221
|
|
@@ -150,12 +235,12 @@ class FileManagerTest < Test::Unit::TestCase
|
|
150
235
|
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
151
236
|
collection.store(:recursive)
|
152
237
|
|
153
|
-
assert_equal(true, File.exists?("/tmp/pho/7.ok") )
|
154
|
-
assert_equal(true, File.exists?("/tmp/pho/8.ok") )
|
155
|
-
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
156
|
-
assert_equal(true, File.exists?("/tmp/pho/a/0.ok") )
|
157
|
-
assert_equal(true, File.exists?("/tmp/pho/a/1.ok") )
|
158
|
-
assert_equal(true, File.exists?("/tmp/pho/b/0.ok") )
|
238
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/7.js.ok") )
|
239
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/8.js.ok") )
|
240
|
+
assert_equal(true, File.exists?("/tmp/pho/.pho/9.js.ok") )
|
241
|
+
assert_equal(true, File.exists?("/tmp/pho/a/.pho/0.txt.ok") )
|
242
|
+
assert_equal(true, File.exists?("/tmp/pho/a/.pho/1.txt.ok") )
|
243
|
+
assert_equal(true, File.exists?("/tmp/pho/b/.pho/0.txt.ok") )
|
159
244
|
|
160
245
|
end
|
161
246
|
|
@@ -175,4 +260,37 @@ class FileManagerTest < Test::Unit::TestCase
|
|
175
260
|
assert_equal(13, files.size)
|
176
261
|
end
|
177
262
|
|
263
|
+
def test_reset()
|
264
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
265
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
266
|
+
|
267
|
+
collection.reset()
|
268
|
+
newfiles = collection.new_files()
|
269
|
+
assert_equal(10, newfiles.size)
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_reset_recursive()
|
273
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
274
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
275
|
+
|
276
|
+
Dir.mkdir("/tmp/pho/b/.pho") unless File.exists?("/tmp/pho/b/.pho")
|
277
|
+
|
278
|
+
file = File.new( File.join("/tmp/pho/b/.pho", "0.txt.fail"), "w" )
|
279
|
+
file.write("FAIL")
|
280
|
+
file.close()
|
281
|
+
|
282
|
+
files = collection.failures(:recurse)
|
283
|
+
assert_equal(4, files.size)
|
284
|
+
assert_equal( true, files.include?("/tmp/pho/b/0.txt") )
|
285
|
+
|
286
|
+
collection.reset(:recurse)
|
287
|
+
newfiles = collection.new_files(:recurse)
|
288
|
+
assert_equal(13, newfiles.size)
|
289
|
+
assert_equal( true, newfiles.include?("/tmp/pho/b/0.txt") )
|
290
|
+
|
291
|
+
files = collection.failures(:recurse)
|
292
|
+
assert_equal(0, files.size)
|
293
|
+
|
294
|
+
assert_equal( true, !File.exists?("/tmp/pho/b/.pho/0.txt.fail") )
|
295
|
+
end
|
178
296
|
end
|