poleica 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +11 -0
- data/lib/poleica/configuration.rb +29 -3
- data/lib/poleica/converters/graphics_magick.rb +0 -5
- data/lib/poleica/converters/libre_office.rb +0 -5
- data/lib/poleica/converters/utils.rb +30 -13
- data/lib/poleica/errors.rb +4 -0
- data/lib/poleica/version.rb +1 -1
- data/lib/poleica.rb +1 -0
- data/test/poleica/configuration_test.rb +25 -1
- data/test/poleica/converters/utils_test.rb +6 -0
- data/test/test_helper.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWJhYzFiNTA4OWRkNTIyZmQ0MDNiODc4YzVmN2I3ZDk5ODViZTE0YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWZjMGQ2OWM3OTcxZjIzN2M1NGJmNWFmM2ViZWFjZmQ2ODk4NDkyYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2FhZGE2MjI4OTA2ZGI1MzViMmZhYWVkNGJlNDRlZTY3OGZmNmE4ZTNmZjE0
|
10
|
+
YTNkOGM1MDYxNzdhYTE5ODVmYzkxYjViNzQ2NjQzNDJmMWRlMThkY2QzZTVm
|
11
|
+
YzFmY2FkMmYxNzQ2MmFmYjQ4N2IzN2QyYzQzMjYwNzVlNmIxZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTg0YmU3MmJjZTg5MTllMTQ5MGRhYzdhZjgwMTc5Y2VjNmRiMTQ2NTA4NWI3
|
14
|
+
M2U3ODVjNzM5ODBlNWE5YjUzMjFkMzA3MjMwNDBmYWYxNmZlNzY2YmJlYzMy
|
15
|
+
Nzk3M2EwMmZlMjY1Mzc4NDZlN2RhMTY1YWY2NzM1OTg4ZDdhN2E=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -46,6 +46,17 @@ Poleica.new(file_path).to_png
|
|
46
46
|
Poleica.new(file_path).to_png(width: 400, weight: 400)
|
47
47
|
```
|
48
48
|
|
49
|
+
## Configuration
|
50
|
+
|
51
|
+
Example :
|
52
|
+
|
53
|
+
```
|
54
|
+
Poleica.configure do |config|
|
55
|
+
config.timeout = 2 # time in secs
|
56
|
+
config.libre_office[:bin_paths][:linux] = '/usr/local/bin/gm'
|
57
|
+
config.graphics_magick[:bin_paths][:osx] = '/Applications/OpenOffice.app/Contents/MacOS/soffice.bin'
|
58
|
+
```
|
59
|
+
|
49
60
|
## Options
|
50
61
|
|
51
62
|
- weight : pixels number
|
@@ -2,12 +2,34 @@
|
|
2
2
|
module Poleica
|
3
3
|
# Configuration class
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :timeout
|
5
|
+
attr_accessor :timeout, :libre_office, :graphics_magick
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
self.timeout
|
8
|
+
self.timeout = 120
|
9
|
+
self.libre_office = init_libre_office_config
|
10
|
+
self.graphics_magick = init_graphics_magick_config
|
11
|
+
end
|
12
|
+
|
13
|
+
def init_graphics_magick_config
|
14
|
+
{
|
15
|
+
bin_paths:
|
16
|
+
{
|
17
|
+
linux: '/usr/local/bin/gm',
|
18
|
+
osx: '/usr/local/bin/gm'
|
19
|
+
}
|
20
|
+
}
|
9
21
|
end
|
10
|
-
|
22
|
+
|
23
|
+
def init_libre_office_config
|
24
|
+
{
|
25
|
+
bin_paths:
|
26
|
+
{
|
27
|
+
linux: '/usr/lib/libreoffice/program/soffice.bin',
|
28
|
+
osx: '/Applications/LibreOffice.app/Contents/MacOS/soffice.bin'
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end # class Configuration
|
11
33
|
|
12
34
|
def self.configure
|
13
35
|
yield(configuration) if block_given?
|
@@ -16,4 +38,8 @@ module Poleica
|
|
16
38
|
def self.configuration
|
17
39
|
@configuration ||= Configuration.new
|
18
40
|
end
|
41
|
+
|
42
|
+
def self.reset_configuration
|
43
|
+
@configuration = Configuration.new
|
44
|
+
end
|
19
45
|
end # module Poleica
|
@@ -7,11 +7,6 @@ module Poleica
|
|
7
7
|
class LibreOffice
|
8
8
|
include Poleica::Converters::Utils
|
9
9
|
|
10
|
-
BIN_PATHS = {
|
11
|
-
linux: '/usr/lib/libreoffice/program/soffice.bin',
|
12
|
-
osx: '/Applications/LibreOffice.app/Contents/MacOS/soffice.bin'
|
13
|
-
}
|
14
|
-
|
15
10
|
COMPATIBLE_TYPES = [
|
16
11
|
Types::Document
|
17
12
|
]
|
@@ -6,6 +6,7 @@ module Poleica
|
|
6
6
|
module Converters
|
7
7
|
# An Utility module for the converters needs to be include
|
8
8
|
module Utils
|
9
|
+
|
9
10
|
HOST_OS ||= (defined?('RbConfig') ? RbConfig : Config)::CONFIG['host_os']
|
10
11
|
|
11
12
|
def windows?
|
@@ -25,13 +26,21 @@ module Poleica
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def bin_path
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
converter = :"#{underscorize(self.class)}"
|
30
|
+
configuration = Poleica.configuration.send(converter)
|
31
|
+
bin_paths = configuration[:bin_paths]
|
32
|
+
path = bin_paths[host_os] || bin_paths[:linux]
|
31
33
|
raise "#{self.class} not found @ #{path}" unless File.exists?(path)
|
32
34
|
path
|
33
35
|
end
|
34
36
|
|
37
|
+
def underscorize(camel_cased_word)
|
38
|
+
word = camel_cased_word.to_s
|
39
|
+
word = word[((word.rindex('::') + 2) || 0)..-1]
|
40
|
+
word.gsub!(/([A-Z]+)/, '_\1').gsub!(/^_/, '').downcase!
|
41
|
+
word
|
42
|
+
end
|
43
|
+
|
35
44
|
module_function
|
36
45
|
|
37
46
|
def extract_extension_and_options(method, args = [])
|
@@ -41,17 +50,25 @@ module Poleica
|
|
41
50
|
[extension, options]
|
42
51
|
end
|
43
52
|
|
44
|
-
def exec_with_timeout(bin, args = [], timeout = nil,
|
45
|
-
args
|
46
|
-
timeout
|
47
|
-
|
48
|
-
process
|
49
|
-
process.
|
50
|
-
process.poll_for_exit(timeout)
|
53
|
+
def exec_with_timeout(bin, args = [], timeout = nil, no_stdout = true)
|
54
|
+
args = Array(args).map(&:to_s)
|
55
|
+
timeout ||= Poleica.configuration.timeout
|
56
|
+
process = ChildProcess.build(bin, *args)
|
57
|
+
set_process_stdout(process, no_stdout)
|
58
|
+
process.start
|
59
|
+
timeout ? process.poll_for_exit(timeout) : process.wait
|
51
60
|
rescue ChildProcess::TimeoutError => e
|
52
|
-
process.stop
|
53
|
-
|
54
|
-
|
61
|
+
process.stop
|
62
|
+
raise(Poleica::TimeoutError.new(e.message))
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_process_stdout(process, no_stdout)
|
66
|
+
if no_stdout
|
67
|
+
null = IO.new(IO.sysopen('/dev/null', 'w'), 'w')
|
68
|
+
process.io.stdout = process.io.stderr = null
|
69
|
+
else
|
70
|
+
process.io.inherit!
|
71
|
+
end
|
55
72
|
end
|
56
73
|
end # module Utils
|
57
74
|
end # module Converters
|
data/lib/poleica/version.rb
CHANGED
data/lib/poleica.rb
CHANGED
@@ -11,4 +11,28 @@ class ConfigurationTest < Minitest::Test
|
|
11
11
|
ensure
|
12
12
|
Poleica.configure { |config| config.timeout = 120 }
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
def test_graphics_magick_configuration
|
16
|
+
Poleica.configure do |config|
|
17
|
+
config.graphics_magick[:bin_paths] = { linux: '', osx: '' }
|
18
|
+
end
|
19
|
+
expected_message = 'Poleica::Converters::GraphicsMagick not found @ '
|
20
|
+
assert_raises(RuntimeError, expected_message) do
|
21
|
+
Poleica.new('test/support/files/example.pdf').to_png
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
Poleica.reset_configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_libre_office_configuration
|
28
|
+
Poleica.configure do |config|
|
29
|
+
config.libre_office[:bin_paths] = { linux: '', osx: '' }
|
30
|
+
end
|
31
|
+
expected_message = 'Poleica::Converters::LibreOffice not found @ '
|
32
|
+
assert_raises(RuntimeError, expected_message) do
|
33
|
+
Poleica.new('test/support/files/example.doc').to_pdf
|
34
|
+
end
|
35
|
+
ensure
|
36
|
+
Poleica.reset_configuration
|
37
|
+
end
|
38
|
+
end # class ConfigurationTest
|
@@ -9,6 +9,12 @@ class UtilsTest < Minitest::Test
|
|
9
9
|
assert(duration < 2)
|
10
10
|
end
|
11
11
|
|
12
|
+
def test_exec_with_timeout_raise_an_exception
|
13
|
+
assert_raises(Poleica::TimeoutError) do
|
14
|
+
Poleica::Converters::Utils.exec_with_timeout('sleep', 2, 0.1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
def test_exec_with_timeout_kill
|
13
19
|
assert(`ps -a | grep soffice.bin | grep -v grep`.empty?)
|
14
20
|
Poleica.configure { |conf| conf.timeout = 0.001 }
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.12
|
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-09-
|
11
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/poleica/converters/graphics_magick.rb
|
77
77
|
- lib/poleica/converters/libre_office.rb
|
78
78
|
- lib/poleica/converters/utils.rb
|
79
|
+
- lib/poleica/errors.rb
|
79
80
|
- lib/poleica/pathable.rb
|
80
81
|
- lib/poleica/polei.rb
|
81
82
|
- lib/poleica/types/all.rb
|