hets.rb revision 82d525750e23960f3f2cc6a11220e0ef8505918f
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
ec416eab0158cfe34b77cea4a11f8b84bc194a7aDaniel Couto Vale class HetsVersionOutdatedError < HetsError; end
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale class HetsConfigDateFormatError < HetsError; end
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale class HetsVersionDateFormatError < HetsError; end
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller yaml = YAML.load_file(File.join(Rails.root, 'config', 'hets.yml'))
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller @path = first_which_exists yaml['hets_path']
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller raise HetsNotFoundError, 'Could not find hets' unless @path
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale unless is_compatible? yaml['hets_version_minimum_date']
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale raise HetsVersionOutdatedError, 'The installed version of Hets is too old'
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller ENV[key.upcase] = first_which_exists value if (key != 'hets_path' and value.is_a? Array)
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller # Checks Hets installation compatibility by its version date
a837d007b255d7a6cca7994e1e555aba95ce41cchenning mueller # * - +minimum_version+ -> Minimum working hets version
a837d007b255d7a6cca7994e1e555aba95ce41cchenning mueller # * *Returns* :
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller # * - true if hets version minimum date prior or equal to actual hets version date
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller # * - false otherwise
083f87068ffcf24df8b0154bfbca4ca5027f8ecehenning mueller # Read Hets version minimum date
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller raise HetsConfigDateFormatError, 'Could not read hets version minimum date in YAML' unless minimum_version
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale # Read Hets version date
b0c849916b1471424344717ada19c745833e4c5bhenning mueller raise HetsVersionDateFormatError, 'Could not read hets version date in output of `hets -V`' unless version_date
40c5626383ebd5e8cf11a636f864023a2aafcd6bDaniel Couto Vale # Return true if minimum date is prior or equal to version date
a837d007b255d7a6cca7994e1e555aba95ce41cchenning mueller # Runs hets with input_file and returns XML output file path.
a837d007b255d7a6cca7994e1e555aba95ce41cchenning mueller def self.parse(input_file, output_path = '')
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller output_path = "-O \"#{output_path}\"" unless output_path.blank?
58721b9d3a8cd6a624269ddf507f80af4417c9bdhenning mueller command = "#{config.path} -o xml --full-signatures -v2 #{output_path} '#{input_file}' 2>&1"
099d0060b8091e71ce78eb3ae1267cfe76a2abddEugen Kuksa # nice runs the process with lower scheduling priority
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger if $?.exitstatus != 0 or status.starts_with? '*** Error'