hydra-derivatives 3.3.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +53 -34
  3. data/.rubocop_todo.yml +42 -9
  4. data/.travis.yml +12 -0
  5. data/Gemfile +3 -3
  6. data/Rakefile +1 -1
  7. data/VERSION +1 -1
  8. data/config/fcrepo_wrapper_test.yml +6 -0
  9. data/hydra-derivatives.gemspec +7 -10
  10. data/lib/hydra/derivatives.rb +2 -2
  11. data/lib/hydra/derivatives/audio_encoder.rb +1 -1
  12. data/lib/hydra/derivatives/io_decorator.rb +11 -6
  13. data/lib/hydra/derivatives/logger.rb +5 -1
  14. data/lib/hydra/derivatives/processors/active_encode.rb +1 -1
  15. data/lib/hydra/derivatives/processors/full_text.rb +5 -0
  16. data/lib/hydra/derivatives/processors/jpeg2k_image.rb +5 -8
  17. data/lib/hydra/derivatives/runners/full_text_extract.rb +1 -1
  18. data/lib/hydra/derivatives/services/capability_service.rb +1 -1
  19. data/lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb +5 -1
  20. data/lib/hydra/derivatives/services/persist_output_file_service.rb +4 -2
  21. data/spec/processors/active_encode_spec.rb +8 -8
  22. data/spec/processors/document_spec.rb +2 -2
  23. data/spec/processors/full_text_spec.rb +32 -12
  24. data/spec/processors/image_spec.rb +12 -10
  25. data/spec/processors/processor_spec.rb +4 -4
  26. data/spec/processors/video_spec.rb +5 -3
  27. data/spec/runners/active_encode_derivatives_spec.rb +2 -2
  28. data/spec/services/audio_derivatives_spec.rb +1 -1
  29. data/spec/services/persist_basic_contained_output_file_service_spec.rb +4 -2
  30. data/spec/services/remote_source_file_spec.rb +3 -3
  31. data/spec/services/tempfile_service_spec.rb +3 -2
  32. data/spec/units/config_spec.rb +2 -2
  33. data/spec/units/derivatives_spec.rb +6 -4
  34. data/spec/units/io_decorator_spec.rb +14 -2
  35. data/spec/units/logger_spec.rb +1 -1
  36. data/spec/units/transcoding_spec.rb +23 -15
  37. metadata +53 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3cb485ab21d05631d5c5643d6fe6726d2dc82fb3
4
- data.tar.gz: 2f30a6f276a10e750bd4d1f5acde291d775e5668
2
+ SHA256:
3
+ metadata.gz: 8528fcd35248b83ece67695b925ea0339e98c4b903d07509377b22907d1b7aa4
4
+ data.tar.gz: 142811abdaf02fa588a3e7cd7cf6441033561fbcd984710cd2b7220b733a3546
5
5
  SHA512:
6
- metadata.gz: 6b0618b15bb531bbe5d2b476b790b3f26652a8ebab3403a325ff720d2fc16b933de2e8c37e94521eb14e405b1f15ceda036c0ef647808d995e81389fb471a250
7
- data.tar.gz: 02225a904af793102c24dbd983116640dea8183ce331f0fb40830095d8012466dfe7c5870ca0a6f398956b2bbdaffeaadfa555d1e7a49c8db936caf65e759c6d
6
+ metadata.gz: cffe7544e081933bce5083c6c6516bb29faf383cfbcf002511048899bb9ae11dcfa4d7b06198a888757d7ab79a9fa142971333f209738068ec579a6be5ec67fb
7
+ data.tar.gz: a9d7f1cd5914313b3febd42691e503d1262853bb6e8128dae093647b50fd74d2627d18f2a1e7955dbee51aced523705ed1c1ab9260921f6b9c8cf549e53800ae
@@ -3,42 +3,35 @@ inherit_from: .rubocop_todo.yml
3
3
 
4
4
  AllCops:
5
5
  DisplayCopNames: true
6
- Include:
7
- - '**/Rakefile'
8
6
  Exclude:
9
7
  - 'vendor/**/*'
10
8
  - 'spec/internal/bin/*'
11
9
  - 'spec/internal/db/schema.rb'
10
+ - Gemfile
11
+ - hydra-derivatives.gemspec
12
+ - Rakefile
12
13
 
13
- Metrics/LineLength:
14
- Enabled: false
15
-
16
- Style/CollectionMethods:
17
- PreferredMethods:
18
- collect: 'map'
19
- collect!: 'map!'
20
- inject: 'reduce'
21
- detect: 'find'
22
- find_all: 'select'
23
-
24
- Style/ClassAndModuleChildren:
25
- Enabled: false
14
+ Layout/IndentationConsistency:
15
+ EnforcedStyle: rails
26
16
 
