poleica 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjQ0ODk3YzY0NWUwY2U4NjBjYTY2NjI1MDY2NTRkMzg5NDQ2YmM3Ng==
4
+ YzM2ZTViOTU5Zjk5OWZkNDM5MjAwZGNmYzc5YTJkYTg5MjY1ZTZmMw==
5
5
  data.tar.gz: !binary |-
6
- ZTUwZTQ1NjExODY0ZTc4YTk1Y2RhM2I4YWY5ZjU5MGE2NTk3MTBjYw==
6
+ ZjY1YmMzYzUyYWNkNDYyYmZkYzhkYTA5OTU0OWIzMjI2Mjk2ZTc0Zg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWJjYjMzMGY5ZTk4NDZhYTZjNjY1ZDU0ZjkzZTUxNjI2MzY3NjkyODJkMzQy
10
- MWFkOTQwNjQ1YTg0MjNhNmFkNjIwMTMwMmFjNjBkMjU1YzlhMDUwMTRiNWI4
11
- NjZlNDA1NTNkMjMxZWNlMDdmYWU2OWZhYzI0YmJkOGVlYTM4NTY=
9
+ ZmJlNmNlZjAxOWZlNDVlYTg5ZWYxZTRiZWQ1NDVjNzllMzBiYTg2MTcyY2Q4
10
+ ZjczZWEwMWY3YzhjZDE0NDk2OTg3NzNiYmQ2YmRjNzVkOGRlMDUzNjU5ZTgz
11
+ YzIwZWNhNTlkNzkzZjE0MWZlZDQwNjUzZTA5NWQ2ZmI0NWJhNjQ=
12
12
  data.tar.gz: !binary |-
13
- MjAwMTdhOTg2NTk5ODY2NjQ0NDgwMGI1M2VlODIzNWM4NTQ2YTQxNDVkZDdm
14
- OWUwNmQyMTZiYjc4OTkxZDZhZTZjYmM0Y2RhODY3YWIxZGVkODNjNmEyYzA5
15
- NjU2NTQ4MzNkNDk4NDVjMWYwMWI5ZmViZjI3NTViZjU0YTJlODA=
13
+ OTQxMzg5NDBlNWI1YzUxM2NmMDM4MDg1MTVmN2ExZmViMTE4YmVkOTYzZDcy
14
+ MTQyYjY2NzM5NmM4NWJiNmNkMjgzNzAwMzJjNjIwMDAwYzk0OGI2N2ZiOThi
15
+ NDBmNmU5Y2UyOWYxMjA0NTg4ZWI0MGM3YzY5YWYxZGExMTdjY2M=
data/.travis.yml CHANGED
@@ -14,7 +14,7 @@ before_script:
14
14
  - ./configure
15
15
  - make
16
16
  - sudo make install
17
- - sudo ln -s /usr/local/bin/gm /usr/bin/gm
17
+ - /usr/lib/libreoffice/program/soffice.bin --nologo --headless --invisible --norestore --nolockcheck --convert-to pdf test/support/files/example.doc || true
18
18
  script:
19
19
  - rake
20
20
  matrix:
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
 
7
7
  group :test do
8
8
  gem 'minitest'
9
- gem 'rubocop', :github => 'bbatsov/rubocop'
9
+ gem 'rubocop', github: 'bbatsov/rubocop'
10
10
  gem 'coveralls', require: false
11
11
  end
12
12
 
@@ -15,5 +15,5 @@ group :development do
15
15
 
16
16
  # Guards
17
17
  gem 'guard-rubocop'
18
- gem 'guard-minitest', :github => 'guard/guard-minitest'
18
+ gem 'guard-minitest', github: 'guard/guard-minitest'
19
19
  end
data/Gemfile.lock CHANGED
@@ -17,7 +17,8 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- poleica (0.9.10)
20
+ poleica (0.9.11)
21
+ childprocess
21
22
 
22
23
  GEM
23
24
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
  Rake::TestTask.new do |t|
4
4
  t.libs.push ['lib', 'test']
5
5
  t.test_files = FileList['test/**/*_test.rb']
6
- t.verbose = true
6
+ t.verbose = true
7
7
  end
8
8
 
9
9
  task :rubocop do |t|
@@ -7,7 +7,7 @@ module Poleica
7
7
  include Poleica::Converters::Utils
8
8
 
9
9
  BIN_PATHS = {
10
- linux: '/usr/bin/gm',
10
+ linux: '/usr/local/bin/gm',
11
11
  osx: '/usr/local/bin/gm'
12
12
  }
