libreconv 0.9.3 → 0.9.4
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 +4 -4
- data/lib/libreconv/version.rb +1 -1
- data/lib/libreconv.rb +20 -13
- data/spec/libreconv_spec.rb +10 -10
- metadata +2 -3
- data/Gemfile.lock +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b7109677cd71c5dd97fdc49de55639d0e48aadd30f3d8f110aca98bac953023
|
4
|
+
data.tar.gz: 3c125782142e2064eb7b0ad6cf9616fddd0c5a2f1d59492bd0da24bb26f84a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb657e3ae1f331a3adac2b6b1048b4dce58540431513e0302dd416d416412de4ded91cde2cce07340416fde5e2a74b5a2bf708bea4f4e0b09e719faae6fcffb
|
7
|
+
data.tar.gz: f7315df7d4ab60f008083dacb2e07f455f572c8bdddb80dc33c9f070bcfadd9f4ae1c37da62fe9b9f27920084f14c2e78b5b6ab7d6ce4b618a7307b48bb04a57
|
data/lib/libreconv/version.rb
CHANGED
data/lib/libreconv.rb
CHANGED
@@ -53,11 +53,12 @@ module Libreconv
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def convert
|
56
|
-
|
56
|
+
pipe_name = 'soffice-pipe-' + SecureRandom.uuid.to_s
|
57
|
+
pipe_path = File.join Dir.tmpdir, pipe_name
|
57
58
|
|
58
59
|
Dir.mktmpdir do |target_path|
|
59
60
|
accept_args = [
|
60
|
-
|
61
|
+
'pipe,name=' + pipe_name,
|
61
62
|
'url',
|
62
63
|
'StarOffice.ServiceManager'
|
63
64
|
].join(';')
|
@@ -65,7 +66,8 @@ module Libreconv
|
|
65
66
|
command = [
|
66
67
|
soffice_command,
|
67
68
|
"--accept=\"#{accept_args}\"",
|
68
|
-
|
69
|
+
'-env:UserInstallation=file:///' +
|
70
|
+
pipe_path.gsub('\\', '/').gsub(%r{^/}, ''),
|
69
71
|
'--headless',
|
70
72
|
'--convert-to',
|
71
73
|
@convert_to,
|
@@ -79,22 +81,27 @@ module Libreconv
|
|
79
81
|
'HOME' => ENV['HOME'],
|
80
82
|
'PATH' => ENV['PATH'],
|
81
83
|
'LANG' => ENV['LANG'],
|
82
|
-
'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH']
|
84
|
+
'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'],
|
85
|
+
'SYSTEMROOT' => ENV['SYSTEMROOT'],
|
86
|
+
'TEMP' => ENV['TEMP']
|
83
87
|
},
|
84
88
|
*command,
|
85
89
|
unsetenv_others: true
|
86
90
|
)
|
87
|
-
|
91
|
+
|
92
|
+
FileUtils.rm_rf pipe_path if File.exist?(pipe_path)
|
93
|
+
unless status.success?
|
88
94
|
raise ConversionFailedError,
|
89
|
-
|
90
|
-
|
95
|
+
'Conversion failed! Output: ' + output.strip.inspect +
|
96
|
+
', Error: ' + error.strip.inspect
|
91
97
|
end
|
92
98
|
|
93
|
-
target_tmp_file =
|
94
|
-
|
95
|
-
|
99
|
+
target_tmp_file = File.join(
|
100
|
+
target_path,
|
101
|
+
File.basename(@escaped_source_path, '.*') + '.' +
|
102
|
+
File.basename(@convert_to, ':*')
|
103
|
+
)
|
96
104
|
FileUtils.cp target_tmp_file, @target
|
97
|
-
FileUtils.rm_rf("/tmp/soffice-dir-#{pipe_uuid}")
|
98
105
|
end
|
99
106
|
end
|
100
107
|
|
@@ -103,14 +110,14 @@ module Libreconv
|
|
103
110
|
def ensure_soffice_exists
|
104
111
|
return if soffice_command && File.exist?(soffice_command)
|
105
112
|
|
106
|
-
raise IOError,
|
113
|
+
raise IOError, 'Can\'t find LibreOffice or OpenOffice executable.'
|
107
114
|
end
|
108
115
|
|
109
116
|
def which(cmd)
|
110
117
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
111
118
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
112
119
|
exts.each do |ext|
|
113
|
-
exe = File.join(path,
|
120
|
+
exe = File.join(path, cmd + ext)
|
114
121
|
return exe if File.executable? exe
|
115
122
|
end
|
116
123
|
end
|
data/spec/libreconv_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Libreconv do
|
|
22
22
|
describe '#new' do
|
23
23
|
it 'raises error if soffice command does not exists' do
|
24
24
|
expect do
|
25
|
-
|
25
|
+
described_class.new(
|
26
26
|
doc_file, '/target', '/Whatever/soffice'
|
27
27
|
)
|
28
28
|
end.to raise_error(IOError)
|
@@ -30,7 +30,7 @@ describe Libreconv do
|
|
30
30
|
|
31
31
|
it 'raises error if source does not exists' do
|
32
32
|
expect do
|
33
|
-
|
33
|
+
described_class.new(
|
34
34
|
fixture_path('nonsense.txt'), '/target'
|
35
35
|
)
|
36
36
|
end.to raise_error(IOError)
|
@@ -40,35 +40,35 @@ describe Libreconv do
|
|
40
40
|
describe '#convert' do
|
41
41
|
it 'converts a docx do pdf specifying target_file' do
|
42
42
|
target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
|
43
|
-
converter =
|
43
|
+
converter = described_class.new(doc_file, target_file)
|
44
44
|
converter.convert
|
45
45
|
expect(File.file?(target_file)).to eq true
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'converts a doc to pdf' do
|
49
49
|
target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
|
50
|
-
converter =
|
50
|
+
converter = described_class.new(doc_file, target_path)
|
51
51
|
converter.convert
|
52
52
|
expect(File.file?(target_file)).to eq true
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'converts a docx to pdf' do
|
56
56
|
target_file = "#{target_path}/#{File.basename(docx_file, '.docx')}.pdf"
|
57
|
-
converter =
|
57
|
+
converter = described_class.new(docx_file, target_path)
|
58
58
|
converter.convert
|
59
59
|
expect(File.file?(target_file)).to eq true
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'converts a pptx to pdf' do
|
63
63
|
target_file = "#{target_path}/#{File.basename(pptx_file, '.pptx')}.pdf"
|
64
|
-
converter =
|
64
|
+
converter = described_class.new(pptx_file, target_path)
|
65
65
|
converter.convert
|
66
66
|
expect(File.file?(target_file)).to eq true
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'converts a ppt to pdf' do
|
70
70
|
target_file = "#{target_path}/#{File.basename(ppt_file, '.ppt')}.pdf"
|
71
|
-
converter =
|
71
|
+
converter = described_class.new(ppt_file, target_path)
|
72
72
|
converter.convert
|
73
73
|
expect(File.file?(target_file)).to eq true
|
74
74
|
end
|
@@ -76,7 +76,7 @@ describe Libreconv do
|
|
76
76
|
# it 'raises ConversionFailedError when URL cannot be loaded' do
|
77
77
|
# stub_request(:get, url)
|
78
78
|
# expect do
|
79
|
-
# converter =
|
79
|
+
# converter = described_class.new(url, target_path)
|
80
80
|
# converter.convert
|
81
81
|
# end.to raise_error(
|
82
82
|
# Libreconv::ConversionFailedError,
|
@@ -89,13 +89,13 @@ describe Libreconv do
|
|
89
89
|
it 'returns the user specified command path' do
|
90
90
|
# Just faking that the command is present here
|
91
91
|
cmd = fixture_path('soffice')
|
92
|
-
converter =
|
92
|
+
converter = described_class.new(doc_file, '/target', cmd)
|
93
93
|
expect(converter.soffice_command).to eq cmd
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'returns the command found in path' do
|
97
97
|
cmd = `which soffice`.strip
|
98
|
-
converter =
|
98
|
+
converter = described_class.new(doc_file, '/target')
|
99
99
|
expect(converter.soffice_command).to eq cmd
|
100
100
|
end
|
101
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libreconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Nyström
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- ".ruby-version"
|
67
67
|
- ".travis.yml"
|
68
68
|
- Gemfile
|
69
|
-
- Gemfile.lock
|
70
69
|
- LICENSE.txt
|
71
70
|
- README.md
|
72
71
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
libreconv (0.9.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.5.2)
|
10
|
-
public_suffix (>= 2.0.2, < 4.0)
|
11
|
-
ast (2.4.0)
|
12
|
-
byebug (10.0.2)
|
13
|
-
coderay (1.1.2)
|
14
|
-
crack (0.4.3)
|
15
|
-
safe_yaml (~> 1.0.0)
|
16
|
-
diff-lcs (1.3)
|
17
|
-
hashdiff (0.3.7)
|
18
|
-
jaro_winkler (1.5.1)
|
19
|
-
method_source (0.9.2)
|
20
|
-
parallel (1.12.1)
|
21
|
-
parser (2.5.3.0)
|
22
|
-
ast (~> 2.4.0)
|
23
|
-
powerpack (0.1.2)
|
24
|
-
pry (0.12.2)
|
25
|
-
coderay (~> 1.1.0)
|
26
|
-
method_source (~> 0.9.0)
|
27
|
-
pry-byebug (3.6.0)
|
28
|
-
byebug (~> 10.0)
|
29
|
-
pry (~> 0.10)
|
30
|
-
public_suffix (3.0.3)
|
31
|
-
rainbow (3.0.0)
|
32
|
-
rake (12.3.2)
|
33
|
-
rspec (3.8.0)
|
34
|
-
rspec-core (~> 3.8.0)
|
35
|
-
rspec-expectations (~> 3.8.0)
|
36
|
-
rspec-mocks (~> 3.8.0)
|
37
|
-
rspec-core (3.8.0)
|
38
|
-
rspec-support (~> 3.8.0)
|
39
|
-
rspec-expectations (3.8.2)
|
40
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.8.0)
|
42
|
-
rspec-mocks (3.8.0)
|
43
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.8.0)
|
45
|
-
rspec-support (3.8.0)
|
46
|
-
rubocop (0.61.1)
|
47
|
-
jaro_winkler (~> 1.5.1)
|
48
|
-
parallel (~> 1.10)
|
49
|
-
parser (>= 2.5, != 2.5.1.1)
|
50
|
-
powerpack (~> 0.1)
|
51
|
-
rainbow (>= 2.2.2, < 4.0)
|
52
|
-
ruby-progressbar (~> 1.7)
|
53
|
-
unicode-display_width (~> 1.4.0)
|
54
|
-
rubocop-rspec (1.30.1)
|
55
|
-
rubocop (>= 0.60.0)
|
56
|
-
ruby-progressbar (1.10.0)
|
57
|
-
safe_yaml (1.0.4)
|
58
|
-
unicode-display_width (1.4.0)
|
59
|
-
webmock (3.4.2)
|
60
|
-
addressable (>= 2.3.6)
|
61
|
-
crack (>= 0.3.2)
|
62
|
-
hashdiff
|
63
|
-
|
64
|
-
PLATFORMS
|
65
|
-
ruby
|
66
|
-
|
67
|
-
DEPENDENCIES
|
68
|
-
bundler
|
69
|
-
libreconv!
|
70
|
-
pry-byebug
|
71
|
-
rake
|
72
|
-
rspec (~> 3.8.0)
|
73
|
-
rubocop
|
74
|
-
rubocop-rspec
|
75
|
-
webmock
|
76
|
-
|
77
|
-
BUNDLED WITH
|
78
|
-
1.17.1
|