27
- Style/Documentation:
28
- Enabled: false
17
+ Metrics/AbcSize:
18
+ Max: 42
19
+ Exclude:
20
+ - lib/hydra/derivatives/processors/document.rb
21
+ - lib/hydra/derivatives/processors/full_text.rb
22
+ - lib/hydra/derivatives/processors/jpeg2k_image.rb
23
+ - lib/hydra/derivatives/processors/shell_based_processor.rb
24
+ - lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb
25
+ - lib/hydra/derivatives/services/tempfile_service.rb
29
26
 
30
- Style/StringLiterals:
31
- Enabled: false
27
+ Metrics/BlockLength:
28
+ Max: 320
32
29
 
33
- Style/SignalException:
30
+ Metrics/LineLength:
34
31
  Enabled: false
35
32
 
36
- Style/IndentationConsistency:
37
- EnforcedStyle: rails
38
-
39
- Style/PredicateName:
40
- Exclude:
41
- - spec/services/tempfile_service_spec.rb
33
+ RSpec/ExampleLength:
34
+ Max: 10
42
35
 
43
36
  RSpec/ExampleWording:
44
37
  CustomTransform:
@@ -52,15 +45,41 @@ RSpec/ExampleWording:
52
45
  RSpec/FilePath:
53
46
  Enabled: false
54
47
 
48
+ RSpec/HookArgument:
49
+ Exclude:
50
+ - spec/spec_helper.rb
51
+
55
52
  RSpec/InstanceVariable:
56
53
  Enabled: false
57
54
 
58
- RSpec/DescribeClass:
59
- Exclude:
60
- - spec/units/config_spec.rb
61
- - spec/units/transcoding_spec.rb
55
+ RSpec/MessageSpies:
56
+ Enabled: false
62
57
 
63
- RSpec/AnyInstance:
64
- Exclude:
65
- - spec/processors/image_spec.rb
66
- - spec/units/transcoding_spec.rb
58
+ RSpec/MultipleExpectations:
59
+ Max: 10
60
+
61
+ RSpec/NamedSubject:
62
+ Enabled: false
63
+
64
+ RSpec/NestedGroups:
65
+ Max: 4
66
+
67
+ Style/ClassAndModuleChildren:
68
+ Enabled: false
69
+
70
+ Style/CollectionMethods:
71
+ PreferredMethods:
72
+ collect: 'map'
73
+ collect!: 'map!'
74
+ inject: 'reduce'
75
+ detect: 'find'
76
+ find_all: 'select'
77
+
78
+ Style/Documentation:
79
+ Enabled: false
80
+
81
+ Style/SignalException:
82
+ Enabled: false
83
+
84
+ Style/StringLiterals:
85
+ Enabled: false
@@ -1,5 +1,14 @@
1
1
  # List of files that we ought to fix based on what Rubocop is complaining about them
2
2
 
3
+ Layout/SpaceBeforeBlockBraces:
4
+ Exclude:
5
+ - lib/hydra/derivatives/processors/jpeg2k_image.rb
6
+ - lib/hydra/derivatives/processors/shell_based_processor.rb
7
+
8
+ Metrics/ClassLength:
9
+ Exclude:
10
+ - lib/hydra/derivatives/processors/jpeg2k_image.rb
11
+
3
12
  Metrics/CyclomaticComplexity:
4
13
  Exclude:
5
14
  - spec/units/transcoding_spec.rb
@@ -12,18 +21,42 @@ Metrics/MethodLength:
12
21
  - lib/hydra/derivatives/processors/shell_based_processor.rb
13
22
  - lib/hydra/derivatives/processors/video/processor.rb
14
23
  - lib/hydra/derivatives/services/tempfile_service.rb
24
+ - spec/**/*.rb
25
+
26
+ Naming/PredicateName:
27
+ Exclude:
28
+ - spec/services/tempfile_service_spec.rb
29
+
30
+ RSpec/AnyInstance:
31
+ Exclude:
32
+ - spec/processors/image_spec.rb
15
33
  - spec/units/transcoding_spec.rb
16
34
 
17
- Metrics/ClassLength:
35
+ RSpec/BeforeAfterAll:
18
36
  Exclude:
19
- - lib/hydra/derivatives/processors/jpeg2k_image.rb
37
+ - spec/**/*.rb
20
38
 
