-
Notifications
You must be signed in to change notification settings - Fork 4
/
package_data.rb
84 lines (74 loc) · 3 KB
/
package_data.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true
# Robot class to run under multiplexing infrastructure
module Robots # Robot package
module DorRepo # Use DorRepo/SdrRepo to avoid name collision with Dor module
module GisAssembly # This is your workflow package name (using CamelCase)
class PackageData < Base
def initialize
super('gisAssemblyWF', 'package-data', check_queued_status: true) # init LyberCore::Robot
end
# Create data.zip for all digital work files
def generate_data_zip(druid, rootdir)
tmpdir = File.join(rootdir, 'temp')
LyberCore::Log.debug "Changing to #{tmpdir}"
fail "package-data: #{druid} is missing #{tmpdir}" unless File.directory?(tmpdir)
Dir.chdir(tmpdir)
File.umask(002)
fns = []
recurse_flag = false
fn = Dir.glob('*.shp.xml').first
if fn.nil?
fn = Dir.glob('*/metadata.xml').first
if fn.nil?
fn = Dir.glob('*.tif.xml').first
if fn.nil?
fail "package-data: #{druid} cannot locate metadata in temp"
else # GeoTIFF
basename = File.basename(fn, '.tif.xml')
Dir.glob("#{basename}.*").each do |x|
fns << x
recurse_flag = true if File.directory?(x)
end
Dir.glob("#{basename}-*.xml").each do |x|
fns << x
end
end
else # ArcGRID
fns << File.basename(File.dirname(fn))
recurse_flag = true
end
else # Shapefile
basename = File.basename(fn, '.shp.xml')
Dir.glob("#{basename}.*").each do |x|
fns << x
recurse_flag = true if File.directory?(x)
end
Dir.glob("#{basename}-*.xml").each do |x|
fns << x
end
end
zipfn = File.join(rootdir, 'content', 'data.zip')
FileUtils.mkdir_p(File.dirname(zipfn)) unless File.directory?(File.dirname(zipfn))
FileUtils.rm_f(zipfn) if File.size?(zipfn)
LyberCore::Log.debug "Compressing #{druid} into #{zipfn}"
system "zip -v#{recurse_flag ? 'r' : ''} '#{zipfn}' #{fns.join(' ')}"
end
# `perform` is the main entry point for the robot. This is where
# all of the robot's work is done.
#
# @param [String] druid -- the Druid identifier for the object to process
def perform(druid)
druid = GisRobotSuite.initialize_robot druid
LyberCore::Log.debug "package-data working on #{druid}"
rootdir = GisRobotSuite.locate_druid_path druid, type: :stage
datafn = "#{rootdir}/content/data.zip"
if File.size?(datafn)
LyberCore::Log.info "package-data: #{druid} found existing packaged data: #{File.basename(datafn)}"
return
end
generate_data_zip druid, rootdir
end
end
end
end
end