poleica 0.9.10 → 0.9.11
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.
- checksums.yaml +8 -8
- data/.travis.yml +1 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -1
- data/Rakefile +1 -1
- data/lib/poleica/converters/graphics_magick.rb +22 -15
- data/lib/poleica/converters/libre_office.rb +15 -11
- data/lib/poleica/converters/utils.rb +12 -15
- data/lib/poleica/version.rb +1 -1
- data/poleica.gemspec +4 -0
- data/test/poleica/converters/coercive_test.rb +0 -1
- data/test/poleica/converters/libre_office_test.rb +0 -21
- data/test/poleica/converters/utils_test.rb +8 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzM2ZTViOTU5Zjk5OWZkNDM5MjAwZGNmYzc5YTJkYTg5MjY1ZTZmMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjY1YmMzYzUyYWNkNDYyYmZkYzhkYTA5OTU0OWIzMjI2Mjk2ZTc0Zg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmJlNmNlZjAxOWZlNDVlYTg5ZWYxZTRiZWQ1NDVjNzllMzBiYTg2MTcyY2Q4
|
10
|
+
ZjczZWEwMWY3YzhjZDE0NDk2OTg3NzNiYmQ2YmRjNzVkOGRlMDUzNjU5ZTgz
|
11
|
+
YzIwZWNhNTlkNzkzZjE0MWZlZDQwNjUzZTA5NWQ2ZmI0NWJhNjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
-
|
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',
|
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', :
|
18
|
+
gem 'guard-minitest', github: 'guard/guard-minitest'
|
19
19
|
end
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -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
|
-
|
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
|
-
|
50
|
-
|
51
|
-
"
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
89
|
-
|
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
|
-
|
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 '
|
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
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
data/lib/poleica/version.rb
CHANGED
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
|
@@ -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
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
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.
|
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-
|
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:
|