21
- Metrics/AbcSize:
39
+ RSpec/DescribeClass:
22
40
  Exclude:
23
- - lib/hydra/derivatives/processors/document.rb
24
- - lib/hydra/derivatives/processors/full_text.rb
25
- - lib/hydra/derivatives/processors/jpeg2k_image.rb
26
- - lib/hydra/derivatives/processors/shell_based_processor.rb
27
- - lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb
28
- - lib/hydra/derivatives/services/tempfile_service.rb
41
+ - spec/units/config_spec.rb
29
42
  - spec/units/transcoding_spec.rb
43
+
44
+ RSpec/PredicateMatcher:
45
+ Exclude:
46
+ - spec/**/*.rb
47
+
48
+ RSpec/ReturnFromStub:
49
+ Exclude:
50
+ - spec/processors/jpeg2k_spec.rb
51
+
52
+ RSpec/SubjectStub:
53
+ Exclude:
54
+ - spec/**/*.rb
55
+
56
+ RSpec/VerifiedDoubles:
57
+ Exclude:
58
+ - spec/processors/full_text_spec.rb
59
+
60
+ Style/EvalWithLocation:
61
+ Exclude:
62
+ - lib/hydra/derivatives.rb
@@ -24,3 +24,15 @@ notifications:
24
24
  - "irc.freenode.org#scholarsphere"
25
25
  template:
26
26
  - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
27
+ addons:
28
+ apt:
29
+ sources:
30
+ - "trusty-media"
31
+ - sourceline: ppa:jonathonf/ffmpeg-3
32
+ packages:
33
+ - ghostscript
34
+ - ufraw-batch
35
+ - libpng-dev
36
+ - imagemagick
37
+ - ffmpeg
38
+ - libreoffice
data/Gemfile CHANGED
@@ -4,9 +4,9 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
- gem 'simplecov'
8
- gem 'coveralls'
9
7
  gem 'byebug' unless ENV['TRAVIS']
10
- gem 'rubocop', '~> 0.37.2', require: false
8
+ gem 'coveralls'
9
+ gem 'rubocop', '~> 0.52.0', require: false
11
10
  gem 'rubocop-rspec', require: false
11
+ gem 'simplecov'
12
12
  end
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ namespace :derivatives do
20
20
  end
21
21
 
22
22
  RSpec::Core::RakeTask.new(:rspec) do |task|
23
- task.rspec_opts = "--tag ~requires_imagemagick --tag ~requires_ffmpeg --tag ~requires_libreoffice --tag ~requires_kdu_compress" if ENV['TRAVIS']
23
+ task.rspec_opts = "--tag ~requires_kdu_compress" if ENV['TRAVIS']
24
24
  end
25
25
 
26
26
  desc 'Start up Solr & Fedora and run tests'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.2
1
+ 3.4.0
@@ -0,0 +1,6 @@
1
+ port: null
2
+ verbose: true
3
+ managed: true
4
+ enable_jms: false
5
+ fcrepo_home_dir: tmp/fcrepo4-test-data
6
+ version: 4.7.4
@@ -1,14 +1,12 @@
1
- # coding: utf-8
2
1
  version = File.read(File.expand_path("../VERSION", __FILE__)).strip
3
2
 
4
-
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = "hydra-derivatives"
7
5
  spec.version = version
8
6
  spec.authors = ["Justin Coyne"]
9
7
  spec.email = ["justin@curationexperts.com"]
10
- spec.description = %q{Derivative generation plugin for hydra}
11
- spec.summary = %q{Derivative generation plugin for hydra}
8
+ spec.description = "Derivative generation plugin for hydra"
9
+ spec.summary = "Derivative generation plugin for hydra"
12
10
  spec.license = "APACHE2"
13
11
  spec.homepage = "https://github.com/projecthydra/hydra-derivatives"
14
12
 
@@ -18,17 +16,16 @@ Gem::Specification.new do |spec|
18
16
  spec.require_paths = ["lib"]
19
17
 
20
18
  spec.add_development_dependency 'bundler', '~> 1.3'
19
+ spec.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
21
20
  spec.add_development_dependency 'rake', '~> 10.1'
22
21
  spec.add_development_dependency 'rspec', '~> 3.1'
23
22
  spec.add_development_dependency "solr_wrapper", "~> 0.4"
24
- spec.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
25
23
 
