poleica 0.9.7 → 0.9.8

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
- ZDE5ZmRlMzY4YjkxOTgzM2M2Nzc2Y2NmZjMxNDRiMGIxMzUxYTg5OA==
4
+ N2JkOTZiMjQ2MmQ3Y2MyYmI3OTI2N2I2MWUzNDI5ZTM5YTE2MmZhOA==
5
5
  data.tar.gz: !binary |-
6
- NTJmZGQ2ZThiOTU4ZThiZGJjMGNlYzA3ZTdhMzhjNGU2NmRmYmYxYg==
6
+ MzdmZDljYWRmMGFiNWJjNDZmMGJlMjE4NWE4YjljY2I5YTJiYjdlMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTZjYTVmNTZiZTQ3ZDQ3ZTdlYjQzYTk0ODcwYzUzYjkwNGYzYjI0NjRkYzEx
10
- NzAyNThmZjUxMDRjNjIyODg0Yzc5YmYyMGI4ZjM1YjE2YmM4ZDZhMGE3MWQw
11
- NGNjNzE4MzU5ZmRlNTg1OWE4NzgyNTgxMzNmMmEyZjE3ZTVmNzA=
9
+ MmNhMTE3YjQ3MjE4OTdhMjFlOTBiYjQyN2Y0ZmJhM2Y0YzU1ZDhiMDNlZjA1
10
+ MjNlZDEwNmFjM2RkMWY4OTRiNmI0OGE2Y2FmZThkMzdhY2ZkMDEzMDNjZGY2
11
+ MDIzZTNhOTM0NTU5MGYzZDgwNGFiNDQzODA1NjA3YmUzMTFjYjc=
12
12
  data.tar.gz: !binary |-
13
- NDQ4OWU5ZDAzZGEyNGU1ZTYxYjIyZTRhOWI4Yjc2NWJhMmRiODU4M2Q4N2Y3
14
- MTQ2MGZiNjJlM2VkOWVlODIyYTkzMzU4YTIwNzk5MTZkOTJjMmQ5YmIwMzI1
15
- NWE3Y2RmYjA2YTcyMDNjNjI5MjU1ZGJkNDhiNTVlZWZhZjEzZTg=
13
+ YzBkMGJmNjgxMmJiZTNhNDNiMWM0MGQwOTIwYTczODdmMTRiNGFhMjY5ZTZm
14
+ MDk2ZWMzNDU5Y2E4MjMwMGQ1YjFmM2M0NGUwMjU1N2FiODQ4NmYyMDk0ZWY0
15
+ OWM0MjYyMjNhNzY3MmQ5MTlkOWMxNWZmMTEyNTNhNWYwMTlmYTM=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ # Poleica 0.9.8 (5 August 2013)
2
+ * Add timeout (2 mins) on LibreOffice and GraphicsMagick execution
1
3
  # Poleica 0.9.7 (4 August 2013)
2
4
  * Add an auto-orient (true by default) to GraphicsMagick
3
5
  # Poleica 0.9.6 (30 July 2013)
data/Gemfile.lock CHANGED
@@ -17,7 +17,7 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- poleica (0.9.7)
20
+ poleica (0.9.8)
21
21
 
22
22
  GEM
23
23
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/antoinelyset/poleica.png?branch=master)](https://travis-ci.org/antoinelyset/poleica)
5
5
  [![Coverage Status](https://coveralls.io/repos/antoinelyset/Poleica/badge.png)](https://coveralls.io/r/antoinelyset/Poleica)
6
6
  [![Code Climate](https://codeclimate.com/github/antoinelyset/Poleica.png)](https://codeclimate.com/github/antoinelyset/Poleica)
7
+ [![Gem Version](https://badge.fury.io/rb/poleica.png)](http://badge.fury.io/rb/poleica)
7
8
  [![Dependency Status](https://gemnasium.com/antoinelyset/Poleica.png)](https://gemnasium.com/antoinelyset/Poleica)
8
9
 
9
10
  ## Install
@@ -57,7 +58,7 @@ Poleica.new(file_path).to_png(width: 400, weight: 400)
57
58
 
58
59
  ## Dependencies
59
60
 
60
- - GraphicsMagick (gm)
61
+ - GraphicsMagick (gm) >= 1.3.11
61
62
  - LibreOffice
62
63
 
63
64
  ## Requirements
@@ -28,7 +28,7 @@ module Poleica
28
28
  opts_gen = OptionsGenerator.new(polei, options)
29
29
  cmd = "#{bin_path} convert "
30
30
  cmd << "#{Utils.escape(polei.path)}#{opts_gen.generate}"
31
- `#{cmd}`
31
+ exec_with_timeout(cmd)
32
32
  expected_file_path = opts_gen[:path]
33
33
  File.exists?(expected_file_path) ? expected_file_path : nil
34
34
  end
@@ -25,7 +25,7 @@ module Poleica
25
25
  def to_pdf(options = {})
26
26
  opts_gen = OptionsGenerator.new(polei, options, :pdf)
27
27
  cmd = "#{bin_path} #{opts_gen.generate}"
28
- `#{cmd}`
28
+ exec_with_timeout(cmd)
29
29
  expected_file_path = opts_gen[:path] || polei.path_with_md5(:pdf)
30
30
  File.exists?(expected_file_path) ? expected_file_path : nil
31
31
  ensure
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'digest/md5'
3
3
  require 'shellwords'
4
+ require 'timeout'
4
5
 
5
6
  module Poleica
6
7
  module Converters
@@ -8,6 +9,8 @@ module Poleica
8
9
  module Utils
9
10
  HOST_OS ||= (defined?('RbConfig') ? RbConfig : Config)::CONFIG['host_os']
10
11
 
12
+ DEFAULT_TIMEOUT = 120
13
+
11
14
  def windows?
12
15
  !!HOST_OS.match(/mswin|windows|cygwin/i)
13
16
  end
@@ -44,6 +47,14 @@ module Poleica
44
47
  def escape(string)
45
48
  Shellwords.shellescape(string)
46
49
  end
47
- end
48
- end
49
- end
50
+
51
+ def exec_with_timeout(cmd, timeout = DEFAULT_TIMEOUT, 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
56
+ Process.kill('TERM', pid)
57
+ end
58
+ end # module Utils
59
+ end # module Converters
60
+ end # module Poleica
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Poleica
3
- VERSION ||= '0.9.7'
3
+ VERSION ||= '0.9.8'
4
4
  end # module Poleica
@@ -2,4 +2,10 @@
2
2
  require 'test_helper'
3
3
  # Test the Utils Converter Module
4
4
  class UtilsTest < Minitest::Test
5
+ def test_exect_with_timeout
6
+ start_time = Time.now
7
+ Poleica::Converters::Utils.exec_with_timeout('sleep 2', 1)
8
+ duration = Time.now - start_time
9
+ assert(duration < 2)
10
+ end
5
11
  end
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.7
4
+ version: 0.9.8
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-04 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement