libis-format 1.2.7 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -1
- data/lib/libis/format/cli/prompt_helper.rb +32 -24
- data/lib/libis/format/converter/audio_converter.rb +23 -30
- data/lib/libis/format/identifier.rb +1 -1
- data/lib/libis/format/tool/extension_identification.rb +23 -25
- data/lib/libis/format/tool/fido.rb +22 -27
- data/lib/libis/format/tool/file_tool.rb +11 -24
- data/lib/libis/format/tool/fop_pdf.rb +19 -20
- data/lib/libis/format/tool/identification_tool.rb +34 -36
- data/lib/libis/format/tool/msg_to_pdf.rb +66 -111
- data/lib/libis/format/tool/office_to_pdf.rb +24 -21
- data/lib/libis/format/tool/pdf_split.rb +19 -20
- data/lib/libis/format/tool/pdf_to_pdfa.rb +32 -30
- data/lib/libis/format/tool/pdfa_validator.rb +16 -14
- data/lib/libis/format/version.rb +3 -1
- data/libis-format.gemspec +23 -22
- data/tools/fop/fop.bat +75 -75
- data/tools/fop/fop.cmd +31 -31
- data/tools/fop/fop.js +341 -341
- data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -11
- data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -17
- data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -74
- data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -66
- metadata +69 -79
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -21
- data/.travis.yml +0 -74
- data/.vscode/launch.json +0 -21
- data/Rakefile +0 -12
- data/base/Dockerfile +0 -33
- data/base/Dockerfile.alpine +0 -20
- data/base/Dockerfile.rvm +0 -56
- data/base/rework_path +0 -25
- data/docker_cfg.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c29bb20892b78bbab9995bdd7ce9e41510c58eaa3f6b63677d4decabd58fa3c
|
4
|
+
data.tar.gz: ee9f707483006aef00181ca19ddb2db59f7b57cba73dcced0783651e6736b1e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df967f1e7548534c9f030d85e823af89c811501b28279ff390904f1ffccef27ecfc34467d5e858d1faa4b24fef018e2c5dc67a79041cebb80bdee02d0f1075d
|
7
|
+
data.tar.gz: fa62cdcc7d6182bf9092af071e1657ac6dd41d47f1ad7327ac66d604e6df3218117f07745c16cbd8b45043901f79ee86ece53d735b223a850c84ad3a5306cff4
|
data/Gemfile
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gem 'coveralls', group: :test, require: false
|
4
6
|
|
5
7
|
gemspec name: 'libis-format', development_group: :test
|
6
8
|
|
7
|
-
|
9
|
+
group :development do
|
10
|
+
gem 'byebug'
|
11
|
+
gem 'debug'
|
12
|
+
gem 'standard'
|
13
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tty-prompt'
|
2
4
|
require 'pastel'
|
3
5
|
|
@@ -5,7 +7,6 @@ module Libis
|
|
5
7
|
module Format
|
6
8
|
module Cli
|
7
9
|
module PromptHelper
|
8
|
-
|
9
10
|
attr_reader :prompt, :pastel
|
10
11
|
|
11
12
|
def initialize(*args)
|
@@ -14,8 +15,6 @@ module Libis
|
|
14
15
|
super
|
15
16
|
end
|
16
17
|
|
17
|
-
protected
|
18
|
-
|
19
18
|
private
|
20
19
|
|
21
20
|
def index_of(list, value)
|
@@ -25,7 +24,9 @@ module Libis
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def ask(question, bool: false, enum: nil, default: nil, mask: false)
|
28
|
-
cmd
|
27
|
+
cmd = :ask
|
28
|
+
args = [question]
|
29
|
+
opts = {}
|
29
30
|
if enum
|
30
31
|
cmd = :select
|
31
32
|
args << enum
|
@@ -38,50 +39,57 @@ module Libis
|
|
38
39
|
prompt.send(cmd, *args, opts)
|
39
40
|
end
|
40
41
|
|
41
|
-
def tree_select(path, question: nil, file: false, page_size: 22, filter: true, cycle: false, create: false,
|
42
|
+
def tree_select(path, question: nil, file: false, page_size: 22, filter: true, cycle: false, create: false, # rubocop:disable Metrics/ParameterLists
|
42
43
|
default_choices: nil)
|
43
44
|
path = Pathname.new(path) unless path.is_a? Pathname
|
44
45
|
|
45
46
|
return path unless path.exist?
|
47
|
+
|
46
48
|
path = path.realpath
|
47
49
|
|
48
50
|
dirs = path.children.select(&:directory?).sort
|
49
51
|
files = file ? path.children.select(&:file?).sort : []
|
50
52
|
|
51
53
|
choices = []
|
52
|
-
choices << {name: "Folder: #{path}", value: path, disabled: file ? '' : false}
|
54
|
+
choices << { name: "Folder: #{path}", value: path, disabled: file ? '' : false }
|
53
55
|
choices += default_choices if default_choices
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
if create
|
57
|
+
choices << {
|
58
|
+
name: '-- new directory --',
|
59
|
+
value: lambda {
|
60
|
+
new_name = prompt.ask('new directory name:', modify: :trim, required: true)
|
61
|
+
new_path = path + new_name
|
62
|
+
FileUtils.mkdir(new_path.to_path)
|
63
|
+
new_path
|
64
|
+
}
|
65
|
+
}
|
59
66
|
end
|
60
|
-
} if create
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
if file && create
|
69
|
+
choices << {
|
70
|
+
name: '-- new file --', value: lambda {
|
71
|
+
new_name = prompt.ask('new file name:', modify: :trim, required: true)
|
72
|
+
path + new_name
|
73
|
+
}
|
74
|
+
}
|
65
75
|
end
|
66
|
-
} if file && create
|
67
76
|
|
68
|
-
choices << {name: '[..]', value: path.parent}
|
77
|
+
choices << { name: '[..]', value: path.parent }
|
69
78
|
|
70
|
-
dirs.each {|d| choices << {name: "[#{d.basename}]", value: d}}
|
71
|
-
files.each {|f| choices << {name: f.basename.to_path, value: f}}
|
79
|
+
dirs.each { |d| choices << { name: "[#{d.basename}]", value: d } }
|
80
|
+
files.each { |f| choices << { name: f.basename.to_path, value: f } }
|
72
81
|
|
73
82
|
question ||= "Select #{'file or ' if files}directory"
|
74
83
|
selection = prompt.select question, choices,
|
75
|
-
per_page: page_size, filter
|
84
|
+
per_page: page_size, filter:, cycle:, default: file ? 2 : 1
|
76
85
|
|
77
86
|
return selection unless selection.is_a? Pathname
|
78
87
|
return selection.to_path if selection == path || selection.file?
|
79
88
|
|
80
|
-
tree_select selection, question
|
81
|
-
|
89
|
+
tree_select selection, question:, file:, page_size:, filter:,
|
90
|
+
cycle:, create:, default_choices:
|
82
91
|
end
|
83
|
-
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
87
|
-
end
|
95
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'base'
|
2
4
|
require 'libis/format/identifier'
|
3
5
|
require 'chromaprint'
|
@@ -7,24 +9,19 @@ require 'fileutils'
|
|
7
9
|
module Libis
|
8
10
|
module Format
|
9
11
|
module Converter
|
10
|
-
|
11
12
|
class AudioConverter < Libis::Format::Converter::Base
|
12
|
-
|
13
13
|
def self.input_types
|
14
|
-
[
|
14
|
+
%i[MP3 FLAC AC3 AAC WMA ALAC WAV AIFF AMR AU M4A]
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.output_types(format = nil)
|
18
18
|
return [] unless input_types.include?(format)
|
19
|
-
[:MP3, :FLAC, :AC3, :AAC, :WMA, :ALAC, :WAV, :AIFF, :AMR, :AU, :M4A]
|
20
|
-
end
|
21
19
|
|
22
|
-
|
23
|
-
super
|
20
|
+
%i[MP3 FLAC AC3 AAC WMA ALAC WAV AIFF AMR AU M4A]
|
24
21
|
end
|
25
22
|
|
26
|
-
def quiet(
|
27
|
-
@flags[:quiet] = !!
|
23
|
+
def quiet(value)
|
24
|
+
@flags[:quiet] = !!value
|
28
25
|
end
|
29
26
|
|
30
27
|
def format(format)
|
@@ -60,9 +57,9 @@ module Libis
|
|
60
57
|
end
|
61
58
|
|
62
59
|
def web_stream(value)
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
return unless value
|
61
|
+
|
62
|
+
@options[:codec] = 'mp3'
|
66
63
|
end
|
67
64
|
|
68
65
|
def preset(stream, name)
|
@@ -88,7 +85,7 @@ module Libis
|
|
88
85
|
|
89
86
|
elsif File.directory?(source)
|
90
87
|
|
91
|
-
sources = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
|
88
|
+
sources = Dir[File.join(source, '**', '*')].reject { |p| File.directory? p }
|
92
89
|
assemble_and_convert(sources, target)
|
93
90
|
|
94
91
|
else
|
@@ -96,15 +93,14 @@ module Libis
|
|
96
93
|
convert_file(source, target)
|
97
94
|
|
98
95
|
end
|
99
|
-
|
100
96
|
end
|
101
97
|
|
102
98
|
def assemble_and_convert(sources, target)
|
103
99
|
result = {}
|
104
|
-
Tempfile.create(%w
|
105
|
-
sources.each {|src| f.puts src}
|
100
|
+
Tempfile.create(%w[list .txt]) do |f|
|
101
|
+
sources.each { |src| f.puts src }
|
106
102
|
opts[:global] ||= []
|
107
|
-
opts[:global] += %w
|
103
|
+
opts[:global] += %w[-f concat]
|
108
104
|
f.close
|
109
105
|
result = convert_file(f.to_path, target)
|
110
106
|
end
|
@@ -112,19 +108,19 @@ module Libis
|
|
112
108
|
end
|
113
109
|
|
114
110
|
def self.sounds_like(file1, file2, threshold, rate, channels)
|
115
|
-
rate ||=
|
111
|
+
rate ||= 96_000
|
116
112
|
channels ||= 2
|
117
113
|
threshold ||= 0.85
|
118
114
|
|
119
|
-
if File.
|
115
|
+
if File.exist?(file1) && File.exist?(file2)
|
120
116
|
# Convert input files into raw 16-bit signed audio (WAV) to process with Chramaprint
|
121
|
-
file1_raw = File.join('', 'tmp', File.basename(file1)
|
122
|
-
file2_raw = File.join('', 'tmp', File.basename(file2)
|
117
|
+
file1_raw = File.join('', 'tmp', "#{File.basename(file1)}.wav")
|
118
|
+
file2_raw = File.join('', 'tmp', "#{File.basename(file2)}.wav")
|
123
119
|
FileUtils.rm(file1_raw, force: true)
|
124
120
|
FileUtils.rm(file2_raw, force: true)
|
125
121
|
cvt_cmd = Libis::Format::Config[:raw_audio_convert_cmd]
|
126
|
-
|
127
|
-
|
122
|
+
`#{format(cvt_cmd, file1, file1_raw, rate, channels)}`
|
123
|
+
`#{format(cvt_cmd, file2, file2_raw, rate, channels)}`
|
128
124
|
file1_audio = File.binread(file1_raw)
|
129
125
|
file2_audio = File.binread(file2_raw)
|
130
126
|
|
@@ -144,16 +140,15 @@ module Libis
|
|
144
140
|
else
|
145
141
|
false
|
146
142
|
end
|
147
|
-
|
148
143
|
rescue Exception => e
|
149
|
-
|
144
|
+
puts "Error comparing sound file #{file1} and #{file2}: #{e.message} @ #{e.backtrace.first}"
|
150
145
|
false
|
151
146
|
end
|
152
147
|
|
153
148
|
protected
|
154
149
|
|
155
150
|
def convert_file(source, target)
|
156
|
-
opts = {global: [], input: [], filter: [], output: []}
|
151
|
+
opts = { global: [], input: [], filter: [], output: [] }
|
157
152
|
|
158
153
|
opts[:global] << '-hide_banner'
|
159
154
|
opts[:global] << '-loglevel' << (@options[:quiet] ? 'fatal' : 'warning')
|
@@ -161,7 +156,7 @@ module Libis
|
|
161
156
|
opts[:output] << '-codec:a' << @options[:codec] if @options[:codec]
|
162
157
|
opts[:output] << '-map_metadata:g' << '0:g' # Copy global metadata
|
163
158
|
opts[:output] << '-map_metadata:s:a' << '0:s:a' # Copy audio metadata
|
164
|
-
opts[:input] << '-accurate_seek' << (@options[:start].to_i
|
159
|
+
opts[:input] << '-accurate_seek' << (@options[:start].to_i.negative? ? '-sseof' : '-ss') << @options[:start] if @options[:start]
|
165
160
|
opts[:input] << '-t' << @options[:duration] if @options[:duration]
|
166
161
|
opts[:output] << '-q:a' << @options[:quality] if @options[:quality]
|
167
162
|
opts[:output] << '-b:a' << @options[:bit_rate] if @options[:bit_rate]
|
@@ -171,9 +166,7 @@ module Libis
|
|
171
166
|
|
172
167
|
Libis::Format::Tool::FFMpeg.run(source, target, opts)
|
173
168
|
end
|
174
|
-
|
175
169
|
end
|
176
|
-
|
177
170
|
end
|
178
171
|
end
|
179
|
-
end
|
172
|
+
end
|
@@ -97,7 +97,7 @@ module Libis
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def get_fido_identification(file, result, options)
|
100
|
-
output = ::Libis::Format::Tool::Fido.run(file, options[:recursive], options[:fido_options])
|
100
|
+
output = ::Libis::Format::Tool::Fido.run(file, options[:recursive], **(options[:fido_options] || {}))
|
101
101
|
process_tool_output(output, result, options[:base_dir])
|
102
102
|
output
|
103
103
|
end
|
@@ -1,58 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'identification_tool'
|
2
4
|
|
3
5
|
module Libis
|
4
6
|
module Format
|
5
7
|
module Tool
|
6
|
-
|
7
8
|
class ExtensionIdentification < Libis::Format::Tool::IdentificationTool
|
8
|
-
|
9
|
-
def run_list(filelist, _options = {})
|
10
|
-
|
9
|
+
def run_list(filelist, **_options)
|
11
10
|
output = runner(nil, filelist)
|
12
11
|
|
13
12
|
process_output(output)
|
14
|
-
|
15
13
|
end
|
16
14
|
|
17
|
-
def run_dir(dir, recursive = true, _options
|
18
|
-
|
15
|
+
def run_dir(dir, recursive = true, **_options)
|
19
16
|
filelist = find_files(dir, recursive)
|
20
17
|
|
21
18
|
output = runner(nil, filelist)
|
22
19
|
|
23
20
|
process_output(output)
|
24
|
-
|
25
21
|
end
|
26
22
|
|
27
|
-
def run(file, _options)
|
28
|
-
|
23
|
+
def run(file, **_options)
|
29
24
|
output = runner(file)
|
30
25
|
|
31
26
|
process_output(output)
|
32
|
-
|
33
27
|
end
|
34
28
|
|
35
29
|
protected
|
36
30
|
|
37
31
|
def runner(*args)
|
38
|
-
|
39
32
|
args.map do |file|
|
40
33
|
info = ::Libis::Format::TypeDatabase.ext_infos(File.extname(file)).first
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
next unless info
|
35
|
+
|
36
|
+
{
|
37
|
+
filepath: file,
|
38
|
+
mimetype: begin
|
39
|
+
info[:MIME].first
|
40
|
+
rescue StandardError
|
41
|
+
nil
|
42
|
+
end,
|
43
|
+
puid: begin
|
44
|
+
info[:PUID].first
|
45
|
+
rescue StandardError
|
46
|
+
nil
|
47
|
+
end,
|
48
|
+
matchtype: 'extension',
|
49
|
+
tool: :type_database
|
50
|
+
}
|
50
51
|
end.cleanup
|
51
|
-
|
52
52
|
end
|
53
|
-
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
57
55
|
end
|
58
|
-
end
|
56
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'libis/tools/extend/string'
|
2
4
|
require 'libis/tools/command'
|
3
5
|
|
@@ -9,36 +11,33 @@ require_relative 'identification_tool'
|
|
9
11
|
module Libis
|
10
12
|
module Format
|
11
13
|
module Tool
|
12
|
-
|
13
14
|
class Fido < Libis::Format::Tool::IdentificationTool
|
14
|
-
|
15
15
|
def self.add_formats(formats_file)
|
16
|
-
|
16
|
+
instance.formats << formats_file unless instance.formats.include?(formats_file)
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.del_formats(formats_file)
|
20
|
-
|
20
|
+
instance.formats.delete(formats_file)
|
21
21
|
end
|
22
22
|
|
23
23
|
attr_reader :formats
|
24
24
|
|
25
|
-
def run_list(filelist, options
|
25
|
+
def run_list(filelist, **options)
|
26
26
|
create_list_file(filelist) do |list_file|
|
27
|
-
output = runner(nil, '-input', list_file.escape_for_string, options)
|
27
|
+
output = runner(nil, '-input', list_file.escape_for_string, **options)
|
28
28
|
process_output(output)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def run_dir(dir, recursive = true, options
|
32
|
+
def run_dir(dir, recursive = true, **options)
|
33
33
|
args = []
|
34
34
|
args << '-recurse' if recursive
|
35
|
-
args
|
36
|
-
output = runner(dir, *args)
|
35
|
+
output = runner(dir, *args, **options)
|
37
36
|
process_output(output)
|
38
37
|
end
|
39
38
|
|
40
|
-
def run(file, options
|
41
|
-
output = runner(file, options)
|
39
|
+
def run(file, **options)
|
40
|
+
output = runner(file, **options)
|
42
41
|
process_output(output)
|
43
42
|
end
|
44
43
|
|
@@ -53,11 +52,9 @@ module Libis
|
|
53
52
|
|
54
53
|
attr_writer :formats
|
55
54
|
|
56
|
-
def runner(filename, *args)
|
57
|
-
|
58
|
-
|
59
|
-
# Load custome format definitions if present
|
60
|
-
args << '-loadformats' << "#{formats.join(',')}" unless formats.empty?
|
55
|
+
def runner(filename, *args, **options)
|
56
|
+
# Load custom format definitions if present
|
57
|
+
args << '-loadformats' << formats.join(',').to_s unless formats.empty?
|
61
58
|
|
62
59
|
# Workaround for Fido performance bug
|
63
60
|
args << '-bufsize' << (options[:bufsize] || 1000).to_s
|
@@ -68,7 +65,7 @@ module Libis
|
|
68
65
|
args << '-nocontainer' if options[:nocontainer]
|
69
66
|
|
70
67
|
# Add filename to argument list (optional)
|
71
|
-
args <<
|
68
|
+
args << filename.escape_for_string.to_s if filename
|
72
69
|
|
73
70
|
# No header output
|
74
71
|
args << '-q'
|
@@ -76,20 +73,20 @@ module Libis
|
|
76
73
|
# Run command and capture results
|
77
74
|
timeout = Libis::Format::Config[:timeouts][:fido]
|
78
75
|
result = ::Libis::Tools::Command.run(
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
Libis::Format::Config[:fido_cmd], *args,
|
77
|
+
timeout:,
|
78
|
+
kill_after: timeout * 2
|
82
79
|
)
|
83
80
|
|
84
81
|
# Log warning if needed
|
85
|
-
raise
|
86
|
-
raise
|
82
|
+
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
83
|
+
raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty?
|
87
84
|
|
88
85
|
# Parse output (CSV) text into array and return result
|
89
|
-
keys = [
|
86
|
+
keys = %i[status time puid format_name format_version filesize filepath mimetype matchtype]
|
90
87
|
data = CSV.parse(result[:out].join("\n"))
|
91
|
-
|
92
|
-
|
88
|
+
.map { |a| Hash[keys.zip(a)] }
|
89
|
+
.select { |a| a[:status] == 'OK' }
|
93
90
|
data.each do |r|
|
94
91
|
r.delete(:time)
|
95
92
|
r.delete(:status)
|
@@ -97,9 +94,7 @@ module Libis
|
|
97
94
|
r[:tool] = :fido
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
97
|
end
|
102
|
-
|
103
98
|
end
|
104
99
|
end
|
105
100
|
end
|
@@ -1,49 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'identification_tool'
|
2
4
|
|
3
5
|
module Libis
|
4
6
|
module Format
|
5
7
|
module Tool
|
6
|
-
|
7
8
|
class FileTool < Libis::Format::Tool::IdentificationTool
|
8
|
-
|
9
|
-
def run_list(filelist, _options = {})
|
10
|
-
|
9
|
+
def run_list(filelist, **_options)
|
11
10
|
create_list_file(filelist) do |list_file|
|
12
|
-
|
13
11
|
output = runner(nil, '--files-from', list_file)
|
14
12
|
|
15
13
|
process_output(output)
|
16
|
-
|
17
14
|
end
|
18
|
-
|
19
15
|
end
|
20
16
|
|
21
|
-
def run_dir(dir, recursive = true, _options
|
22
|
-
|
17
|
+
def run_dir(dir, recursive = true, **_options)
|
23
18
|
filelist = find_files(dir, recursive)
|
24
19
|
|
25
20
|
create_list_file(filelist) do |list_file|
|
26
|
-
|
27
21
|
output = runner(nil, '--files-from', list_file)
|
28
22
|
|
29
23
|
process_output(output)
|
30
|
-
|
31
24
|
end
|
32
|
-
|
33
25
|
end
|
34
26
|
|
35
|
-
def run(file, _options
|
36
|
-
|
27
|
+
def run(file, **_options)
|
37
28
|
output = runner(file)
|
38
29
|
|
39
30
|
process_output(output)
|
40
|
-
|
41
31
|
end
|
42
32
|
|
43
33
|
protected
|
44
34
|
|
45
35
|
def runner(filename, *args)
|
46
|
-
|
47
36
|
# Create new argument list
|
48
37
|
opts = []
|
49
38
|
|
@@ -61,23 +50,21 @@ module Libis
|
|
61
50
|
# Run the UNIX file command and capture the results
|
62
51
|
timeout = Libis::Format::Config[:timeouts][:file_tool]
|
63
52
|
result = ::Libis::Tools::Command.run(
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
'file', *opts,
|
54
|
+
timeout:,
|
55
|
+
kill_after: timeout * 2
|
67
56
|
)
|
68
57
|
|
69
|
-
raise
|
70
|
-
raise
|
58
|
+
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
59
|
+
raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty?
|
71
60
|
|
72
61
|
# Parse output text into array and return result
|
73
62
|
result[:out].map do |line|
|
74
63
|
r = line.split(/:\s+/)
|
75
|
-
{filepath: r[0], mimetype: r[1], matchtype: 'magic', tool: :file}
|
64
|
+
{ filepath: r[0], mimetype: r[1], matchtype: 'magic', tool: :file }
|
76
65
|
end
|
77
66
|
end
|
78
|
-
|
79
67
|
end
|
80
|
-
|
81
68
|
end
|
82
69
|
end
|
83
70
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'os'
|
2
4
|
|
3
5
|
require 'libis/tools/extend/string'
|
@@ -9,49 +11,46 @@ require 'libis/format/config'
|
|
9
11
|
module Libis
|
10
12
|
module Format
|
11
13
|
module Tool
|
12
|
-
|
13
14
|
class FopPdf
|
14
15
|
include ::Libis::Tools::Logger
|
15
16
|
|
16
17
|
def self.installed?
|
17
|
-
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd],
|
18
|
-
return false unless result[:status]
|
18
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], '-version')
|
19
|
+
return false unless (result[:status]).zero?
|
20
|
+
|
19
21
|
File.exist?(Libis::Format::Config[:fop_jar])
|
20
22
|
end
|
21
23
|
|
22
|
-
def self.run(xml, target
|
23
|
-
|
24
|
+
def self.run(xml, target)
|
25
|
+
new.run xml, target
|
24
26
|
end
|
25
27
|
|
26
|
-
def run(xml, target
|
27
|
-
|
28
|
+
def run(xml, target)
|
28
29
|
if OS.java?
|
29
30
|
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
30
31
|
end
|
31
32
|
|
32
33
|
timeout = Libis::Format::Config[:timeouts][:fop]
|
33
34
|
result = Libis::Tools::Command.run(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
Libis::Format::Config[:java_cmd],
|
36
|
+
"-Dfop.home=#{File.dirname(Libis::Format::Config[:fop_jar])}",
|
37
|
+
'-Djava.awt.headless=true',
|
38
|
+
'-jar', Libis::Format::Config[:fop_jar],
|
39
|
+
'-fo', xml,
|
40
|
+
'-pdf', target,
|
41
|
+
timeout:,
|
42
|
+
kill_after: timeout * 2
|
42
43
|
)
|
43
44
|
|
44
|
-
raise
|
45
|
-
raise
|
45
|
+
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
46
|
+
raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero?
|
46
47
|
|
47
48
|
{
|
48
49
|
command: result,
|
49
|
-
files: [
|
50
|
+
files: [target]
|
50
51
|
}
|
51
|
-
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
54
|
end
|
56
55
|
end
|
57
56
|
end
|