Sha256: 0200ee1dfe90ab1857a290aba162d436195c99434d9190333e601af22b40e0ec

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

require 'open3'
module Sufia
  module FileContent
    module ExtractMetadata
      include Open3

      def extract_metadata
        out = nil
        to_tempfile do |f|
          out = run_fits!(f.path)
        end
        out
      end

      def to_tempfile &block
        return if content.nil?
        f = Tempfile.new("#{pid}-#{dsVersionID}")
        f.binmode
        if content.respond_to? :read
          f.write(content.read)
        else
          f.write(content)
        end
        f.close
        content.rewind if content.respond_to? :rewind
        yield(f)
        f.unlink

      end

      private 


        def run_fits!(file_path)
            command = "#{fits_path} -i #{file_path}"
            stdin, stdout, stderr = popen3(command)
            stdin.close
            out = stdout.read
            stdout.close
            err = stderr.read
            stderr.close
            raise "Unable to execute command \"#{command}\"\n#{err}" unless err.empty? or err.include? "Error parsing Exiftool XML Output"
            out
        end


        def fits_path
          Sufia::Engine.config.fits_path
        end

      end
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sufia-0.1.0 lib/sufia/file_content/extract_metadata.rb
sufia-0.0.8 lib/sufia/file_content/extract_metadata.rb
sufia-0.0.7 lib/sufia/file_content/extract_metadata.rb
sufia-0.0.6 lib/sufia/file_content/extract_metadata.rb
sufia-0.0.5 lib/sufia/file_content/extract_metadata.rb
sufia-0.0.4 lib/sufia/file_content/extract_metadata.rb