26
- spec.add_dependency 'active-fedora', '>= 11.3.1', '< 12'
27
- spec.add_dependency 'mini_magick', '>= 3.2', '< 5'
28
- spec.add_dependency 'activesupport', '>= 4.0', '< 6'
29
- spec.add_dependency 'mime-types', '> 2.0', '< 4.0'
24
+ spec.add_dependency 'active-fedora', '>= 11.3.1', '< 13'
30
25
  spec.add_dependency 'active_encode', '~>0.1'
26
+ spec.add_dependency 'activesupport', '>= 4.0', '< 6'
31
27
  spec.add_dependency 'addressable', '~>2.5'
32
28
  spec.add_dependency 'deprecation'
29
+ spec.add_dependency 'mime-types', '> 2.0', '< 4.0'
30
+ spec.add_dependency 'mini_magick', '>= 3.2', '< 5'
33
31
  end
34
-
@@ -50,8 +50,8 @@ module Hydra
50
50
  @config = Config.new
51
51
  end
52
52
 
53
- CONFIG_METHODS = [:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
54
- :kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service, :active_encode_poll_time].freeze
53
+ CONFIG_METHODS = %i[ffmpeg_path libreoffice_path temp_file_base fits_path kdu_compress_path
54
+ kdu_compress_recipes enable_ffmpeg source_file_service output_file_service active_encode_poll_time].freeze
55
55
  CONFIG_METHODS.each do |method|
56
56
  module_eval <<-RUBY
57
57
  def self.#{method}
@@ -4,7 +4,7 @@ module Hydra::Derivatives
4
4
  class AudioEncoder
5
5
  def initialize
6
6
  @ffmpeg_output = Open3.capture3('ffmpeg -codecs').to_s
7
- rescue
7
+ rescue StandardError
8
8
  Logger.warn('Unable to find ffmpeg')
9
9
  @ffmpeg_output = ""
10
10
  end
@@ -1,6 +1,7 @@
1
- # Nieve implementation of IO wrapper class that adds mime_type and original_name attributes.
2
- # This is done so the attributes do not have to be passed as additional arguments,
3
- # and are attached properly to the object they describe.
1
+ # Naive implementation of IO wrapper class that adds mime_type and original_filename
2
+ # attributes. This is done to match the interface of ActionDispatch::HTTP::UploadedFile
3
+ # so the attributes do not have to be passed as additional arguments, and are attached
4
+ # properly to the object they describe.
4
5
  #
5
6
  #
6
7
  # Use SimpleDelegator to wrap the given class or instance
@@ -9,12 +10,16 @@ require 'delegate'
9
10
  module Hydra
10
11
  module Derivatives
11
12
  class IoDecorator < SimpleDelegator
12
- attr_accessor :mime_type, :original_name
13
+ extend Deprecation
13
14
 
14
- def initialize(file, mime_type = nil, original_name = nil)
15
+ attr_accessor :mime_type, :original_filename
16
+ alias original_name original_filename
17
+ deprecation_deprecate original_name: 'original_name has been deprecated. Use original_filename instead. This will be removed in hydra-derivatives 4.0'
18
+
19
+ def initialize(file, mime_type = nil, original_filename = nil)
15
20
  super(file)
16
21
  self.mime_type = mime_type
17
- self.original_name = original_name
22
+ self.original_filename = original_filename
18
23
  end
19
24
  end
20
25
  end
@@ -3,7 +3,7 @@ module Hydra::Derivatives
3
3
  class << self
4
4
  def method_missing(method_name, *arguments, &block)
5
5
  logger.send(method_name, *arguments, &block)
6
- rescue
6
+ rescue StandardError
7
7
  super
8
8
  end
9
9
 
@@ -11,6 +11,10 @@ module Hydra::Derivatives
11
11
  logger.respond_to? method_name
12
12
  end
13
13
 
14
+ def respond_to_missing?(method_name, _include_private = false)
15
+ logger.respond_to_missing? method_name
16
+ end
17
+
14
18
  private
15
19
 
16
20
  def logger
@@ -45,7 +45,7 @@ module Hydra::Derivatives::Processors
45
45
  # After a timeout error, try to cancel the encoding.
46
46
  def cleanup_after_timeout
47
47
  encode_job.cancel!
48
- rescue => e
48
+ rescue StandardError => e
49
49
  cancel_error = e
50
50
  ensure
51
51
  msg = "Unable to process ActiveEncode derivative: The command took longer than #{timeout} seconds to execute. Encoding will be cancelled."
@@ -23,6 +23,7 @@ module Hydra::Derivatives::Processors
23
23
  # @return [String] the result of calling the extract service
24
24
  def fetch
25
25
  req = Net::HTTP.new(uri.host, uri.port)
