libis-format 1.0.8 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4de569e2d7055cf0d08602b481e3e7e2eb981a3dfc81968b2ebb19239244ffb
4
- data.tar.gz: 402ec6e4ab234d75e8dadc3bf862398cb81dd7563d7c316279aad82f098ab3e4
3
+ metadata.gz: 40c91211db466867a86d905e707302783d77f8ce96bce970229294fc3506f4dd
4
+ data.tar.gz: 3254048984ba29c9c6a1d556f25e7dc346ba1c0fc2082b80562c3ae64f41dc8f
5
5
  SHA512:
6
- metadata.gz: 38bb64081e41ca8abe3e43b26610989162f5b6cc9f3f4e0123d524d5519dbb879dd0a1634920ceb78690cd06ee81dc8bfdf8a7cf0e6719832f399c716d8a4c7c
7
- data.tar.gz: 70c249c6b0814614e7408bb9fa7b448af8db3ea54bda3028f7a49ac79987e254b309a53effa3334713e3e853c09942809bb26d2b4ee09e79823ee50c88661c12
6
+ metadata.gz: caa9a7a5cbc6e99c7d1afb8af83274b2db4de847fde394d3d9cdc1129019044353bdbe6527fb4aabbcb8817be175e99f6bac1eeef0b79eb3e7ab94b7594db4ce
7
+ data.tar.gz: f3ade6093b38aab4b8c529c0d80e5a822aa2042264efc8d076077f74ee0cd20ebd91dbe5b2d6d030394607fcde196b28c8dabc2659788308e926981cca880905
data/Gemfile CHANGED
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
3
3
  gem 'coveralls', group: :test, require: false
4
4
 
5
5
  gemspec name: 'libis-format', development_group: :test
6
+
7
+ gem 'standard'
@@ -12,7 +12,6 @@ module Libis
12
12
  Config[:java_cmd] = 'java'
13
13
  Config[:j2k_cmd] = 'j2kdriver'
14
14
  Config[:soffice_cmd] = 'soffice'
15
- Config[:emai2pdf_cmd] = 'convert_email'
16
15
  Config[:ghostscript_cmd] = 'gs'
17
16
  Config[:droid_cmd] = '/opt/droid/droid.sh'
18
17
  Config[:droid_temp_path] = '/tmp'
@@ -22,6 +21,7 @@ module Libis
22
21
  Config[:fido_formats] = [(File.join(Libis::Format::DATA_DIR, 'lias_formats.xml'))]
23
22
  Config[:pdf_tool] = File.join(Libis::Format::TOOL_DIR, 'PdfTool.jar')
24
23
  Config[:preflight_jar] = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-2.0.13.jar')
24
+ Config[:emai2pdf_jar] = File.join(Libis::Format::TOOL_DIR, 'emailconverter.jar')
25
25
  # noinspection RubyStringKeysInHashInspection
26
26
  Config[:xml_validations] = [['archive/ead', File.join(Libis::Format::DATA_DIR, 'ead.xsd')]]
27
27
  Config[:type_database] = File.join(Libis::Format::DATA_DIR, 'types.yml')
@@ -97,19 +97,18 @@ module Libis
97
97
 
98
98
  end
99
99
 
100
- target
101
-
102
100
  end
103
101
 
104
102
  def assemble_and_convert(sources, target)
103
+ result = {}
105
104
  Tempfile.create(%w(list .txt)) do |f|
106
105
  sources.each {|src| f.puts src}
107
106
  opts[:global] ||= []
108
107
  opts[:global] += %w(-f concat)
109
108
  f.close
110
- target = convert_file(f.to_path, target)
109
+ result = convert_file(f.to_path, target)
111
110
  end
112
- target
111
+ result
113
112
  end
114
113
 
115
114
  def self.sounds_like(file1, file2, threshold, rate, channels)
@@ -155,6 +154,7 @@ module Libis
155
154
 
156
155
  def convert_file(source, target)
157
156
  opts = {global: [], input: [], filter: [], output: []}
157
+
158
158
  opts[:global] << '-hide_banner'
159
159
  opts[:global] << '-loglevel' << (@options[:quiet] ? 'fatal' : 'warning')
