gat 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +84 -0
- data/PostInstall.txt +22 -0
- data/README.txt +49 -0
- data/Rakefile +12 -0
- data/bin/gat +15 -0
- data/lib/gat.rb +323 -0
- data/lib/gat/action/base.rb +197 -0
- data/lib/gat/action/ruby_method.rb +35 -0
- data/lib/gat/action/shell_command.rb +185 -0
- data/lib/gat/boot.rb +63 -0
- data/lib/gat/checks.rb +136 -0
- data/lib/gat/debug.rb +29 -0
- data/lib/gat/dependence/argument.rb +62 -0
- data/lib/gat/dependence/base.rb +54 -0
- data/lib/gat/dependence/folder.rb +104 -0
- data/lib/gat/dependence/program.rb +36 -0
- data/lib/gat/email.rb +80 -0
- data/lib/gat/exceptions.rb +163 -0
- data/lib/gat/extends.rb +102 -0
- data/lib/gat/help.rb +79 -0
- data/lib/gat/interpreter.rb +93 -0
- data/lib/gat/launcher.rb +100 -0
- data/lib/gat/logger.rb +331 -0
- data/lib/gat/operation.rb +253 -0
- data/lib/gat/version.rb +20 -0
- data/lib/gatgets/dar_backup/dar_backup.rb +367 -0
- data/lib/gatgets/dar_backup/dar_backup.yml +387 -0
- data/lib/gatgets/dar_backup/launcher.rb +44 -0
- data/lib/gatgets/dar_backup/templates/list_backups.erb +31 -0
- data/lib/gatgets/dar_backup/templates/search.erb +33 -0
- data/lib/gatgets/gatgets_manager/gatgets_manager.rb +65 -0
- data/lib/gatgets/gatgets_manager/gatgets_manager.yml +71 -0
- data/lib/gatgets/gatgets_manager/templates/list.erb +9 -0
- data/lib/gatgets/synchronization/README +26 -0
- data/lib/gatgets/synchronization/launcher.rb +20 -0
- data/lib/gatgets/synchronization/launcher_cron.sh +69 -0
- data/lib/gatgets/synchronization/synchronization.rb +123 -0
- data/lib/gatgets/synchronization/synchronization.yml +144 -0
- data/test/test_gat.rb +36 -0
- data/test/test_helper.rb +3 -0
- metadata +131 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
:file => exception.rb
|
4
|
+
:author => (c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
######################################################################################
|
7
|
+
## This file is part of GAT: http://gat.rubyforge.org ##
|
8
|
+
## ##
|
9
|
+
## GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher. ##
|
10
|
+
## You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.##
|
11
|
+
######################################################################################
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
17
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
=end
|
22
|
+
|
23
|
+
|
24
|
+
module Gat
|
25
|
+
|
26
|
+
class GagetExceptions < StandardError
|
27
|
+
|
28
|
+
attr_reader :exception_location
|
29
|
+
attr_reader :exception_options
|
30
|
+
attr_reader :exception_backtrace
|
31
|
+
|
32
|
+
def initialize(error, location, options = {})
|
33
|
+
if error.is_a?(Exception)
|
34
|
+
super(options[:message].nil? ? error.message : options[:message] )
|
35
|
+
@exception_backtrace = error.backtrace
|
36
|
+
else
|
37
|
+
super(error)
|
38
|
+
@exception_backtrace = nil
|
39
|
+
end
|
40
|
+
@exception_location = location
|
41
|
+
@exception_options = options
|
42
|
+
end
|
43
|
+
|
44
|
+
def exception_message
|
45
|
+
return message
|
46
|
+
end
|
47
|
+
|
48
|
+
def exit_level #:nodoc:
|
49
|
+
return 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def exit_error
|
53
|
+
error_string = "ERROR: `#{ self.exception_message }` at `#{ self.exception_location }`"
|
54
|
+
if self.exception_backtrace
|
55
|
+
error_string << "\nBACK:\n #{ self.exception_backtrace.shift } \n #{ self.exception_backtrace.join("\n ") }"
|
56
|
+
elsif self.backtrace
|
57
|
+
error_string << "\nBACK:\n #{ self.backtrace.shift } \n #{ self.backtrace.join("\n ") }"
|
58
|
+
end
|
59
|
+
error_string
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Gatget Exception.
|
65
|
+
# Normal Code Exception. Something gone wrong but exit is controlled
|
66
|
+
class GatgetException < GagetExceptions
|
67
|
+
|
68
|
+
def initialize(error, location, options = {})
|
69
|
+
super(error, location, options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def exit_level
|
73
|
+
return 1
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
# Gatget Fatal Exception.
|
79
|
+
# Fatal Code Exception. Something gone wrong and no callbacks are launched
|
80
|
+
class GatgetFatalException < GagetExceptions
|
81
|
+
|
82
|
+
def initialize(error, location, options = {})
|
83
|
+
super(error, location, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def exit_level
|
87
|
+
return 2
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
# Undefined Exception
|
93
|
+
# No controlled Gatget Exception, but callbacks are launched
|
94
|
+
class UndefinedException < GagetExceptions
|
95
|
+
|
96
|
+
def initialize(error, location, options = {})
|
97
|
+
super(error, location, options)
|
98
|
+
end
|
99
|
+
|
100
|
+
def exit_level
|
101
|
+
return 3
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# Process Exception
|
108
|
+
# Action || condition failed during the process
|
109
|
+
class GatgetProcessException < GagetExceptions
|
110
|
+
|
111
|
+
def initialize(error, location, options = {})
|
112
|
+
super(error, location, options)
|
113
|
+
end
|
114
|
+
|
115
|
+
def exit_level
|
116
|
+
return 4
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
# Config Exception
|
122
|
+
# Config malformed or missing data at YML
|
123
|
+
class GatgetConfigException < GagetExceptions
|
124
|
+
|
125
|
+
def initialize(error, location, options = {})
|
126
|
+
super(error, location, options)
|
127
|
+
end
|
128
|
+
|
129
|
+
def exit_level
|
130
|
+
return 5
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# Argument Exception
|
136
|
+
# missing arguments or bad arguments
|
137
|
+
class GatgetArgumentException < GagetExceptions
|
138
|
+
|
139
|
+
def initialize(error, location, options = {})
|
140
|
+
super(error, location, options)
|
141
|
+
end
|
142
|
+
|
143
|
+
def exit_level
|
144
|
+
return 7
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# Instance Exception
|
150
|
+
# Gatget coulnt generate an instance and launch script
|
151
|
+
class GatgetInstanceException < GagetExceptions
|
152
|
+
|
153
|
+
def initialize(error, location, options = {})
|
154
|
+
super(error, location, options)
|
155
|
+
end
|
156
|
+
|
157
|
+
def exit_level
|
158
|
+
return 6
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
data/lib/gat/extends.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
:file => extends.rb
|
4
|
+
:author => see each method for more information
|
5
|
+
|
6
|
+
######################################################################################
|
7
|
+
## This file is part of GAT: http://gat.rubyforge.org ##
|
8
|
+
## ##
|
9
|
+
## GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher. ##
|
10
|
+
## You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.##
|
11
|
+
######################################################################################
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
17
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
=end
|
22
|
+
|
23
|
+
# This file just extend some objects with usefull methods for gat
|
24
|
+
|
25
|
+
# Underscore and camelize method ... DarBackup.underscore => dar_backup.camelize => DarBackup
|
26
|
+
# stolen from rails code ;)
|
27
|
+
# http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
|
28
|
+
# Rails is released under the MIT licens as you can see at http://rubyonrails.org/
|
29
|
+
class String
|
30
|
+
def underscore
|
31
|
+
self.gsub(/::/, '/').
|
32
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
33
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
34
|
+
tr("-", "_").
|
35
|
+
downcase
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def camelize
|
40
|
+
self.gsub(/\/(.?)/) { "::#{ $1.upcase }" }.
|
41
|
+
gsub(/(?:^|_)(.)/) { $1.upcase }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class File
|
47
|
+
def self.nice_size(file)
|
48
|
+
filesize = File.size(file)
|
49
|
+
|
50
|
+
if filesize >= 1073741824
|
51
|
+
filesize = "#{ filesize / 1073741824 } Gb."
|
52
|
+
elsif filesize >= 1048576
|
53
|
+
filesize = "#{ filesize / 1048576 } Mb."
|
54
|
+
elsif filesize >= 1024
|
55
|
+
filesize = "#{ filesize / 1024 } Kb."
|
56
|
+
else
|
57
|
+
filesize = "#{ filesize } bytes"
|
58
|
+
end
|
59
|
+
|
60
|
+
filesize
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Hash#deep_merge
|
65
|
+
# From: http://pastie.textmate.org/pastes/30372, Elliott Hird
|
66
|
+
# Source: http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
67
|
+
# This file contains extensions to Ruby and other useful snippits of code.
|
68
|
+
# Time to extend Hash with some recursive merging magic.
|
69
|
+
|
70
|
+
|
71
|
+
class Hash
|
72
|
+
|
73
|
+
# Merges self with another hash, recursively.
|
74
|
+
#
|
75
|
+
# This code was lovingly stolen from some random gem:
|
76
|
+
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
77
|
+
#
|
78
|
+
# Thanks to whoever made it.
|
79
|
+
|
80
|
+
def deep_merge(hash)
|
81
|
+
target = dup
|
82
|
+
|
83
|
+
hash.keys.each do |key|
|
84
|
+
if hash[key].is_a? Hash and self[key].is_a? Hash
|
85
|
+
target[key] = target[key].deep_merge(hash[key])
|
86
|
+
next
|
87
|
+
end
|
88
|
+
|
89
|
+
target[key] = hash[key]
|
90
|
+
end
|
91
|
+
|
92
|
+
target
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
data/lib/gat/help.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
:file => help.rb
|
4
|
+
:author => (c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
######################################################################################
|
7
|
+
## This file is part of GAT: http://gat.rubyforge.org ##
|
8
|
+
## ##
|
9
|
+
## GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher. ##
|
10
|
+
## You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.##
|
11
|
+
######################################################################################
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
17
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
=end
|
22
|
+
|
23
|
+
|
24
|
+
module Gat
|
25
|
+
module Help
|
26
|
+
|
27
|
+
def gatget_help
|
28
|
+
|
29
|
+
help_message = "\n Help: \n"
|
30
|
+
help_message << " ------\n\n"
|
31
|
+
help_message << " # #{ 'launcher name'.ljust(31) } : #{ $0 }\n"
|
32
|
+
help_message << " # #{ 'launcher class'.ljust(31) } : #{ self.class.name }\n"
|
33
|
+
help_message << " # #{ 'gatget name'.ljust(31) } : #{ self.name.camelize }\n"
|
34
|
+
help_message << " # #{ 'description'.ljust(31) } : #{ self.config['description'] || '<gatget description not avalilable>' }\n"
|
35
|
+
|
36
|
+
if self.config['operations'].nil? or self.config['operations'].is_a?(String)
|
37
|
+
help_message << " # no operations defined\n"
|
38
|
+
else
|
39
|
+
help_message << " # operations\n"
|
40
|
+
|
41
|
+
self.config['operations'].each_pair do |op_key, op_data|
|
42
|
+
help_message << " #{ ' ' * 5 } * #{ op_key.ljust(25) } : #{ op_data['description'] || '< no description avalilable >' } \n\n"
|
43
|
+
syntax_message = " #{ ' ' * 9 } $ > #{ $0 } #{ op_key } "
|
44
|
+
argument_message = ''
|
45
|
+
|
46
|
+
if op_data['arguments'] and op_data['arguments'].any?
|
47
|
+
|
48
|
+
if self.config['arguments'].nil?
|
49
|
+
raise GatgetConfigException.new("Global arguments not defined in yml", 'gatget_help')
|
50
|
+
end
|
51
|
+
|
52
|
+
op_data['arguments'].each do |argument|
|
53
|
+
syntax_message << "<#{ argument }> "
|
54
|
+
unless self.config['arguments'][argument].nil?
|
55
|
+
argument_data = self.config['arguments'][argument]['description'] || '<no description available>'
|
56
|
+
argument_message << "\n #{ ' ' * 9 } | #{ "<#{ argument }>".ljust(21) } : #{ argument_data } "
|
57
|
+
else
|
58
|
+
raise GatgetConfigException.new("argument '#{argument}' not defined", 'gatget_help')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
help_message << syntax_message
|
63
|
+
help_message << argument_message
|
64
|
+
help_message << "\n\n\n"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
help_message << "Gat Version #{ Gat::VERSION }"
|
68
|
+
|
69
|
+
|
70
|
+
$stdout.puts help_message
|
71
|
+
end
|
72
|
+
|
73
|
+
def returning(value)
|
74
|
+
yield(value)
|
75
|
+
value
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
:file => interpreter.rb
|
4
|
+
:author => (c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
######################################################################################
|
7
|
+
## This file is part of GAT: http://gat.rubyforge.org ##
|
8
|
+
## ##
|
9
|
+
## GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher. ##
|
10
|
+
## You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.##
|
11
|
+
######################################################################################
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
17
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
=end
|
22
|
+
|
23
|
+
module Gat
|
24
|
+
module Interpreter
|
25
|
+
|
26
|
+
|
27
|
+
def interpreter_parameters(gatget_text, gatget_object)
|
28
|
+
|
29
|
+
interpreted_string = gatget_text.gsub(/\{\{[\w\d]+\}\}/) do |gat_parameter|
|
30
|
+
parameter = gat_parameter.gsub(/[{}]/,'')
|
31
|
+
gat_parameter = interpreter_parameter(parameter, gatget_object)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def interpreter_parameter(parameter_name, gatget_object)
|
38
|
+
parameter_config = gatget_object.get_element_config('parameters', parameter_name)
|
39
|
+
|
40
|
+
if not parameter_config or parameter_config.nil?
|
41
|
+
# FIXME This is never true as it would have raised an exception in get_element_config
|
42
|
+
raise GatgetConfigException.new("Parameter #{ parameter_name } not found at YML", "interpreter_parameters")
|
43
|
+
end
|
44
|
+
|
45
|
+
if not parameter_config['value'] or parameter_config['value'].blank?
|
46
|
+
raise GatgetConfigException.new("Parameter #{ parameter_name } has blank or missing value", "interpreter_parameter")
|
47
|
+
end
|
48
|
+
|
49
|
+
case parameter_config['type']
|
50
|
+
when 'dependence'
|
51
|
+
dependence_type, *dependence_name = parameter_config['value'].split("/")
|
52
|
+
ret = gatget_object.get_dependence_value(dependence_type, dependence_name.join("_"))
|
53
|
+
if parameter_config['array_method']
|
54
|
+
ret = eval("ret.#{ parameter_config['array_method'] }")
|
55
|
+
end
|
56
|
+
|
57
|
+
if parameter_config['join']
|
58
|
+
ret = [ *ret ].join(parameter_config['join'])
|
59
|
+
end
|
60
|
+
when 'eval'
|
61
|
+
ret = eval(parameter_config['value'])
|
62
|
+
else
|
63
|
+
if parameter_config['type'].empty?
|
64
|
+
raise GatgetConfigException.new("'#{parameter_config['type']}' type invalid for argument #{ parameter_name }. Should be 'dependence' or 'eval'", "interpreter_parameter")
|
65
|
+
else
|
66
|
+
raise GatgetConfigException.new("missing type por argument #{ parameter_name }", "interpreter_parameter")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
ret
|
71
|
+
|
72
|
+
# What does it happens if a ret is nil or blank or false?????
|
73
|
+
# ToDo
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def interpreter_shell_command(action)
|
79
|
+
syntax = self.syntax.gsub(/\{\{[\w\d]+\}\}/) do |argument|
|
80
|
+
|
81
|
+
# replace current argument with data
|
82
|
+
unless self.arguments.keys.include?(argument.gsub(/[{}]/,''))
|
83
|
+
raise GatgetConfigException.new("Syntax failed for action #{ action.name }. Missing argument: #{ argument }", "interpreter_shell_command")
|
84
|
+
end
|
85
|
+
|
86
|
+
argument = self.arguments[argument.gsub(/[{}]/,'')]
|
87
|
+
end
|
88
|
+
syntax
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
data/lib/gat/launcher.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
:file => launcher.rb
|
4
|
+
:author => (c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
######################################################################################
|
7
|
+
## This file is part of GAT: http://gat.rubyforge.org ##
|
8
|
+
## ##
|
9
|
+
## GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher. ##
|
10
|
+
## You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.##
|
11
|
+
######################################################################################
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
17
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
=end
|
22
|
+
|
23
|
+
module Gat
|
24
|
+
module Launcher
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def included(base)
|
28
|
+
base.extend ClassMethods
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
|
34
|
+
# This method launches the Gatget
|
35
|
+
# Usage:
|
36
|
+
# class ExampleGatget < Gat::Base
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# options = { :specific_gatget_options }
|
40
|
+
#
|
41
|
+
# ExampleScript.launch(options, ARGV)
|
42
|
+
#
|
43
|
+
|
44
|
+
def launch(options, arguments)
|
45
|
+
|
46
|
+
launch_error = false
|
47
|
+
|
48
|
+
# Load Instance gatget.
|
49
|
+
#
|
50
|
+
# Gatget exceptions are rescued by Instance Error if fails
|
51
|
+
# Other exceptions are parsed as Undefined
|
52
|
+
begin
|
53
|
+
instance_gatget = self.new(options, arguments)
|
54
|
+
rescue GatgetException, GatgetConfigException, GatgetArgumentException => error
|
55
|
+
launch_error = GatgetInstanceException.new(error, error.exception_location)
|
56
|
+
rescue => error
|
57
|
+
launch_error = UndefinedException.new(error, 'initialize_gatget')
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# If no error, continue with the process
|
62
|
+
unless launch_error
|
63
|
+
# Gatget exceptions are rescued and parsed as is.
|
64
|
+
# Other exceptions are parsed as Undefined
|
65
|
+
begin
|
66
|
+
instance_gatget.execute
|
67
|
+
rescue GatgetException, GatgetProcessException, GatgetConfigException, GatgetArgumentException => error
|
68
|
+
launch_error = error
|
69
|
+
rescue => error
|
70
|
+
launch_error = UndefinedException.new(error, 'launch_error')
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# Rescue operations
|
75
|
+
if launch_error and instance_gatget.methods.include?('onfail')
|
76
|
+
begin
|
77
|
+
instance_gatget.onfail_error = launch_error
|
78
|
+
instance_gatget.logger.log("message", "failed_gatget", 'starting rescue operations for failed_gatget')
|
79
|
+
instance_gatget.send('onfail')
|
80
|
+
rescue => error
|
81
|
+
$stderr.puts launch_error.exit_error
|
82
|
+
# no controlled gatget failed, exit
|
83
|
+
instance_gatget.logger.log("error", "failed_gatget", error.message)
|
84
|
+
error_string = error.methods.include?('exception_message') ? error.exception_message : error
|
85
|
+
launch_error = GatgetFatalException.new(error_string, 'launch')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if launch_error
|
91
|
+
$stderr.puts launch_error.exit_error
|
92
|
+
exit launch_error.exit_level
|
93
|
+
else
|
94
|
+
# Success
|
95
|
+
exit 0
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|