26
+ req.use_ssl = true if check_for_ssl
26
27
  resp = req.post(uri.to_s, file_content, request_headers)
27
28
  raise "Solr Extract service was unsuccessful. '#{uri}' returned code #{resp.code} for #{source_path}\n#{resp.body}" unless resp.code == '200'
28
29
  file_content.rewind if file_content.respond_to?(:rewind)
@@ -56,6 +57,10 @@ module Hydra::Derivatives::Processors
56
57
  @uri ||= connection_url + 'update/extract?extractOnly=true&wt=json&extractFormat=text'
57
58
  end
58
59
 
60
+ def check_for_ssl
61
+ uri.scheme == 'https'
62
+ end
63
+
59
64
  # @returns [URI] path to the solr collection
60
65
  def connection_url
61
66
  ActiveFedora::SolrService.instance.conn.uri
@@ -17,16 +17,13 @@ module Hydra::Derivatives::Processors
17
17
  def kdu_compress_recipe(args, quality, long_dim)
18
18
  if args[:recipe].is_a? Symbol
19
19
  recipe = [args[:recipe].to_s, quality].join('_').to_sym
20
- if Hydra::Derivatives.kdu_compress_recipes.key? recipe
21
- return Hydra::Derivatives.kdu_compress_recipes[recipe]
22
- else
23
- ActiveFedora::Base.logger.warn "No JP2 recipe for :#{args[:recipe]} ('#{recipe}') found in configuration. Using best guess."
24
- return calculate_recipe(args, quality, long_dim)
25
- end
20
+ return Hydra::Derivatives.kdu_compress_recipes[recipe] if Hydra::Derivatives.kdu_compress_recipes.key? recipe
21
+ ActiveFedora::Base.logger.warn "No JP2 recipe for :#{args[:recipe]} ('#{recipe}') found in configuration. Using best guess."
22
+ calculate_recipe(args, quality, long_dim)
26
23
  elsif args[:recipe].is_a? String
27
- return args[:recipe]
24
+ args[:recipe]
28
25
  else
29
- return calculate_recipe(args, quality, long_dim)
26
+ calculate_recipe(args, quality, long_dim)
30
27
  end
31
28
  end
32
29
 
@@ -3,7 +3,7 @@ module Hydra::Derivatives
3
3
  # Adds format: 'txt' as the default to each of the directives
4
4
  def self.transform_directives(options)
5
5
  options.each do |directive|
6
- directive.reverse_merge!(format: 'txt')
6
+ directive.reverse_merge!(format: 'txt', binary: false)
7
7
  end
8
8
  options
9
9
  end
@@ -5,7 +5,7 @@ module Hydra::Derivatives
5
5
  attr_accessor :ffmpeg_output
6
6
  def capture_output
7
7
  @ffmpeg_output = Open3.capture3('ffmpeg -codecs').to_s
8
- rescue
8
+ rescue StandardError
9
9
  Logger.warn('Unable to find ffmpeg')
10
10
  @ffmpeg_output = ""
11
11
  end
@@ -31,8 +31,12 @@ module Hydra::Derivatives
31
31
  end
32
32
  private_class_method :retrieve_remote_file
33
33
 
34
+ # @param [IO,String] content the data to be persisted
35
+ # @param [Hash] directives directions which can be used to determine where to persist to.
36
+ # @return [Hydra::Derivatives::IoDecorator]
34
37
  def self.io(content, directives)
35
- Hydra::Derivatives::IoDecorator.new(content, new_mime_type(directives.fetch(:format), charset(content)))
38
+ charset = charset(content) if directives[:format] == 'txt' || !directives.fetch(:binary, true)
39
+ Hydra::Derivatives::IoDecorator.new(content, new_mime_type(directives.fetch(:format), charset))
36
40
  end
37
41
  private_class_method :io
38
42
 
@@ -9,14 +9,16 @@ module Hydra::Derivatives
9
9
  raise NotImplementedError, "PersistOutputFileService is an abstract class. Implement `call' on #{self.class.name}"
10
10
  end
11
11
 
12
+ # @param file [Hydra::Derivatives::IoDecorator]
12
13
  def self.determine_original_name(file)
13
- if file.respond_to? :original_name
14
- file.original_name
14
+ if file.respond_to? :original_filename
15
+ file.original_filename
15
16
  else
16
17
  "derivative"
17
18
  end
18
19
  end
19
20
 
21
+ # @param file [Hydra::Derivatives::IoDecorator]
20
22
  def self.determine_mime_type(file)
21
23
  if file.respond_to? :mime_type
22
24
  file.mime_type