handbrake 0.3.0 → 0.3.1

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.
@@ -1,3 +1,13 @@
1
+ 0.3.1
2
+ =====
3
+
4
+ - Add `:dry_run` option for {HandBrake::CLI}. When true, the commands
5
+ that would be executed otherwise are printed to standard out
6
+ instead.
7
+ - Ensure that the directories needed by a call to
8
+ {HandBrake::CLI#output} exist before writing to them.
9
+ - Ensure that the options hash passed into #output is not modified.
10
+
1
11
  0.3.0
2
12
  =====
3
13
 
@@ -1,4 +1,5 @@
1
1
  require 'handbrake'
2
+ require 'fileutils'
2
3
 
3
4
  module HandBrake
4
5
  ##
@@ -18,18 +19,28 @@ module HandBrake
18
19
  # @return [Boolean]
19
20
  attr_writer :trace
20
21
 
22
+ ##
23
+ # Set whether dry_run mode is selected.
24
+ #
25
+ # @return [Boolean]
26
+ attr_writer :dry_run
27
+
21
28
  ##
22
29
  # @param [Hash] options
23
30
  # @option options [String] :bin_path ('HandBrakeCLI') the full
24
31
  # path to the executable to use
25
32
  # @option options [Boolean] :trace (false) whether {#trace?} is
26
33
  # enabled
34
+ # @option options [Boolean] :dry_run (false) if true, nothing will
35
+ # actually be executed. The commands that would have been
36
+ # executed will be printed to standard out.
27
37
  # @option options [#run] :runner (a PopenRunner instance) the class
28
38
  # encapsulating the execution method for HandBrakeCLI. You
29
39
  # shouldn't usually need to replace this.
30
40
  def initialize(options={})
31
41
  @bin_path = options[:bin_path] || 'HandBrakeCLI'
32
42
  @trace = options[:trace].nil? ? false : options[:trace]
43
+ @dry_run = options[:dry_run] || false
33
44
  @runner = options[:runner] || PopenRunner.new(self)
34
45
 
35
46
  @args = []
@@ -55,14 +66,32 @@ module HandBrake
55
66
  @trace
56
67
  end
57
68
 
69
+ ##
70
+ # Is this instance in `dry_run` mode?
71
+ #
72
+ # If it is, then no commands will actually be executed. The
73
+ # constructed `HandBrakeCLI` invocations will be printed to
74
+ # standard out, instead.
75
+ def dry_run?
76
+ @dry_run
77
+ end
78
+
79
+ def fileutils_options
80
+ {
81
+ :noop => dry_run?,
82
+ :verbose => trace? || dry_run?
83
+ }
84
+ end
85
+ private :fileutils_options
86
+
58
87
  ##
59
88
  # Performs a conversion. This method immediately begins the
60
89
  # transcoding process; set all other options first.
61
90
  #
62
91
  # @param [String] filename the desired name for the final output
63
- # file
92
+ # file.
64
93
  # @param [Hash] options additional options to control the behavior
65
- # of the output process
94
+ # of the output process. The provided hash will not be modified.
66
95
  # @option options [Boolean,:ignore] :overwrite (true) determines
67
96
  # the behavior if the desired output file already exists. If
68
97
  # `true`, the file is replaced. If `false`, an exception is
@@ -84,6 +113,7 @@ module HandBrake
84
113
  #
85
114
  # @return [void]
86
115
  def output(filename, options={})
116
+ options = options.dup
87
117
  overwrite = options.delete :overwrite
88
118
  case overwrite
89
119
  when true, nil
@@ -116,6 +146,7 @@ module HandBrake
116
146
  raise "Unknown options for output: #{options.keys.inspect}"
117
147
  end
118
148
 
149
+ FileUtils.mkdir_p(File.dirname(interim_filename), fileutils_options)
119
150
  run('--output', interim_filename)
120
151
 
121
152
  if filename != interim_filename
@@ -135,7 +166,8 @@ module HandBrake
135
166
  else
136
167
  true
137
168
  end
138
- FileUtils.mv(interim_filename, filename, :verbose => trace?) if replace
169
+ FileUtils.mkdir_p(File.dirname(filename), fileutils_options)
170
+ FileUtils.mv(interim_filename, filename, fileutils_options) if replace
139
171
  end
140
172
  end
141
173
 
@@ -280,13 +312,18 @@ module HandBrake
280
312
  cmd = "'" + arguments.unshift(@cli.bin_path).join("' '") + "' 2>&1"
281
313
 
282
314
  $stderr.puts "Spawning HandBrakeCLI using #{cmd.inspect}" if @cli.trace?
283
- IO.popen(cmd) do |io|
284
- while line = io.read(60)
285
- output << line
286
- $stderr.write(line) if @cli.trace?
315
+ if @cli.dry_run?
316
+ puts cmd
317
+ RunnerResult.new('', 0)
318
+ else
319
+ IO.popen(cmd) do |io|
320
+ while line = io.read(60)
321
+ output << line
322
+ $stderr.write(line) if @cli.trace?
323
+ end
287
324
  end
325
+ RunnerResult.new(output, $?)
288
326
  end
289
- RunnerResult.new(output, $?)
290
327
  end
291
328
  end
292
329
 
@@ -1,5 +1,5 @@
1
1
  module HandBrake
2
2
  ##
3
3
  # The current version
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -96,6 +96,18 @@ module HandBrake
96
96
  should raise_error('Unknown options for output: [:quux]')
97
97
  end
98
98
 
99
+ it 'does not directly modify the passed-in options hash' do
100
+ options = { :overwrite => true }
101
+ cli.output(filename, options)
102
+ options[:overwrite].should be_true
103
+ end
104
+
105
+ it 'creates the target directory when it does not exist' do
106
+ new_dir = File.join(tmpdir, 'quux')
107
+ cli.output(File.join(new_dir, 'baz.m4v'))
108
+ File.directory?(new_dir).should be_true
109
+ end
110
+
99
111
  describe ':overwrite' do
100
112
  context 'true' do
101
113
  it 'executes when the file does not exist' do
@@ -179,12 +191,19 @@ module HandBrake
179
191
  File.read(filename).should == 'This is the file created by --output'
180
192
  end
181
193
 
194
+ it 'creates the directory for the desired filename if necessary' do
195
+ new_dir = File.join(tmpdir, 'quux')
196
+ cli.output(File.join(new_dir, 'baz.m4v'), :atomic => atomic_option_value)
197
+ File.directory?(new_dir).should be_true
198
+ end
199
+
182
200
  it 'removes the temporary file' do
183
201
  cli.output(filename, :atomic => atomic_option_value)
184
202
  File.exist?(expected_temporary_file).should be_false
185
203
  end
186
204
 
187
205
  it 'overwrites the temporary file if it exists' do
206
+ FileUtils.mkdir_p File.dirname(expected_temporary_file)
188
207
  FileUtils.touch expected_temporary_file
189
208
  cli.output(filename, :atomic => atomic_option_value)
190
209
  it_should_have_run(expected_temporary_file)
@@ -242,7 +261,7 @@ module HandBrake
242
261
  end
243
262
 
244
263
  context 'an alternate path' do
245
- let(:atomic_option_value) { tmpdir('somewhere/else') }
264
+ let(:atomic_option_value) { File.join(tmpdir, 'somewhere/else') } # not mkdir'd
246
265
  let(:expected_temporary_file) { File.join(atomic_option_value, "foo.handbraking.m4v") }
247
266
  let(:expected_no_extension_temporary_filename) {
248
267
  File.join(atomic_option_value, 'foo.handbraking')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handbrake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-08-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubytree
16
- requirement: &2152701940 !ruby/object:Gem::Requirement
16
+ requirement: &2152476560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152701940
24
+ version_requirements: *2152476560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2152701440 !ruby/object:Gem::Requirement
27
+ requirement: &2152476060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.5'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152701440
35
+ version_requirements: *2152476060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2152700980 !ruby/object:Gem::Requirement
38
+ requirement: &2152475600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152700980
46
+ version_requirements: *2152475600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &2152700520 !ruby/object:Gem::Requirement
49
+ requirement: &2152475140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152700520
57
+ version_requirements: *2152475140
58
58
  description: A lightweight literate ruby wrapper for HandBrakeCLI, the command-line
59
59
  interface for the HandBrake video transcoder.
60
60
  email: