hets.rb revision 099d0060b8091e71ce78eb3ae1267cfe76a2abdd
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale class HetsDeploymentError < Exception; end
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale class HetsVersionOutdatedError < HetsError; end
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller class HetsConfigDateFormatError < HetsError; end
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller class HetsVersionDateFormatError < HetsError; end
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller yaml = YAML.load_file(File.join(Rails.root, 'config', 'hets.yml'))
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale @path = first_which_exists yaml['hets_path']
82d525750e23960f3f2cc6a11220e0ef8505918fhenning mueller raise HetsNotFoundError, 'Could not find hets' unless @path
82d525750e23960f3f2cc6a11220e0ef8505918fhenning mueller unless is_compatible? yaml['hets_version_minimum_date']
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller raise HetsVersionOutdatedError, 'The installed version of Hets is too old'
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller # Set hets environment variables for when the wrapper script is not used.
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale @library_path = first_which_exists yaml['hets_lib']
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale raise HetsDeploymentError, 'Hets library not found.' unless @library_path
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale # Checks Hets installation compatibility by its version date
71fdc30cc6e637d99cacb455537e7b8fbfe77395henning mueller # * - +minimum_date+ -> Minimum working hets version date
71fdc30cc6e637d99cacb455537e7b8fbfe77395henning mueller # * *Returns* :
71fdc30cc6e637d99cacb455537e7b8fbfe77395henning mueller # * - true if hets version minimum date prior or equal to actual hets version date
71fdc30cc6e637d99cacb455537e7b8fbfe77395henning mueller # * - false otherwise
71fdc30cc6e637d99cacb455537e7b8fbfe77395henning mueller # Read Hets version minimum date
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale raise HetsConfigDateFormatError, 'Could not read hets version minimum date in YAML' unless minimum_date
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale # Read Hets version date
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller raise HetsVersionDateFormatError, 'Could not read hets version date in output of `hets -V`' unless version_date
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller # Return true if minimum date is prior or equal to version date
705933deb08bc4269e8c08d50143af3cb5c1c670henning mueller paths.map { |path| File.expand_path path }.each do |path|
705933deb08bc4269e8c08d50143af3cb5c1c670henning mueller # Runs hets with input_file and returns XML output file path.
574a02d837d442144fe066284dfed20e43a42053Julian Kornberger def self.parse(input_file, url_catalog = [], output_path = nil)
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller url_mapping = url_catalog.empty? '' : " -C #{url_catalog.join(',')}"
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller command = "#{@@config.path}#{url_mapping} -o xml --full-signatures -a none -v2 #{output_path} '#{input_file}' 2>&1"