vtools 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,7 @@ module VTools
13
13
  require 'ostruct'
14
14
  require 'open3'
15
15
  require 'logger'
16
+ require "fileutils"
16
17
 
17
18
  require 'vtools/version'
18
19
  require 'vtools/errors'
@@ -46,9 +46,7 @@ module VTools
46
46
  time = 0.0
47
47
  end
48
48
  progress = time / @video.duration
49
-
50
- # callbacks
51
- Hook.exec :in_convert, @video, progress
49
+ Hook.exec :in_convert, @video, progress # callbacks
52
50
  end
53
51
  end
54
52
  end
@@ -1,7 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
3
  module VTools
4
-
5
4
  # shared methods
6
5
  module SharedMethods
7
6
  # both static & instance bindings
@@ -83,14 +82,22 @@ module VTools
83
82
  generator = instance_exec(file_name, &generator).to_s if generator.is_a? Proc
84
83
  rescue => e
85
84
  generator = nil
86
- raise ConfigError, "Path generator error (#{e})"
85
+ raise ConfigError, "Path generator error: (#{e})"
87
86
  end
88
87
 
89
88
  storage = CONFIG[:"#{scope}_storage"].to_s
90
89
  storage += "/" unless storage.empty?
91
90
  storage += generator || ""
92
91
 