13
13
 
@@ -26,9 +26,7 @@ module Poleica
26
26
 
27
27
  def to_png(options = {})
28
28
  opts_gen = OptionsGenerator.new(polei, options)
29
- cmd = "#{bin_path} convert "
30
- cmd << "#{Utils.escape(polei.path)}#{opts_gen.generate}"
31
- exec_with_timeout(cmd)
29
+ exec_with_timeout(bin_path, opts_gen.generate)
32
30
  expected_file_path = opts_gen[:path]
33
31
  File.exists?(expected_file_path) ? expected_file_path : nil
34
32
  end
@@ -46,9 +44,13 @@ module Poleica
46
44
  end
47
45
 
48
46
  def generate
49
- "#{page_options} #{orient_options}" +
50
- " #{thumbnail_or_resize_options}" +
51
- " #{Utils.escape(output_options)}"
47
+ [
48
+ 'convert',
49
+ "#{polei.path}#{page_options}",
50
+ orient_options,
51
+ thumbnail_or_resize_options,
52
+ output_options
53
+ ].flatten
52
54
  end
53
55
 
54
56
  def [](key)
@@ -84,18 +86,23 @@ module Poleica
84
86
 
85
87
  def thumbnail_options
86
88
  @thumbnail_options ||=
87
- "-thumbnail #{options[:width]}x" +
88
- "#{options[:height]}^" +
89
- ' -gravity center' +
90
- " -extent #{options[:width]}x" +
91
- "#{options[:height]}"
89
+ [
90
+ '-thumbnail',
91
+ "#{options[:width]}x#{options[:height]}^",
92
+ '-gravity',
93
+ 'center',
94
+ '-extent',
95
+ "#{options[:width]}x#{options[:height]}"
96
+ ]
92
97
  end
93
98
 
94
99
  def resize_options
95
100
  @resize_options ||=
96
- "-resize #{options[:width]}x" +
97
- "#{options[:height]}" +
98
- "#{'!' if options[:force_resize]}"
101
+ [
102
+ '-resize',
103
+ "#{options[:width]}x#{options[:height]}" +
104
+ "#{'!' if options[:force_resize]}"
105
+ ]
99
106
  end
100
107
 
101
108
  def output_options
@@ -24,8 +24,7 @@ module Poleica
24
24
 
25
25
  def to_pdf(options = {})
26
26
  opts_gen = OptionsGenerator.new(polei, options, :pdf)
27
- cmd = "#{bin_path} #{opts_gen.generate}"
28
- exec_with_timeout(cmd)
27
+ exec_with_timeout(bin_path, opts_gen.generate)
29
28
  expected_file_path = opts_gen[:path] || polei.path_with_md5(:pdf)
30
29
  File.exists?(expected_file_path) ? expected_file_path : nil
31
30
  ensure
@@ -47,7 +46,11 @@ module Poleica
47
46
  end
48
47
 
49
48
  def generate
50
- "#{default_options} #{format} #{output_options}"
49
+ [
50
+ default_options,
51
+ format,
52
+ output_options
53
+ ].flatten
51
54
  end
52
55
 
53
56
  def [](key)
@@ -85,18 +88,19 @@ module Poleica
85
88
  end
86
89
 
87
90
  def default_options
88
- '--nologo --headless --invisible' +
89
- ' --norestore --nolockcheck --convert-to'
91
+ %w{
92
+ --nologo
93
+ --headless
94
+ --invisible
95
+ --norestore
96
+ --nolockcheck
97
+ --convert-to
98
+ }
90
99
  end
91
100
 
92
101
  def output_options
93
102
  dir_path = File.dirname(temp_path)
94
- "--outdir #{Utils.escape(dir_path)} #{Utils.escape(temp_path)}"
95
- end
96
-
97
- def pages_options
98
- @pages_options ||= Array(options[:page]).
99
- flatten.compact.uniq.sort.to_s
103
+ ['--outdir', dir_path, temp_path]
100
104
  end
101
105
  end # class OptionsGenerator
102
106
  end # class LibreOffice
@@ -1,7 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'digest/md5'
3
- require 'shellwords'
4
- require 'timeout'
3
+ require 'childprocess'
5
4
 
6
5
  module Poleica
7
6
  module Converters
@@ -42,19 +41,17 @@ module Poleica
42
41
  [extension, options]
43
42
  end
44
43
 
