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
data/History.txt
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
== 0.2.8 2010-02-16
|
2
|
+
* Bugfix release
|
3
|
+
* ShellCommandChilds was only executing for the first child
|
4
|
+
* Folder backups were not ordered when reading them for deletion
|
5
|
+
* Added more error messages to avoid meaningless messages
|
6
|
+
* Tests
|
7
|
+
* Added a good lot of basic tests
|
8
|
+
|
9
|
+
== 0.2.7 2009-11-12
|
10
|
+
|
11
|
+
* Gat Improve
|
12
|
+
* Added mount capabilities to folder dependencies thourgh type 'mount'
|
13
|
+
* Starting with SPEC test
|
14
|
+
* Dar Backup Fixes
|
15
|
+
* Fix Gat::Action.get_current_action bug. Now, Base class must be called, since me move action to module.
|
16
|
+
|
17
|
+
|
18
|
+
== 0.2.6 2009-11-10
|
19
|
+
|
20
|
+
* Gat Improve
|
21
|
+
* Moved action.rb and dependences.rb to more orderned folder structure.
|
22
|
+
* Gat Fixes
|
23
|
+
* Fix blank domain at email default output
|
24
|
+
* Dar Backup Fixes
|
25
|
+
* Fix. Invalid excution of delete catalog and system backups when no need to delete backups
|
26
|
+
|
27
|
+
|
28
|
+
== 0.2.5 2009-10-23
|
29
|
+
|
30
|
+
* Gat Fixes
|
31
|
+
* Incorrect mess in hour gatget times.
|
32
|
+
* DarBackup changes:
|
33
|
+
* Added thresold concept. Space disk limit to perform backup
|
34
|
+
* Syncronization
|
35
|
+
* First include of syncronization gatget.
|
36
|
+
|
37
|
+
== 0.2.4 2009-10-20
|
38
|
+
|
39
|
+
* Gat changes
|
40
|
+
* Exceptions has been revised. Now, inherit from StandardError insted of ::Exception
|
41
|
+
* Changed Exception error.
|
42
|
+
* Include new Argument support types (get and gat_password) which gets values from stdin.
|
43
|
+
* GatgetManager Support.
|
44
|
+
* First release with GatgetManager, which is a gatget to control install of rest.
|
45
|
+
* Included launcher as bin executable, avalaible from instalation
|
46
|
+
* DarBackup gatget Bug fixes
|
47
|
+
* Fixed argument of marked backups to delete.
|
48
|
+
|
49
|
+
== 0.2.3 2009-10-18
|
50
|
+
|
51
|
+
* Gat changes
|
52
|
+
* Permanent remove of conditions. Instead of, we will use helpers everywhere.
|
53
|
+
* Revised email default body and subjects.
|
54
|
+
* DarBackup gatget Bug fixes
|
55
|
+
* Fixed argument of marked backups to delete.
|
56
|
+
|
57
|
+
== 0.2.2 2009-10-02
|
58
|
+
|
59
|
+
* Gat changes
|
60
|
+
* Temporal (or maybe permanent) deprecation of conditions
|
61
|
+
* DarBackup gatget Bug fixes
|
62
|
+
* Incorrect compartion because slashes between current and date based folder for backups.
|
63
|
+
* Revised onfail launch method
|
64
|
+
|
65
|
+
== 0.2.1 2009-09-30
|
66
|
+
|
67
|
+
* 1 minor enhancement
|
68
|
+
* Gemified.
|
69
|
+
|
70
|
+
== 0.2.0 2009-09-07
|
71
|
+
|
72
|
+
* 1 major enhancement:
|
73
|
+
* Changed all gat structure from procedural to classes
|
74
|
+
* Removed gatget modules and converted actions, conditions, outputs, etc. to classes
|
75
|
+
* Gat start to be what we thought it will be :D
|
76
|
+
* Added templates
|
77
|
+
|
78
|
+
|
79
|
+
== 0.1.0 2009-06-25
|
80
|
+
|
81
|
+
* 1 major enhancement:
|
82
|
+
* Initial release
|
83
|
+
* Moved from IRGAT proyect
|
84
|
+
* Include Backup Gatget. Sync Gatget is still under development
|
data/PostInstall.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gat Gem Post Install Doc
|
2
|
+
===============================================================================
|
3
|
+
|
4
|
+
Gat provides several built in Gatgets. For now, it contains
|
5
|
+
|
6
|
+
- GatgetDarBackup => Performs and maintains a whole system of backups with
|
7
|
+
dar (Disk Archiver for GNU/Linux)
|
8
|
+
|
9
|
+
|
10
|
+
To use this, simply copy the file named launcher.rb to the gatget install
|
11
|
+
folder (default by gem, /usr/lib/ruby/gems/ruby1.8/gat/gatgets/<gatget_name>)
|
12
|
+
and place it under your local executable folder (for example: /usr/local/bin).
|
13
|
+
|
14
|
+
|
15
|
+
For more information on gat, see http://gat.rubyforge.org
|
16
|
+
|
17
|
+
|
18
|
+
===============================================================================
|
19
|
+
Copyright © 2007-2009 Gnoxys. http://www.gnoxys.net.
|
20
|
+
Gat is released under GPL v3.0 or higther. See README for more information
|
21
|
+
|
22
|
+
|
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= G.A.T. (Gnoxys Administrations Tools)
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
GAT is a Ruby gem that tries to provide a script fast development framework.
|
6
|
+
|
7
|
+
Based on a YML structure, GAT allows you to write basic and advanced scripts with a whole set of tools that scripting need.
|
8
|
+
|
9
|
+
More info can be found at http://gat.rubyforge.org
|
10
|
+
|
11
|
+
|
12
|
+
== FEATURES/PROBLEMS:
|
13
|
+
|
14
|
+
* Still in ALPHA release. Not recommended for production use
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
== INSTALL:
|
24
|
+
|
25
|
+
Just type at console (as root or with sudo):
|
26
|
+
|
27
|
+
# gem install gat
|
28
|
+
|
29
|
+
|
30
|
+
== EXAMPLE
|
31
|
+
|
32
|
+
Look into gatgets/example for an example of using GAT
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
This file is part of GAT: http://gat.rubyforge.org
|
37
|
+
|
38
|
+
(c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
39
|
+
|
40
|
+
GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher.
|
41
|
+
You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/gat
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gatgets/gatgets_manager/gatgets_manager'
|
4
|
+
|
5
|
+
class MainGatgetsManagerScript < GatgetGatgetsManager #:nodoc:
|
6
|
+
end
|
7
|
+
|
8
|
+
# default options... see all options at Gatget config file GAT_ROOT + /lib/gatgets/gatget_manager/gatgets_manager
|
9
|
+
|
10
|
+
options = {
|
11
|
+
'gatget_config' => { }
|
12
|
+
}
|
13
|
+
|
14
|
+
# Launch Gatget
|
15
|
+
MainGatgetsManagerScript.launch(options, ARGV)
|
data/lib/gat.rb
ADDED
@@ -0,0 +1,323 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of GAT: http://gat.rubyforge.org
|
3
|
+
|
4
|
+
(c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher.
|
7
|
+
You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
10
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
11
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
12
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
13
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
14
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
15
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Gat Base Folder
|
19
|
+
if File.symlink?(__FILE__)
|
20
|
+
GAT_ROOT = File.expand_path(File.dirname(File.readlink(__FILE__)) + '/..')
|
21
|
+
else
|
22
|
+
GAT_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
23
|
+
end
|
24
|
+
|
25
|
+
# Gat Script Folder
|
26
|
+
if File.symlink?($0)
|
27
|
+
GAT_SCRIPT_PATH = File.expand_path(File.dirname(File.readlink($0)))
|
28
|
+
else
|
29
|
+
GAT_SCRIPT_PATH = File.expand_path(File.dirname($0))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gat BOOT
|
33
|
+
require GAT_ROOT + '/lib/gat/boot'
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
module Gat
|
38
|
+
|
39
|
+
# Gat::Base Class
|
40
|
+
#
|
41
|
+
# Gat::Base provides basic features, like logger, times, debug levels, a launcher controlled by exceptions and command line parsed
|
42
|
+
# Base class is, as we see, the container. It control the config and the whole process. But it is only the container,
|
43
|
+
# the process itlsef is runned by actions, conditions or operations.
|
44
|
+
#
|
45
|
+
# Gat::Base include then, methods to collect config information, mess the time, launch the script, etc... features that are usually needed
|
46
|
+
# by almost of the scripts
|
47
|
+
#
|
48
|
+
# Gat::Base now, delegate the execution to the Gat::Operation, but, we want that Gat::Base provides interaction framework, for
|
49
|
+
# example, interact with machine, creating onfly actions
|
50
|
+
class Base
|
51
|
+
|
52
|
+
# include module methods at base class
|
53
|
+
include Gat::Checks
|
54
|
+
include Gat::Debug
|
55
|
+
include Gat::Help
|
56
|
+
include Gat::Launcher
|
57
|
+
include Gat::Email
|
58
|
+
|
59
|
+
# set read only attributes
|
60
|
+
attr_reader :config
|
61
|
+
attr_reader :arguments
|
62
|
+
attr_reader :operation
|
63
|
+
attr_reader :debug
|
64
|
+
attr_reader :verbose
|
65
|
+
attr_reader :name
|
66
|
+
attr_reader :path
|
67
|
+
|
68
|
+
|
69
|
+
# set read && write attributes
|
70
|
+
attr :times
|
71
|
+
attr :logger
|
72
|
+
attr :variables
|
73
|
+
attr :flags
|
74
|
+
|
75
|
+
attr_accessor :onfail_error
|
76
|
+
|
77
|
+
|
78
|
+
# Initializes the Gat.Base class, reading the yaml script and any templates.
|
79
|
+
# Gat set a lot of variable accessors
|
80
|
+
# - logger: through log method, store all the ouputs of a gatget process
|
81
|
+
# - times: stores times references
|
82
|
+
# - config: gatget config merged with option passed to the script
|
83
|
+
# - dependences: needed information through the process
|
84
|
+
#
|
85
|
+
#
|
86
|
+
def initialize(options = {}, arguments = [])
|
87
|
+
|
88
|
+
@logger = Logger.new(self) # start gatget_logger
|
89
|
+
|
90
|
+
@times = Hash.new # store time
|
91
|
+
@times['init'] = Time.now
|
92
|
+
|
93
|
+
@debug,arguments = debug?(arguments) # load_debug
|
94
|
+
@verbose,arguments = verbose?(arguments) # load_verbose
|
95
|
+
|
96
|
+
@config = set_gatget_config(options) # load config
|
97
|
+
|
98
|
+
@arguments = arguments
|
99
|
+
|
100
|
+
|
101
|
+
@logger.log("message", "gatget", "Initialize #{ self.name } < #{ self.class.superclass.name } at script #{ $0 }" )
|
102
|
+
@logger.log("message", "gatget", "Gat::Version: #{ Gat::VERSION }, http://www.gnoxys.net")
|
103
|
+
|
104
|
+
# ToDO
|
105
|
+
# Gat, at this time, is only a operation framework. I mean, a gatget has many operation,
|
106
|
+
# like gat_password store_password || view_password.
|
107
|
+
# Then, at this point of development, we care only about these operations. But,
|
108
|
+
# inside gat planning, we want not only run operation but simulations or interactive
|
109
|
+
# programs, that doesnt have a start.steps.end structure, like console
|
110
|
+
#
|
111
|
+
# @operation, is though to be remove for gat::mode at future
|
112
|
+
#
|
113
|
+
@operation = build_operation(arguments) # load operation
|
114
|
+
@variables = { } # variables are empty at start
|
115
|
+
@flags = { } # flags are empty at start
|
116
|
+
end
|
117
|
+
|
118
|
+
# Return the config for a defined gatget element structure
|
119
|
+
# only arguments, folders, programs, actions, conditions, outputs element_types are allowed
|
120
|
+
#
|
121
|
+
# raise GatgetConfigException if none found
|
122
|
+
def get_element_config(element_type, element_name)
|
123
|
+
|
124
|
+
unless ['arguments', 'folders', 'programs', 'actions', 'conditions', 'parameters'].include?(element_type)
|
125
|
+
raise GatgetConfigException.new("undefined gat element type #{ element_type } in YML structure", "get_element_config")
|
126
|
+
end
|
127
|
+
@config[element_type] ||
|
128
|
+
raise(GatgetConfigException.new("'#{ element_type.capitalize }' section not defined in YML structure", "get_element_config"))
|
129
|
+
@config[element_type][element_name] ||
|
130
|
+
raise(GatgetConfigException.new("'#{ element_type.capitalize }/#{ element_name }' element not found in YML structure",
|
131
|
+
"get_element_config"))
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_dependence_variable( variable_name )
|
135
|
+
get_dependence_value('variable', variable_name)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Return the dependence value
|
139
|
+
# only arguments, folders, programs, static, variable are allowed
|
140
|
+
#
|
141
|
+
# raise GatgetConfigException if none found
|
142
|
+
def get_dependence_value(dependence_type, dependence_name)
|
143
|
+
|
144
|
+
unless ['arguments', 'folders', 'programs', 'static', 'variable', 'flags', 'action_output'].include?(dependence_type)
|
145
|
+
raise GatgetConfigException.new("undefined gat dependence type #{ dependence_type }", "get_dependence_value")
|
146
|
+
end
|
147
|
+
|
148
|
+
case dependence_type
|
149
|
+
when 'static'
|
150
|
+
ret = self.config['static'][dependence_name]
|
151
|
+
when 'variable'
|
152
|
+
ret = self.variables[dependence_name]
|
153
|
+
when 'folders'
|
154
|
+
dependence_folders = self.operation.send(dependence_type).select { |dependence| dependence_name[/^#{ dependence.name }/]}
|
155
|
+
if dependence_folders.any?
|
156
|
+
ret = dependence_folders.first.value(dependence_name)
|
157
|
+
else
|
158
|
+
ret = nil
|
159
|
+
end
|
160
|
+
when 'action_output'
|
161
|
+
ret = self.operation.get_action(dependence_name).output
|
162
|
+
else
|
163
|
+
values = self.operation.send(dependence_type)
|
164
|
+
if values.any?
|
165
|
+
ret = values.select { |dependence| dependence_name == dependence.name }.first.value
|
166
|
+
else
|
167
|
+
raise GatgetConfigException.new("Empty dependence '#{dependence_type}', for operation '#{self.operation.name}'", "get_dependence_value")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Set a value for a variable to be used along the script
|
173
|
+
# Override variable is warned at warning level
|
174
|
+
def set_dependence_variable(variable_name, variable_value)
|
175
|
+
if self.variables[variable_name]
|
176
|
+
@logger.log("warning", "dependence", "#{ self.class } rewrite variable #{ variable_name } at #{ Time.now }")
|
177
|
+
end
|
178
|
+
|
179
|
+
self.variables[variable_name] = variable_value
|
180
|
+
end
|
181
|
+
|
182
|
+
# Set flag value
|
183
|
+
def set_flag(flag_name, true_or_false)
|
184
|
+
self.flags[flag_name] = true_or_false
|
185
|
+
end
|
186
|
+
|
187
|
+
# Get flag value
|
188
|
+
def get_flag(flag_name)
|
189
|
+
ret = self.flags[flag_name]
|
190
|
+
if ret == nil
|
191
|
+
self.operation.gatget.logger.log("warning", "get_flag","Undefined flag #{flag_name}")
|
192
|
+
ret = false
|
193
|
+
end
|
194
|
+
ret
|
195
|
+
end
|
196
|
+
|
197
|
+
# Execute the gatget
|
198
|
+
# Now, this method just call the current operation and run it. As interactive mode, and after set dependences,
|
199
|
+
# execute method will run also @operations or another interactive process
|
200
|
+
def execute
|
201
|
+
if self.operation
|
202
|
+
self.operation.execute
|
203
|
+
else
|
204
|
+
raise GatgetConfigException("Operation is undefined!", "gatget_execute")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
# Set the @config attribute to the gaget. This method read the Gatget YML config and merge with other possible inputs
|
210
|
+
#
|
211
|
+
# Gat gets the gatget name by the class.superclass method. So, a Gatget must be ALWAYS runned by a launchers see example for more information
|
212
|
+
#
|
213
|
+
# options Hash with some options
|
214
|
+
# - config_file_path: where the config file is stored. By default < gat_gem_install/gatgets/category/<gatget_name>.yml
|
215
|
+
# - gatget_config: override default options with launcher options
|
216
|
+
# - gat_config: link to common gatgets config at yml format
|
217
|
+
#
|
218
|
+
private
|
219
|
+
def set_gatget_config(options)
|
220
|
+
|
221
|
+
gatget_name = self.class.superclass.name.gsub(/^Gatget/,'').underscore
|
222
|
+
@path = eval("GATGET_#{ gatget_name.upcase }_ROOT")
|
223
|
+
options ||= Hash.new
|
224
|
+
config_file = options['config_file_path'] || "#{ @path }/#{ gatget_name }.yml"
|
225
|
+
|
226
|
+
config = get_yaml_config("#{ config_file }") || Hash.new
|
227
|
+
|
228
|
+
# merge default yml script structure with specific instance options
|
229
|
+
if options['gatget_config'] and options['gatget_config'].any?
|
230
|
+
config = config.deep_merge(options['gatget_config'])
|
231
|
+
end
|
232
|
+
|
233
|
+
# include gat common config?
|
234
|
+
if options['gat_config']
|
235
|
+
gat_config = get_yaml_config(options['gat_config'])
|
236
|
+
config = config.deep_merge(gat_config)
|
237
|
+
end
|
238
|
+
|
239
|
+
# set attributes
|
240
|
+
@name = gatget_name
|
241
|
+
@description = config['description'] || 'Another Gatget'
|
242
|
+
@config_file = config_file
|
243
|
+
@config = config
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
# Get the YML config at one path
|
248
|
+
# Just to rescue the error formating at YML or so
|
249
|
+
#
|
250
|
+
def get_yaml_config(gatget_config_file)
|
251
|
+
begin
|
252
|
+
config_yml = YAML.load_file(gatget_config_file)
|
253
|
+
rescue => error_msj
|
254
|
+
raise GatgetConfigException.new(error_msj, 'get_yaml_config')
|
255
|
+
end
|
256
|
+
config_yml
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
# Evalue the gatget operation
|
262
|
+
#
|
263
|
+
# Gatget runs by operations, which *must* come as first aguments. For example. gat_backup do_backup, perform #do_backup# operations
|
264
|
+
# Detect if operations missing or not in config
|
265
|
+
def build_operation(arguments = [])
|
266
|
+
|
267
|
+
# Run help for gatget
|
268
|
+
help?(arguments)
|
269
|
+
|
270
|
+
# is gatget_operations defined?
|
271
|
+
unless @config['operations'] and @config['operations'].any?
|
272
|
+
raise GatgetConfigException.new("operations not defined in config: #{@config_file}", "build_operation")
|
273
|
+
end
|
274
|
+
|
275
|
+
# do we have an operation in arguments?
|
276
|
+
unless arguments.any?
|
277
|
+
gatget_help
|
278
|
+
raise GatgetArgumentException.new("no operation invoking gat", "build_operation")
|
279
|
+
end
|
280
|
+
|
281
|
+
# do we have an operation at config?
|
282
|
+
unless @config['operations'].include?(arguments.first)
|
283
|
+
gatget_help
|
284
|
+
raise GatgetArgumentException.new("operation `#{ arguments.first }` undefined invoking gat", "build_operation")
|
285
|
+
end
|
286
|
+
|
287
|
+
# return operation.new
|
288
|
+
operation = Gat::Operation.new(arguments.first, @config['operations'][arguments.first], self)
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
protected
|
293
|
+
# Set debug to Gat
|
294
|
+
def debug?(arguments)
|
295
|
+
debug = false
|
296
|
+
if arguments.include?('-d') or arguments.include?('--debug_mode')
|
297
|
+
debug = true
|
298
|
+
arguments = arguments - ['-d', '--debug_mode']
|
299
|
+
end
|
300
|
+
return debug, arguments
|
301
|
+
end
|
302
|
+
|
303
|
+
# Set verbose to gat
|
304
|
+
def verbose?(arguments)
|
305
|
+
verbose = 0
|
306
|
+
arguments.each do |argument|
|
307
|
+
if argument[/^-v/]
|
308
|
+
verbose = argument.count('v')
|
309
|
+
arguments = arguments - [ argument ]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
return verbose, arguments
|
313
|
+
end
|
314
|
+
|
315
|
+
# Show help and exit
|
316
|
+
def help?(arguments)
|
317
|
+
if arguments.include?('-h') or arguments.include?('--help')
|
318
|
+
gatget_help
|
319
|
+
exit 0
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|