160
160
  opts[:output] << '-vn' # disable input video stream in case it exists
@@ -168,10 +168,8 @@ module Libis
168
168
  opts[:output] << '-ar' << @options[:sampling_freq] if @options[:sampling_freq]
169
169
  opts[:output] << '-ac' << @options[:channels] if @options[:channels]
170
170
  opts[:output] << '-f' << @options[:format] if @options[:format]
171
- result = Libis::Format::Tool::FFMpeg.run(source, target, opts)
172
- info "FFMpeg output: #{result}"
173
- result
174
- target
171
+
172
+ Libis::Format::Tool::FFMpeg.run(source, target, opts)
175
173
  end
176
174
 
177
175
  end
@@ -68,14 +68,18 @@ module Libis
68
68
  end
69
69
 
70
70
  temp_files = []
71
+ xtra_files = []
72
+
73
+ result = { commands: [] }
71
74
 
72
75
  # noinspection RubyParenthesesAroundConditionInspection
73
- result = @converter_chain.each_with_index do |node, i|
76
+ conversion_success = converter_chain.each_with_index do |node, i|
74
77
 
75
78
  target_type = node[:output]
76
79
  converter_class = node[:converter]
77
80
  converter = converter_class.new
78
81
 
82
+
79
83
  node[:operations].each do |operation|
80
84
  converter.send operation[:method], operation[:argument]
81
85
  end if node[:operations]
@@ -90,17 +94,25 @@ module Libis
90
94
 
91
95
  FileUtils.mkdir_p File.dirname(target)
92
96
 
93
- src_file = converter.convert(src_file, target, target_type)
97
+ r = converter.convert(src_file, target, target_type)
98
+
99
+ src_file = r[:files].first
100
+ xtra_files += r[:files][1..]
101
+ break :failed unless src_file1
94
102
 
95
- break :failed unless src_file
103
+ result[:commands] << r.merge(converter: converter_class.name)
104
+
105
+ :success
96
106
 
97
107
  end
98
108
 
109
+ result[:files] = [src_file] + xtra_files
110
+
99
111
  temp_files.each do |f|
100
112
  FileUtils.rm(f, force: true)
101
113
  end
102
114
 
103
- result == :failed ? nil : target_file
115
+ conversion_success == :failed ? nil : result
104
116
 
105
117
  end
106
118
 
@@ -4,6 +4,7 @@ require_relative 'base'
4
4
 
5
5
  require 'libis/format/tool/email_to_pdf'
6
6
  require 'libis/format/type_database'
7
+ require 'rexml/document'
7
8
 
8
9
  module Libis
9
10
  module Format
@@ -27,10 +28,7 @@ module Libis
27
28
  def convert(source, target, format, opts = {})
28
29
  super
29
30
 
30
- return nil unless Format::Tool::EmailToPdf.run(source, target)
31
-
32
- target
33
-
31
+ Format::Tool::EmailToPdf.run(source, target)
34
32
  end
35
33
 
36
34
  end
@@ -31,8 +31,6 @@ module Libis
31
31
 
32
32
  Libis::Format::Tool::FopPdf.run(source, target)
33
33
 
34
- target
35
-
36
34
  end
37
35
 
38
36
  end
@@ -180,9 +180,11 @@ module Libis
180
180
  convert_image(source, target, format)
181
181
  end
182
182
  end
183
-
184
- target
185
-
183
+
184
+ {
185
+ files: [target],
186
+ converter: self.class.name
187
+ }
186
188
  end
187
189
 
188
190
  def assemble_and_convert(sources, target, format)
@@ -90,16 +90,16 @@ module Libis
90
90
  end
91
91
 
92
92
 
93
- Libis::Tools::Command.run(
93
+ result = Libis::Tools::Command.run(
94
94
  Libis::Format::Config[:j2k_cmd],
95
95
  '--input-file-name', source,
96
96
  '--set-output-type', 'JP2',
97
97
  *options,
98
98
  '--output-file-name', target,
99
-
100
99
  )
101
100
 
102
- target
101
+ result.merge(files: [target], converter: self.class.name)
102
+
103
103
  end
104
104
  end
105
105
  end
@@ -43,9 +43,7 @@ module Libis
43
43
  def convert(source, target, format, opts = {})
44
44
  super
45
45
 
46
- return nil unless Format::Tool::OfficeToPdf.run(source, target)
47
-
48
- target
46
+ Format::Tool::OfficeToPdf.run(source, target)
49
47
 
50
48
  end
51
49
 
@@ -119,7 +119,10 @@ module Libis
119
119
  result = pdf_to_pdfa(source, target)
120
120
  end
121
121
 
122
- result
122
+ {
123
+ files: [result]
124
+ converter: self.class.name
125
+ }
123
126
 
124
127
  end
125
128
 
@@ -31,9 +31,7 @@ module Libis
31
31
  def convert(source, target, format, opts = {})
32
32
  super
33
33
 
34
- return nil unless Format::Tool::SpreadsheetToOds.run(source, target)
35
-
36
- target
34
+ Format::Tool::SpreadsheetToOds.run(source, target)
37
35
 
38
36
  end
39
37
 
@@ -1,5 +1,5 @@
1
1
  require_relative 'base'
2
- require 'libis/format/tool/ffmpeg'
2
+ require 'libis/format/tool/ff_mpeg'
3
3
 
4
4
  require 'fileutils'
5
5
 
@@ -179,7 +179,10 @@ module Libis
179
179
 
180
180
  end
181
181
 
182
- target
182
+ {
183
+ files: [target],
184
+ converter: self.class.name
185
+ }
183
186
 
184
187
  end
185
188
 
@@ -1,40 +1,75 @@
1
- require 'fileutils'
1
+ require "fileutils"
2
2
 
3
- require 'libis/tools/extend/string'
4
- require 'libis/tools/logger'
5
- require 'libis/tools/command'
3
+ require "libis/tools/extend/string"
4
+ require "libis/tools/logger"
5
+ require "libis/tools/command"
6
6
 
7
- require 'libis/format/config'
7
+ require "libis/format/config"
8
+ require "rexml/document"
8
9
 
9
10
  module Libis
10
11
  module Format
11
12
  module Tool
12
-
13
13
  class EmailToPdf
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:email2pdf_cmd], "-v")
18
+ result[:status] == 0
19
+ end
20
+
16
21
  def self.run(source, target, options = {})
17
- self.new.run source, target, options
22
+ new.run source, target, options
18
23
  end
19
24
 
20
25
  def run(source, target, _ = {})
21
26
  timeout = Libis::Format::Config[:timeouts][:email2pdf] || 120
22
27
  result = Libis::Tools::Command.run(
23
- Libis::Format::Config[:email2pdf_cmd],
24
- source,
25
- target,
26
- timeout: timeout,
27
- kill_after: timeout * 2
28
+ Libis::Format::Config[:java_cmd],
29
+ "-Duser.timezone=Europe/Brussels -Duser.language=nl -Duser.country=BE",
30
+ "jar", Libis::Format::Config[:email2pdf_cmd],
31
+ "-e", "-hd", "-a",
32
+ "-o", target,
33
+ source,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
28
36
  )
29
37
 
30
- raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
31
- warn "EmailToPdf conversion messages: \n\t#{result[:out].join("\n\t")}" unless result[:err].empty?
32
- raise RuntimeError, "#{self.class} failed to generate target file #{target}" unless File.exist?(target)
38
+ warn "EmailToPdf conversion messages: \n\t#{result[:out].join("\n\t")}" unless result[:out].empty?
39
+
40
+ raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
41
+ raise "#{self.class} failed to generate target file #{target}" unless File.exist?(target)
42
+ raise "#{self.class} command failed with status code #{result[:status]}" unless result[:status] == 0
43
+
44
+ base_path = File.join(File.dirname(target), File.basename(target, ".*"))
45
+ headers_file = "#{base_path}.headers.xml"
46
+ headers = read_header(headers_file)
33
47
 
34
- nil
48
+ {
49
+ command: result,
50
+ files: [target, headers_file] + headers[:attachments].map { |a| File.join("#{base_path}-attachments", a) },
51
+ headers: headers
52
+ }
35
53
  end
36
- end
37
54
 
55
+ private
56
+
57
+ def read_header(headers_file)
58
+ headers = {}
59
+ return headers unless File.exist?(headers_file)
60
+ doc = REXML::Document.new(File.new(headers_file))
61
+ root = doc.root
62
+ root.elements("/emailheader/*").each do |element|
63
+ case element.name
64
+ when "attachments"
65
+ headers[:attachments] = element.elements.map { |e| e.text }
66
+ else
67
+ headers[element.name.to_sym] = element.text
68
+ end
69
+ end
70
+ headers
71
+ end
72
+ end
38
73
  end
39
74
  end
40
75
  end
@@ -13,6 +13,11 @@ module Libis
13
13
  include Singleton
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:ffmpeg_cmd], "-h")
18
+ result[:status] == 0
19
+ end
20
+
16
21
  def self.run(source, target, options = {})
17
22
  self.instance.run source, target, options
18
23
  end
@@ -38,7 +43,11 @@ module Libis
38
43
 
39
44
  warn "FFMpeg warnings: #{(result[:err] + result[:out]).join("\n")}" unless result[:err].empty?
40
45
 
41
- result[:out]
46
+ {
47
+ command: result,
48
+ files: [ target ]
49
+ }
50
+
42
51
  end
43
52
 
44
53
  end
@@ -13,6 +13,12 @@ module Libis
13
13
  class FopPdf
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
18
+ return false unless result[:status] == 0
19
+ File.exist?(Libis::Format::Config[:fop_jar])
20
+ end
21
+
16
22
  def self.run(xml, target, options = [])
17
23
  self.new.run xml, target, options
18
24
  end
@@ -37,6 +43,11 @@ module Libis
37
43
  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
38
44
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0
39
45
 
46
+ {
47
+ command: result,
48
+ files: [ target ]
49
+ }
50
+
40
51
  end
41
52
  end
42
53
 
@@ -13,6 +13,11 @@ module Libis
13
13
  class OfficeToPdf
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:soffice_cmd], "--version")
18
+ result[:status] == 0
19
+ end
20
+
16
21
  def self.run(source, target, options = {})
17
22
  self.new.run source, target, options
18
23
  end
@@ -50,7 +55,11 @@ module Libis
50
55
  ensure
51
56
  FileUtils.rmtree workdir rescue nil
52
57
 
53
- result[:out]
58
+ {
59
+ command: result,
60
+ files: [ target ]
61
+ }
62
+
54
63
  end
55
64
  end
56
65
 
@@ -13,6 +13,12 @@ module Libis
13
13
  class PdfCopy
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
18
+ return false unless result[:status] == 0
19
+ File.exist?(Libis::Format::Config[:pdf_tool])
20
+ end
21
+
16
22
  def self.run(source, target, options = [])
17
23
  self.new.run source, target, options
18
24
  end
@@ -38,7 +44,11 @@ module Libis
38
44
  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
45
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
46
 
41
- result
47
+ {
48
+ command: result,
49
+ files: [ target ]
50
+ }
51
+
42
52
  end
43
53
  end
44
54
 
@@ -13,6 +13,12 @@ module Libis
13
13
  class PdfMerge
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
18
+ return false unless result[:status] == 0
19
+ File.exist?(Libis::Format::Config[:pdf_tool])
20
+ end
21
+
16
22
  def self.run(source, target, options = [])
17
23
  self.new.run source, target, options
18
24
  end
@@ -39,7 +45,11 @@ module Libis
39
45
  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
40
46
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
41
47
 
42
- result
48
+ {
49
+ command: result,
50
+ files: [ target ]
51
+ }
52
+
43
53
  end
44
54
  end
45
55
 
@@ -13,6 +13,11 @@ module Libis
13
13
  class PdfOptimizer
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:ghostscript_cmd], "--version")
18
+ result[:status] == 0
19
+ end
20
+
16
21
  def self.run(source, target, quality)
17
22
  self.new.run source, target, quality
18
23
  end
@@ -21,7 +26,7 @@ module Libis
21
26
 
22
27
  timeout = Libis::Format::Config[:timeouts][:pdf_optimizer]
