libis-format 0.9.37 → 0.9.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libis/format/identifier.rb +25 -22
- data/lib/libis/format/version.rb +1 -1
- data/spec/identifier_spec.rb +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee2f761cde56c377abdfff7b7d40d09c32c0c93
|
4
|
+
data.tar.gz: 5d6384f6484d04ec01705883e04ead5b0d02dacb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a359cd06cc1f3f442b69981858e44e55f4cd085e0e0291e4b03c0a530e86d5f5e72d1083cc7b2fa306fdd4dba033ce4eb985c49373fe0d4467052f1406146a3
|
7
|
+
data.tar.gz: 619bdb26cfea98753544d47fd1096150cd2f7ec56e5322bffabf6a4c598797f31be68d22b3f7f267aebcc5f743ae6d60bcd498a1eb27af183a5b0a5cbae7c0a9
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'singleton'
|
4
|
+
require 'pathname'
|
4
5
|
|
5
6
|
require 'libis-tools'
|
6
7
|
require 'libis/tools/extend/hash'
|
@@ -48,19 +49,19 @@ module Libis
|
|
48
49
|
result = {messages: [], output: {}, formats: {}}
|
49
50
|
|
50
51
|
begin
|
51
|
-
get_droid_identification(file,
|
52
|
+
get_droid_identification(file, result, options) if options[:droid]
|
52
53
|
rescue => e
|
53
54
|
log_msg(result, :error, "Error running Droid: #{e.message} @ #{e.backtrace.first}")
|
54
55
|
end
|
55
56
|
|
56
57
|
begin
|
57
|
-
get_fido_identification(file,
|
58
|
+
get_fido_identification(file, result, options) if options[:fido]
|
58
59
|
rescue => e
|
59
60
|
log_msg(result, :error, "Error running Fido: #{e.message} @ #{e.backtrace.first}")
|
60
61
|
end
|
61
62
|
|
62
63
|
begin
|
63
|
-
get_file_identification(file,
|
64
|
+
get_file_identification(file, result, options) if options[:file]
|
64
65
|
rescue => e
|
65
66
|
log_msg(result, :error, "Error running File: #{e.message} @ #{e.backtrace.first}")
|
66
67
|
end
|
@@ -71,7 +72,7 @@ module Libis
|
|
71
72
|
# determine XML type. Add custom types at runtime with
|
72
73
|
# Libis::Tools::Format::Identifier.add_xml_validation('my_type', '/path/to/my_type.xsd')
|
73
74
|
begin
|
74
|
-
validate_against_xml_schema(result) if options[:xml_validation]
|
75
|
+
validate_against_xml_schema(result, options[:base_dir]) if options[:xml_validation]
|
75
76
|
rescue => e
|
76
77
|
log_msg(result, :error, "Error validating XML files: #{e.message} @ #{e.backtrace.first}")
|
77
78
|
end
|
@@ -88,41 +89,42 @@ module Libis
|
|
88
89
|
@xml_validations = Libis::Format::Config[:xml_validations].to_h
|
89
90
|
end
|
90
91
|
|
91
|
-
def get_file_identification(file,
|
92
|
-
output = ::Libis::Format::FileTool.run(file, recursive)
|
93
|
-
process_tool_output(output, result)
|
92
|
+
def get_file_identification(file, result, options)
|
93
|
+
output = ::Libis::Format::FileTool.run(file, options[:recursive])
|
94
|
+
process_tool_output(output, result, options[:base_dir])
|
94
95
|
output
|
95
96
|
end
|
96
97
|
|
97
|
-
def get_fido_identification(file,
|
98
|
-
output = ::Libis::Format::Fido.run(file, recursive)
|
99
|
-
process_tool_output(output, result)
|
98
|
+
def get_fido_identification(file, result, options)
|
99
|
+
output = ::Libis::Format::Fido.run(file, options[:recursive])
|
100
|
+
process_tool_output(output, result, options[:base_dir])
|
100
101
|
output
|
101
102
|
end
|
102
103
|
|
103
|
-
def get_droid_identification(file,
|
104
|
-
output = ::Libis::Format::Droid.run(file, recursive)
|
105
|
-
process_tool_output(output, result)
|
104
|
+
def get_droid_identification(file, result, options)
|
105
|
+
output = ::Libis::Format::Droid.run(file, options[:recursive])
|
106
|
+
process_tool_output(output, result, options[:base_dir])
|
106
107
|
output
|
107
108
|
end
|
108
109
|
|
109
|
-
def get_extension_identification(file,
|
110
|
-
output = ::Libis::Format::ExtensionIdentification.run(file, recursive)
|
111
|
-
process_tool_output(output, result)
|
110
|
+
def get_extension_identification(file, result, options)
|
111
|
+
output = ::Libis::Format::ExtensionIdentification.run(file, options[:recursive])
|
112
|
+
process_tool_output(output, result, options[:base_dir])
|
112
113
|
output
|
113
114
|
end
|
114
115
|
|
115
|
-
def validate_against_xml_schema(result)
|
116
|
+
def validate_against_xml_schema(result, base_dir)
|
116
117
|
result[:output].each do |file, file_results|
|
117
118
|
file_results.each do |file_result|
|
118
|
-
xml_validate(file, file_result, result)
|
119
|
+
xml_validate(file, file_result, result, base_dir)
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
|
-
def xml_validate(file, file_result, result)
|
124
|
+
def xml_validate(file, file_result, result, base_dir)
|
124
125
|
return unless file_result[:mimetype] =~ /^(text|application)\/xml$/
|
125
|
-
|
126
|
+
filepath = base_dir ? File.join(base_dir, file) : file
|
127
|
+
doc = ::Libis::Tools::XmlDocument.open filepath
|
126
128
|
xml_validations.each do |mime, xsd_file|
|
127
129
|
next unless xsd_file
|
128
130
|
begin
|
@@ -165,7 +167,7 @@ module Libis
|
|
165
167
|
end
|
166
168
|
case format_matches.count
|
167
169
|
when 0
|
168
|
-
# No this really cannot happen. If there are
|
170
|
+
# No this really cannot happen. If there are no hits, there will be at least a format [nil,nil]
|
169
171
|
when 1
|
170
172
|
# only one match, that's easy. The first of the highest score will be used
|
171
173
|
file_result.merge!(get_best_result(output))
|
@@ -192,8 +194,9 @@ module Libis
|
|
192
194
|
|
193
195
|
private
|
194
196
|
|
195
|
-
def process_tool_output(output, result)
|
197
|
+
def process_tool_output(output, result, base_dir)
|
196
198
|
output.each do |file, file_output|
|
199
|
+
file = Pathname.new(file).relative_path_from(Pathname(base_dir)).to_s.freeze if base_dir
|
197
200
|
result[:output][file] ||= []
|
198
201
|
result[:output][file] += file_output
|
199
202
|
end
|
data/lib/libis/format/version.rb
CHANGED
data/spec/identifier_spec.rb
CHANGED
@@ -70,10 +70,10 @@ describe 'Identfier' do
|
|
70
70
|
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
71
71
|
::Libis::Tools::Config.logger.level = :all
|
72
72
|
::Libis::Format::Config[:droid_path] = '/opt/droid/droid.sh'
|
73
|
-
::Libis::Format::Config[:fido_path] = '
|
73
|
+
::Libis::Format::Config[:fido_path] = File.join(ENV['HOME'], 'bin', 'fido')
|
74
74
|
end
|
75
75
|
|
76
|
-
let (:identifier) {
|
76
|
+
let (:identifier) {::Libis::Format::Identifier}
|
77
77
|
let (:logoutput) {::Libis::Tools::Config.logger.appenders.last.sio}
|
78
78
|
let (:dir) {File.join File.absolute_path(File.dirname(__FILE__)), 'data'}
|
79
79
|
|
@@ -114,6 +114,14 @@ describe 'Identfier' do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
it 'should identify all files in a folder with base_dir option' do
|
118
|
+
result = identifier.get(dir, base_dir: dir)
|
119
|
+
expect(result[:formats].size).to be >= formatlist.size
|
120
|
+
formatlist.each do |file, format|
|
121
|
+
expect(result[:formats][file]).to include format
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
117
125
|
it 'should identify all files in a list at once' do
|
118
126
|
filelist = fidolist.keys.map {|file| File.join(dir, file)}
|
119
127
|
result = identifier.get (filelist)
|
@@ -123,6 +131,15 @@ describe 'Identfier' do
|
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
134
|
+
it 'should identify all files in a list with base_dir option' do
|
135
|
+
filelist = fidolist.keys.map {|file| File.join(dir, file)}
|
136
|
+
result = identifier.get(filelist, base_dir: dir)
|
137
|
+
expect(result[:formats].size).to be >= formatlist.size
|
138
|
+
formatlist.each do |file, format|
|
139
|
+
expect(result[:formats][file]).to include format
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
126
143
|
context 'individual files' do
|
127
144
|
|
128
145
|
formatlist.each do |file, format|
|
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: 0.9.
|
4
|
+
version: 0.9.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|