93
- (!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/+#, '/').gsub(%r#/$#, '')
92
+ path = (!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/+#, '/').gsub(%r#/$#, '')
93
+
94
+ # generate path
95
+ begin
96
+ FileUtils.mkdir_p path, :mode => 775
97
+ rescue => e
98
+ raise FileError, "Path generator error: #{e}"
99
+ end unless File.exists?(path)
100
+ path
94
101
  end
95
102
 
96
103
  # path generator setter
@@ -41,7 +41,6 @@ module VTools
41
41
  # save thumb if no error
42
42
  if (error = lines).empty?
43
43
  thumbs << thumb = {:path => file, :offset => time_offset(seconds)}
44
-
45
44
  Hook.exec :in_thumb, @video, thumb # callbacks
46
45
  else
47
46
  errors << "#{error} (#{file})"
@@ -2,5 +2,5 @@
2
2
 
3
3
  # current version
4
4
  module VTools
5
- VERSION = [ 1, 0, 0 ]
5
+ VERSION = [ 1, 0, 1 ]
6
6
  end
@@ -140,7 +140,7 @@ describe VTools::SharedMethods do
140
140
  VTools::CONFIG[:test_index] = "test.value"
141
141
 
142
142
  @class.config(:test_index).should == "test.value"
143
- @class.config(:nonexistent_index).should be nil
143
+ @class.config(:nonexistent_index).should_not be
144
144
  end
145
145
  end
146
146
 
@@ -182,93 +182,135 @@ describe VTools::SharedMethods do
182
182
  end
183
183
  end
184
184
 
185
- context "#generate_path" do
185
+ context "paths generator" do
186
186
 
187
- it "returns valid string" do
188
- VTools::CONFIG[:video_storage] = "test/path/"
189
- VTools::CONFIG[:thumb_storage] = "/thumb/path"
187
+ before do
188
+ VTools::CONFIG[:video_storage] = nil
189
+ VTools::CONFIG[:thumb_storage] = nil
190
+ VTools::CONFIG[:thumb_path_generator] = nil
191
+ VTools::CONFIG[:video_path_generator] = nil
192
+ end
190
193
 
191
- @class.generate_path("test.filename").should == "test/path"
192
- @class.generate_path("test.filename", "thumb").should == "/thumb/path"
194
+ context "#generate_path" do
193
195
 
194
- VTools::CONFIG[:thumb_storage] = ''
196
+ before do
197
+ File.stub(:exists?).and_return(true)
198
+ VTools::CONFIG[:PWD] = ""
199
+ end
195
200
 
196
- VTools::CONFIG[:PWD] = "test/pwd"
197
- @class.generate_path("test.filename", "thumb").should == "test/pwd"
201
+ context "using string path from" do
202
+ it "config storage" do
203
+ VTools::CONFIG[:video_storage] = "test/path/"
204
+ VTools::CONFIG[:thumb_storage] = "/thumb/path"
198
205
 
199
- VTools::CONFIG[:PWD] = nil
200
- VTools::CONFIG[:thumb_storage] = nil
206
+ @class.generate_path("test.filename").should == "test/path"
207
+ @class.generate_path("test.filename", "thumb").should == "/thumb/path"
208
+ end
201
209
 
202
- @class.generate_path("test.filename", "thumb").should == ""
203
- end
210
+ it "CONFIG[:PWD]" do
204
211
 
205
- it "executes block" do
206
- prc = proc do |file|
207
- file.should == "test.filename"
208
- self.class.should == Tested
209
- "test/path"
212
+ VTools::CONFIG[:thumb_storage] = ''
213
+ VTools::CONFIG[:PWD] = "test/pwd"
214
+ @class.generate_path("test.filename", "thumb").should == "test/pwd"
215
+ @class.generate_path("test.filename").should == "test/pwd"
216
+ end
217
+
218
+ it "empty set" do
219
+ @class.generate_path("test.filename").should == ""
220
+ end
210
221
  end
211
222
 
212
- VTools::CONFIG[:video_storage] = '/root/'
213
- VTools::CONFIG[:video_path_generator] = prc
214
- @class.generate_path("test.filename", "video").should == "/root/test/path"
223
+ context "using callback" do
224
+
225
+ let(:failed_prc) { proc { CONFIG[:thumb_storage] } }
226
+ let(:prc) {
227
+ proc do |file|
228
+ file.should == "test.filename"
229
+ self.class.should == Tested
230
+ "test/path"
231
+ end
232
+ }
233
+
234
+
235
+ it "executes block" do
236
+ VTools::CONFIG[:video_storage] = '/root/'
237
+ VTools::CONFIG[:video_path_generator] = prc
238
+ @class.generate_path("test.filename", "video").should == "/root/test/path"
239
+
240
+ VTools::CONFIG[:thumb_storage] = 'root'
241
+ VTools::CONFIG[:thumb_path_generator] = prc
242
+ @class.generate_path("test.filename", "thumb").should == "root/test/path"
243
+ end
244
+
245
+ it "raises exception on invalid block" do
246
+ VTools::CONFIG[:video_path_generator] = failed_prc
247
+ expect do
248
+ @class.generate_path("test.filename", "video")
249
+ end.to raise_error VTools::ConfigError, /Path generator error/
250
+ end
251
+ end
215
252
 
216
- VTools::CONFIG[:thumb_storage] = 'root'
217
- VTools::CONFIG[:thumb_path_generator] = prc
218
- @class.generate_path("test.filename", "thumb").should == "root/test/path"
219
- end
253
+ context "creates path" do
220
254
 
221
- it "raises exception on invalid block" do
222
- prc = proc do
223
- CONFIG[:thumb_storage]
224
- end
255
+ before do
256
+ File.stub(:exists?).and_return(false)
257
+ VTools::CONFIG[:video_storage] = "/root/"
258
+ end
225
259
 
226
- VTools::CONFIG[:video_path_generator] = prc
227
- expect do
228
- @class.generate_path("test.filename", "video").should == "/root/test/path"
229
- end.to raise_error VTools::ConfigError, /Path generator error/
230
- end
231
- end
260
+ it "successfull" do
261
+ FileUtils.should_receive(:mkdir_p).and_return(nil)
232
262
 
233
- context "#path_generator" do
263
+ expect do
264
+ @class.generate_path("test.filename").should == "/root"
265
+ end.to_not raise_error
266
+ end
234
267
 
235
- before do
236
- VTools::CONFIG[:video_storage] = nil
237
- VTools::CONFIG[:thumb_storage] = nil
238
- VTools::CONFIG[:thumb_path_generator] = nil
239
- VTools::CONFIG[:video_path_generator] = nil
268
+ it "with error" do
269
+ FileUtils.should_receive(:mkdir_p).and_return do
270
+ raise Errno::EACCES, "Permission denied"
271
+ end
272
+
273
+ expect do
274
+ @class.generate_path("test.filename")
275
+ end.to raise_error VTools::FileError, /Path generator error: /
276
+ end
277
+ end
240
278
  end
241
279
 
242
- let(:block) { proc { nil } }
280
+ context "#path_generator appended to" do
243
281
 
244
- it "appends generator to thumbs" do
245
- @class.path_generator "thumb", &block
246
- VTools::CONFIG[:thumb_path_generator].should == block
247
- VTools::CONFIG[:video_path_generator].should be nil
248
- end
282
+ let(:block_stub) { proc {nil} }
249
283
 
250
- it "appends generator to thumbs (invalid placeholedr given)" do
251
- @class.path_generator "invalid", &block
252
- VTools::CONFIG[:thumb_path_generator].should == block
253
- VTools::CONFIG[:video_path_generator].should be nil
254
- end
284
+ it "thumbs only" do
285
+ @class.path_generator "thumbs path", &block_stub
286
+ VTools::CONFIG[:thumb_path_generator].should == block_stub
287
+ VTools::CONFIG[:video_path_generator].should_not be
288
+ end
255
289
 
256
- it "appends generator to video" do
257
- @class.path_generator "video", &block
258
- VTools::CONFIG[:video_path_generator].should == block
259
- VTools::CONFIG[:thumb_path_generator].should be nil
260
- end
290
+ it "thumbs path only (invalid placeholedr given)" do
291
+ @class.path_generator "invalid", &block_stub
292
+ VTools::CONFIG[:thumb_path_generator].should == block_stub
293
+ VTools::CONFIG[:video_path_generator].should_not be
294
+ end
261
295
 
262
- it "appends generator to both (default)" do
263
- @class.path_generator &block
264
- VTools::CONFIG[:video_path_generator].should == block
265
- VTools::CONFIG[:thumb_path_generator].should == block
266
- end
296
+ it "video path" do
297
+ @class.path_generator "video", &block_stub
298
+ VTools::CONFIG[:video_path_generator].should == block_stub
299
+ VTools::CONFIG[:thumb_path_generator].should_not be
300
+ end
301
+
302
+ it "both paths (default)" do
303
+ @class.path_generator &block_stub
304
+ [:video_path_generator, :thumb_path_generator].each do |index|
305
+ VTools::CONFIG[index].should == block_stub
306
+ end
307
+ end
267
308
 
268
- it "skips generator appending" do
269
- @class.path_generator
270
- VTools::CONFIG[:video_path_generator].should be nil
271
- VTools::CONFIG[:thumb_path_generator].should be nil
309
+ it "nothing" do
310
+ @class.path_generator
311
+ VTools::CONFIG[:video_path_generator].should_not be
312
+ VTools::CONFIG[:thumb_path_generator].should_not be
313
+ end
272
314
  end
273
315
  end
274
316
 
@@ -10,7 +10,6 @@ require "rspec"
10
10
  require "stringio"
11
11
 
12
12
  # helpers utilities
13
- #
14
13
  module Helpers
15
14
 
16
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
16
- requirement: &79436730 !ruby/object:Gem::Requirement
16
+ requirement: &71995340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *79436730
24
+ version_requirements: *71995340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &79436540 !ruby/object:Gem::Requirement
27
+ requirement: &71995150 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *79436540
35
+ version_requirements: *71995150
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &79436310 !ruby/object:Gem::Requirement
38
+ requirement: &71994920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *79436310
46
+ version_requirements: *71994920
47
47
  description: FFMPEG & FFMPEGTHUMBNAILER based video processor. Permits to generate
48
48
  thumbs and encode/edit video. Can be started as daemon.
49
49
  email: v.tofir@gmail.com