23
28
  result = Libis::Tools::Command.run(
24
- 'gs',
29
+ Libis::Format::Config[:ghostscript_cmd],
25
30
  '-sDEVICE=pdfwrite',
26
31
  '-dCompatibilityLevel=1.4',
27
32
  "-dPDFSETTINGS=/#{quality}",
@@ -36,7 +41,11 @@ module Libis
36
41
  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
37
42
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0
38
43
 
39
- result
44
+ {
45
+ command: result,
46
+ files: [ target ]
47
+ }
48
+
40
49
  end
41
50
  end
42
51
 
@@ -13,6 +13,12 @@ module Libis
13
13
  class PdfSplit
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
18
+ return false unless result[:status] == 0
19
+ File.exist?(Libis::Format::Config[:pdf_tool])
20
+ end
21
+
16
22
  def self.run(source, target, options = [])
17
23
  self.new.run source, target, options
18
24
  end
@@ -38,7 +44,11 @@ module Libis
38
44
  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
45
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
46
 
41
- result
47
+ {
48
+ command: result,
49
+ files: [ target ] # TODO: collect the files
50
+ }
51
+
42
52
  end
43
53
  end
44
54
 
@@ -16,6 +16,11 @@ module Libis
16
16
  class PdfToPdfa
17
17
  include ::Libis::Tools::Logger
18
18
 
19
+ def self.installed?
20
+ result = Libis::Tools::Command.run(Libis::Format::Config[:ghostscript_cmd])
21
+ result == 0
22
+ end
23
+
19
24
  def self.run(source, target = nil, options = {})
20
25
  self.new.run source, target, options
21
26
  end
@@ -61,7 +66,11 @@ module Libis
61
66
  result[:err] << 'Failed to validate generated PDF/A file.'
62
67
  end
63
68
 
64
- result
69
+ {
70
+ command: result,
71
+ files: [ target ]
72
+ }
73
+
65
74
  end
66
75
 
67
76
 
@@ -13,6 +13,11 @@ module Libis
13
13
  class SpreadsheetToOds
14
14
  include ::Libis::Tools::Logger
15
15
 
16
+ def self.installed?
17
+ result = Libis::Tools::Command.run(Libis::Format::Config[:soffice_cmd], "--version")
18
+ result == 0
19
+ end
20
+
16
21
  def self.run(source, target, options = {})
17
22
  self.new.run source, target, options
18
23
  end
@@ -51,7 +56,11 @@ module Libis
51
56
  ensure
52
57
  FileUtils.rmtree workdir rescue nil
53
58
 
54
- result[:out]
59
+ {
60
+ command: result,
61
+ files: [ target ]
62
+ }
63
+
55
64
  end
56
65
  end
57
66
 
@@ -10,7 +10,7 @@ module Libis
10
10
  autoload :FileTool, 'libis/format/tool/file_tool'
11
11
 
12
12
  autoload :OfficeToPdf, 'libis/format/tool/office_to_pdf'
13
- autoload :FFMpeg, 'libis/format/tool/ffmpeg'
13
+ autoload :FFMpeg, 'libis/format/tool/ff_mpeg'
14
14
  autoload :FopPdf, 'libis/format/tool/fop_pdf'
15
15
  autoload :PdfCopy, 'libis/format/tool/pdf_copy'
16
16
  autoload :PdfMerge, 'libis/format/tool/pdf_merge'
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Format
3
- VERSION = '1.0.8'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
11
+ date: 2023-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -228,7 +228,7 @@ files:
228
228
  - lib/libis/format/tool/droid.rb
229
229
  - lib/libis/format/tool/email_to_pdf.rb
230
230
  - lib/libis/format/tool/extension_identification.rb
231
- - lib/libis/format/tool/ffmpeg.rb
231
+ - lib/libis/format/tool/ff_mpeg.rb
232
232
  - lib/libis/format/tool/fido.rb
233
233
  - lib/libis/format/tool/file_tool.rb
234
234
  - lib/libis/format/tool/fop_pdf.rb
@@ -248,6 +248,7 @@ files:
248
248
  - tools/PdfTool.jar
249
249
  - tools/bcpkix-jdk15on-1.49.jar
250
250
  - tools/bcprov-jdk15on-1.49.jar
251
+ - tools/emailconverter.jar
251
252
  - tools/fop/build/fop.jar
252
253
  - tools/fop/conf/fop.xconf
253
254
  - tools/fop/fop