45
- def escape(string)
46
- Shellwords.shellescape(string)
47
- end
48
-
49
- def exec_with_timeout(cmd,
50
- timeout = Poleica.configuration.timeout,
51
- no_stdout = true)
52
- cmd << ' >/dev/null' if no_stdout
53
- pid = Process.spawn(cmd)
54
- Timeout.timeout(timeout) { Process.wait(pid) }
55
- rescue Timeout::Error => e
56
- Process.kill('KILL', pid)
57
- raise e
44
+ def exec_with_timeout(bin, args = [], timeout = nil, is_stdout = true)
45
+ args = Array(args).map(&:to_s)
46
+ timeout ||= Poleica.configuration.timeout
47
+ null = IO.new(IO.sysopen('/dev/null', 'w'), 'w')
48
+ process = ChildProcess.build(bin, *args).start
49
+ process.io.stdout = process.io.stderr = null
50
+ process.poll_for_exit(timeout)
51
+ rescue ChildProcess::TimeoutError => e
52
+ process.stop && raise(e)
53
+ ensure
54
+ null && null.close
58
55
  end
59
56
  end # module Utils
60
57
  end # module Converters
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Poleica
3
- VERSION ||= '0.9.10'
3
+ VERSION ||= '0.9.11'
4
4
  end # module Poleica
data/poleica.gemspec CHANGED
@@ -13,6 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+
17
+ s.add_runtime_dependency 'childprocess'
18
+ # s.add_runtime_dependency 'posix-spawn' ONLY MRI
19
+
16
20
  s.add_development_dependency 'bundler', '~> 1.3'
17
21
  s.add_development_dependency 'rake'
18
22
  end
@@ -19,7 +19,6 @@ class CoerciveTest < Minitest::Test
19
19
  def test_try_convert_intermediary_file_creation
20
20
  coercive_conv.send(:coerce, :to_png, {})
21
21
  assert(File.exists?(expected_pdf_path))
22
- clean_png_file
23
22
  clean_pdf_file
24
23
  end
25
24
 
@@ -41,29 +41,8 @@ class LibreOfficeTest < Minitest::Test
41
41
  assert_equal(returned_path, path_option)
42
42
  end
43
43
 
44
- # FIXME fail on Ubuntu
45
- # def test_multithreading
46
- # threads = multithreaded_conversion
47
- # threads.each_with_index do |t, n|
48
- # t.join
49
- # assert_equal(t[:expected_path], t[:returned_path])
50
- # assert(File.exists?(t[:expected_path]))
51
- # File.delete(t[:expected_path]) if File.exists?(t[:expected_path])
52
- # end
53
- # end
54
-
55
44
  private
56
45
 
57
- def multithreaded_conversion(threads_number = 5)
58
- (0..threads_number - 1).map do |n|
59
- Thread.new do
60
- path_option = "#{Support.support_path}/files/path_test#{n}.pdf"
61
- Thread.current[:expected_path] = path_option
62
- Thread.current[:returned_path] = doc_polei.to_pdf(path: path_option)
63
- end
64
- end
65
- end
66
-
67
46
  def clean_pdf_file
68
47
  if File.exists?(Support.expected_converted_path(DOC_PATH, :pdf))
69
48
  File.delete(Support.expected_converted_path(DOC_PATH, :pdf))
@@ -4,14 +4,17 @@ require 'test_helper'
4
4
  class UtilsTest < Minitest::Test
5
5
  def test_exec_with_timeout
6
6
  start_time = Time.now
7
- Poleica::Converters::Utils.exec_with_timeout('sleep 2', 0.1) rescue nil
7
+ Poleica::Converters::Utils.exec_with_timeout('sleep', 2, 0.1) rescue nil
8
8
  duration = Time.now - start_time
9
9
  assert(duration < 2)
10
10
  end
11
11
 
12
- def test_exec_with_timeout_exception
13
- assert_raises(Timeout::Error) do
14
- Poleica::Converters::Utils.exec_with_timeout('sleep 2', 0.1)
15
- end
12
+ def test_exec_with_timeout_kill
13
+ assert(`ps -a | grep soffice.bin | grep -v grep`.empty?)
14
+ Poleica.configure { |conf| conf.timeout = 0.001 }
15
+ Poleica.new("#{Support.support_path}/files/example.doc").to_png rescue nil
16
+ assert(`ps -a | grep example.doc | grep -v grep`.empty?)
17
+ ensure
18
+ Poleica.configure { |config| config.timeout = 120 }
16
19
  end
17
20
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poleica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Lyset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-06 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ! '>='
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ name: childprocess
13
27
  - !ruby/object:Gem::Dependency
14
28
  requirement: !ruby/object:Gem::Requirement
15
29
  requirements: