forj 0.0.43 → 0.0.44

Sign up to get free protection for your applications and to get access to all the features.
data/lib/forj-config.rb CHANGED
@@ -24,40 +24,180 @@ require 'yaml'
24
24
  #require_relative 'log.rb'
25
25
  #include Logging
26
26
 
27
+ def rhExist?(yVal, *p)
28
+
29
+ if p.length() == 0
30
+ return 0
31
+ end
32
+ return 0 if yVal.class != Hash
33
+ p=p.flatten
34
+ if p.length() == 1
35
+ return 1 if yVal.key?(p[0])
36
+ return 0
37
+ end
38
+ return 0 if yVal.nil? or not yVal.key?(p[0])
39
+ ret = 0
40
+ ret = rhExist?(yVal[p[0]], p.drop(1)) if yVal[p[0]].class == Hash
41
+ return 1 + ret
42
+ end
43
+
44
+ def rhGet(yVal, *p)
45
+
46
+ return nil if yVal.class != Hash
47
+ p=p.flatten
48
+ if p.length() == 0 or not yVal
49
+ return yVal
50
+ end
51
+ if p.length() == 1
52
+ return yVal[p[0]] if yVal.key?(p[0])
53
+ return nil
54
+ end
55
+ return nil if not yVal
56
+ return rhGet(yVal[p[0]], p.drop(1)) if yVal.key?(p[0])
57
+ nil
58
+ end
59
+
60
+ def rhSet(yVal, value, *p)
61
+ if p.length() == 0
62
+ return yVal
63
+ end
64
+ p=p.flatten
65
+ if p.length() == 1
66
+ if not yVal.nil?
67
+ if value
68
+ yVal[p[0]] = value
69
+ else
70
+ yVal.delete(p[0])
71
+ end
72
+ return yVal
73
+ end
74
+ if value
75
+ ret = { p[0] => value }
76
+ else
77
+ ret = {}
78
+ end
79
+ return ret
80
+ end
81
+ if not yVal.nil?
82
+ yVal[p[0]] = {} if not yVal[p[0]] or yVal[p[0]].class != Hash
83
+ ret=rhSet(yVal[p[0]], value, p.drop(1))
84
+ return yVal
85
+ else
86
+ ret = rhSet(nil, value, p.drop(1))
87
+ return { p[0] => ret }
88
+ end
89
+ end
90
+
91
+ def rhKeyToSymbol(yVal, levels = 1)
92
+ return nil if yVal.nil? or yVal.class != Hash
93
+ yRes = {}
94
+ yVal.each { | key, value |
95
+ if key.class == String
96
+ if levels <= 1
97
+ yRes[key.to_sym] = value
98
+ else
99
+ yRes[key.to_sym] = rhKeyToSymbol(value, levels - 1)
100
+ end
101
+ else
102
+ if levels <= 1
103
+ yRes[key] = value
104
+ else
105
+ yRes[key] = rhKeyToSymbol(value, levels - 1)
106
+ end
107
+ end
108
+ }
109
+ yRes
110
+ end
111
+
112
+ def rhKeyToSymbol?(yVal, levels = 1)
113
+ return false if yVal.nil? or yVal.class != Hash
114
+ yVal.each { | key, value |
115
+ if key.class == String
116
+ return true
117
+ end
118
+ if levels >1
119
+ res = rhKeyToSymbol?(value, levels - 1)
120
+ return true if res
121
+ end
122
+ }
123
+ false
124
+ end
125
+
27
126
  class ForjDefault
28
127
 
29
128
  # @sDefaultsName='defaults.yaml'
30
129
  # @yDefaults = defaults.yaml file data hash
31
130
 
32
- def initialize()
33
- # Load yaml documents (defaults)
34
- # If config doesn't exist, it will be created, empty with 'defaults:' only
131
+ # Load yaml documents (defaults)
132
+ # If config doesn't exist, it will be created, empty with 'defaults:' only
133
+
35
134
 
36
- if not $LIB_PATH
37
- Logging.fatal(1, 'Internal $LIB_PATH was not set.')
38
- end
135
+ def self.exist?(key, section = :default)
136
+ key = key.to_sym if key.class == String
137
+ (rhExist?(@@yDefaults, section, key) == 2)
138
+ end
139
+
140
+ def self.get(key, section = :default)
141
+ key = key.to_sym if key.class == String
142
+ return(rhGet(@@yDefaults, section, key)) if key
143
+ rhGet(@@yDefaults, section) if not key
144
+ end
39
145
 
40
- Logging.info('Reading default configuration...')
146
+ def self.dump()
147
+ @@yDefaults
148
+ end
149
+ # Loop on Config metadata
150
+ def self.meta_each
151
+ rhGet(@@yDefaults, :sections).each { | section, hValue |
152
+ hValue.each { | key, value |
153
+ yield section, key, value
154
+ }
155
+ }
156
+ end
41
157
 
42
- @sDefaultsName=File.join($LIB_PATH,'defaults.yaml')
158
+ def self.meta_exist?(key)
159
+ return nil if not key
43
160
 
44
- @yDefaults=YAML.load_file(@sDefaultsName)
161
+ key = key.to_sym if key.class == String
162
+ section = rhGet(@@account_section_mapping, key)
163
+ rhExist?(@@yDefaults, :sections, section, key) == 3
45
164
  end
46
165
 
47
- def exist?(key, section = :default)
166
+ def self.get_meta(key)
167
+ return nil if not key
168
+
48
169
  key = key.to_sym if key.class == String
49
- (rhExist?(@yDefaults, section, key) == 2)
170
+ section = rhGet(@@account_section_mapping, key)
171
+ rhGet(@@yDefaults, :sections, section, key)
172
+ end
173
+
174
+ def self.build_section_mapping
175
+ @@account_section_mapping = {}
176
+ rhGet(@@yDefaults, :sections).each { | section, hValue |
177
+ next if section == :default
178
+ hValue.each_key { | map_key |
179
+ Logging.fatal(1, "defaults.yaml: Duplicate entry between sections. '%s' defined in section '%s' already exists in section '%s'" % [map_key, section, rhGet(@account_section_mapping, map_key) ])if rhExist?(@account_section_mapping, map_key) != 0
180
+ rhSet(@@account_section_mapping, section, map_key)
181
+ }
182
+ }
50
183
  end
51
184
 
52
- def get(key, section = :default)
185
+ def self.get_meta_section(key)
53
186
  key = key.to_sym if key.class == String
54
- return(rhGet(@yDefaults, section, key)) if key
55
- rhGet(@yDefaults, section) if not key
187
+ rhGet(@@account_section_mapping, key)
56
188
  end
57
189
 
58
- def dump()
59
- @yDefaults
190
+ if not $LIB_PATH
191
+ Logging.fatal(1, 'Internal $LIB_PATH was not set.')
60
192
  end
193
+
194
+ Logging.info('Reading default configuration...')
195
+
196
+ @@sDefaultsName=File.join($LIB_PATH,'defaults.yaml')
197
+
198
+ @@yDefaults=YAML.load_file(@@sDefaultsName)
199
+
200
+ self.build_section_mapping
61
201
  end
62
202
 
63
203
  class ForjConfig
@@ -67,7 +207,7 @@ class ForjConfig
67
207
  # @yRuntime = data in memory.
68
208
  # @yLocal = config.yaml file data hash.
69
209
  # @yObjConfig = Extra loaded data
70
- # @oDefaults = Application defaults object
210
+ # ForjDefault = Application defaults class
71
211
 
72
212
  attr_reader :sConfigName
73
213
 
@@ -78,7 +218,7 @@ class ForjConfig
78
218
  # Build a config hash.
79
219
 
80
220
  res = {}
81
- @oDefaults.dump[:default].each_key { |key|
221
+ ForjDefault.dump[:default].each_key { |key|
82
222
  dump_key = exist?(key)
83
223
  rhSet(res, get(key), dump_key, key)
84
224
  }
@@ -134,12 +274,10 @@ class ForjConfig
134
274
  @sConfigName = File.join($FORJ_DATA_PATH,sConfigDefaultName)
135
275
  end
136
276
 
137
- @oDefaults = ForjDefault.new
138
-
139
277
  if File.exists?(@sConfigName)
140
278
  @yLocal = YAML.load_file(@sConfigName)
141
279
  if rhKeyToSymbol?(@yLocal, 2)
142
- @yLocal = rhKeyToSymbol(@yLocal, 2)
280
+ @yLocal = rhKeyToSymbol(@yLocal, 2)
143
281
  self.SaveConfig()
144
282
  end
145
283
 
@@ -222,7 +360,7 @@ class ForjConfig
222
360
  # Function to set a runtime key/value, but remove it if value is nil.
223
361
  # To set in config.yaml, use LocalSet
224
362
  # To set on extra data, like account information, use ExtraSet
225
-
363
+
226
364
  key = key.to_sym if key.class == String
227
365
  return false if key.class != Symbol
228
366
 
@@ -234,42 +372,49 @@ class ForjConfig
234
372
  true
235
373
  end
236
374
 
237
- def get(key, interms = nil, default = nil)
238
-
375
+ def runtimeExist?(key)
376
+ (rhExist?(@yRuntime, key) == 1)
377
+ end
378
+
379
+ def runtimeGet(key)
380
+ rhGet(@yRuntime, key) if runtimeExist?(key)
381
+ end
382
+
383
+ def get(key, default = nil)
239
384
  key = key.to_sym if key.class == String
240
385
  return nil if key.class != Symbol
241
386
  # If key is in runtime
242
- return rhGet(@yRuntime, key) if rhExist?(@yRuntime, key) == 1
243
- # Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
244
- if interms
245
- if interms.instance_of? Hash
246
- return rhGet(interms, key) if rhExist?(interms, key) == 1
247
- elsif interms.instance_of? Array # Array of hashes
248
- iCount=0
249
- oVal = nil
250
- interms.each { | elem |
251
- if elem.class == Hash
252
- elem.each { | hashkey, value |
253
- if value.class == Hash and rhExist?(elem, hashkey, key) == 2 # hash of hash
254
- oVal = rhGet(elem, hashkey, key)
255
- break
256
- elsif value.class != Hash and rhExist?(elem, hashkey) == 1 # single hash: key = value.
257
- oVal = rhGet(elem, hashkey)
258
- break
259
-
260
- end
261
- }
262
- break if oVal
263
- end
264
- iCount += 1
265
- }
266
- return oVal
267
- end
268
- end
387
+ return runtimeGet(key) if runtimeExist?(key)
388
+ #~ # Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
389
+ #~ if interms
390
+ #~ if interms.instance_of? Hash
391
+ #~ return rhGet(interms, key) if rhExist?(interms, key) == 1
392
+ #~ elsif interms.instance_of? Array # Array of hashes
393
+ #~ iCount=0
394
+ #~ oVal = nil
395
+ #~ interms.each { | elem |
396
+ #~ if elem.class == Hash
397
+ #~ elem.each { | hashkey, value |
398
+ #~ if value.class == Hash and rhExist?(elem, hashkey, key) == 2 # hash of hash
399
+ #~ oVal = rhGet(elem, hashkey, key)
400
+ #~ break
401
+ #~ elsif value.class != Hash and rhExist?(elem, hashkey) == 1 # single hash: key = value.
402
+ #~ oVal = rhGet(elem, hashkey)
403
+ #~ break
404
+ #~
405
+ #~ end
406
+ #~ }
407
+ #~ break if oVal
408
+ #~ end
409
+ #~ iCount += 1
410
+ #~ }
411
+ #~ return oVal
412
+ #~ end
413
+ #~ end
269
414
  # else key in local default config of default section.
270
415
  return LocalGet(key) if LocalDefaultExist?(key)
271
416
  # else key in application defaults
272
- return @oDefaults.get(key) if @oDefaults.exist?(key)
417
+ return ForjDefault.get(key) if ForjDefault.exist?(key)
273
418
  # else default
274
419
  default
275
420
  end
@@ -278,7 +423,7 @@ class ForjConfig
278
423
 
279
424
  key = key.to_sym if key.class == String
280
425
 
281
- @oDefaults.get(key, section)
426
+ ForjDefault.get(key, section)
282
427
  end
283
428
 
284
429
  def exist?(key, interms = nil)
@@ -304,7 +449,7 @@ class ForjConfig
304
449
  end
305
450
  return 'local' if LocalDefaultExist?(key)
306
451
  # else key in application defaults
307
- return 'default' if @oDefaults.exist?(key)
452
+ return 'default' if ForjDefault.exist?(key)
308
453
  false
309
454
  end
310
455
 
@@ -358,101 +503,12 @@ class ForjConfig
358
503
  def fatal_if_inexistent(key)
359
504
  Logging.fatal(1, "Internal error - %s: '%s' is missing" % [caller(), key]) if not self.get(key)
360
505
  end
361
- end
362
506
 
363
- def rhExist?(yVal, *p)
364
-
365
- if p.length() == 0
366
- return 0
507
+ def meta_each
508
+ ForjDefault.meta_each { |section, key, value|
509
+ next if rhGet(value, :account_exclusive)
510
+ yield section, key, value
511
+ }
367
512
  end
368
- return 0 if yVal.class != Hash
369
- p=p.flatten
370
- if p.length() == 1
371
- return 1 if yVal[p[0]]
372
- return 0
373
- end
374
- return 0 if not yVal or not yVal[p[0]]
375
- ret = rhExist?(yVal[p[0]], p.drop(1)) if yVal[p[0]]
376
- return 1 + ret
377
- end
378
-
379
- def rhGet(yVal, *p)
380
-
381
- if p.length() == 0 or not yVal
382
- return nil
383
- end
384
- p=p.flatten
385
- if p.length() == 1
386
- return yVal[p[0]] if yVal[p[0]]
387
- return nil
388
- end
389
- return nil if not yVal
390
- return rhGet(yVal[p[0]], p.drop(1)) if yVal[p[0]]
391
- nil
392
- end
393
513
 
394
- def rhSet(yVal, value, *p)
395
- if p.length() == 0
396
- return yVal
397
- end
398
- p=p.flatten
399
- if p.length() == 1
400
- if yVal
401
- if value
402
- yVal[p[0]] = value
403
- else
404
- yVal.delete(p[0])
405
- end
406
- return yVal
407
- end
408
- if value
409
- ret = { p[0] => value }
410
- else
411
- ret = {}
412
- end
413
- return ret
414
- end
415
- if yVal
416
- yVal[p[0]] = {} if not yVal[p[0]] or yVal[p[0]].class != Hash
417
- ret=rhSet(yVal[p[0]], value, p.drop(1))
418
- return yVal
419
- else
420
- ret = rhSet(nil, value, p.drop(1))
421
- return { p[0] => ret }
422
- end
423
- end
424
-
425
- def rhKeyToSymbol(yVal, levels = 1)
426
- return nil if not yVal
427
- yRes = {}
428
- yVal.each { | key, value |
429
- if key.class == String
430
- if levels <= 1
431
- yRes[key.to_sym] = value
432
- else
433
- yRes[key.to_sym] = rhKeyToSymbol(value, levels - 1)
434
- end
435
- else
436
- if levels <= 1
437
- yRes[key] = value
438
- else
439
- yRes[key] = rhKeyToSymbol(value, levels - 1)
440
- end
441
- end
442
- }
443
- yRes
444
- end
445
-
446
- def rhKeyToSymbol?(yVal, levels = 1)
447
- return false if not yVal
448
- yVal.each { | key, value |
449
- if key.class == String
450
- return true
451
- end
452
- if levels >1
453
- res = rhKeyToSymbol?(value, levels - 1)
454
- return true if res
455
- end
456
- }
457
- false
458
514
  end
@@ -0,0 +1,209 @@
1
+ # encoding: UTF-8
2
+
3
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Forj
18
+ module Settings
19
+ def Settings.account_show_all(oConfig, account_name)
20
+ oConfig.set(:account_name, account_name)
21
+
22
+ oForjAccount = ForjAccount.new(oConfig)
23
+ oForjAccount.ac_load()
24
+ puts "List of account settings for provider '%s': " % [oForjAccount.get(:provider)]
25
+ puts "%-15s %-12s :\n------------------------------" % ['key', 'section name']
26
+
27
+ oForjAccount.metadata_each { |section, found_key, hValue|
28
+ next if rhGet(hValue, :readonly)
29
+ sDesc = rhGet(hValue, :desc)
30
+ puts "%-15s %-12s : %s" % [found_key, section, sDesc]
31
+ }
32
+ puts "\nUse `forj set KeyName=Value -a %s` to set one." % [ account_name]
33
+ puts "Use `forj get -a %s` to check current values." % [ account_name]
34
+ end
35
+
36
+ def Settings.config_show_all(oConfig)
37
+ puts "List of available FORJ default settings:"
38
+ puts "%-15s %-12s :\n------------------------------" % ['key', 'section name']
39
+ oConfig.meta_each { |section, found_key, hValue|
40
+ next if rhGet(hValue, :readonly)
41
+ sDesc = rhGet(hValue, :desc)
42
+ puts "%-15s %-12s : %s" % [found_key, section, sDesc]
43
+ }
44
+ puts "\nUse `forj set KeyName=Value` to set one. "
45
+ puts "Use `forj get` to get current values. "
46
+ end
47
+
48
+ def Settings.account_set(oConfig, account_name, *p)
49
+ bDirty = false
50
+
51
+ oConfig.set(:account_name, account_name)
52
+
53
+ oForjAccount = ForjAccount.new(oConfig)
54
+ oForjAccount.ac_load()
55
+
56
+ p.flatten!
57
+ p.each { | key_val |
58
+ mkey_val = key_val.match(/^(.*) *= *(.*)$/)
59
+
60
+ Logging.fatal(1, "Syntax error. Please set your value like: 'key=value' and retry.") if not mkey_val
61
+
62
+ key_to_set = mkey_val[1]
63
+ key_value = mkey_val[2]
64
+
65
+ sBef = "unset"
66
+ sAft = "unset"
67
+
68
+ Logging.fatal(1, "Unable to update protected '%s'. use `forj setup`, to update it." % key_to_set) if oForjAccount.readonly?(key_to_set)
69
+ if oForjAccount.meta_type?(key_to_set) == :default
70
+ Logging.fatal(1, "Unable set '%s' value. To update this one, use forj set %s, WITHOUT -a %s" % [key_to_set, key_to_set, account_name])
71
+ end
72
+
73
+ full_key = '%s/%s' % [ForjDefault.get_meta_section(key_to_set), key_to_set]
74
+
75
+ old_value = oForjAccount.get(key_to_set)
76
+ sBef = "'%s' (%s)" % [old_value, oForjAccount.exist?(key_to_set)] if oForjAccount.exist?(key_to_set)
77
+
78
+ if old_value == key_value
79
+ puts "%-25s: No update" % [full_key]
80
+ next
81
+ end
82
+ bDirty = true
83
+
84
+ if key_value == ""
85
+ oForjAccount.del(key_to_set)
86
+ else
87
+ oForjAccount.set(key_to_set, key_value)
88
+ end
89
+
90
+ sAft = "'%s' (%s)" % [oForjAccount.get(key_to_set), oForjAccount.exist?(key_to_set)] if oForjAccount.exist?(key_to_set)
91
+ puts "%-25s: %s => %s" % [full_key, sBef, ANSI.bold+sAft+ANSI.clear]
92
+ }
93
+ oForjAccount.ac_save() if bDirty
94
+ end
95
+
96
+ def Settings.config_set(oConfig, *p)
97
+ bDirty = false
98
+
99
+ p.flatten!
100
+ p.each { | key_val |
101
+ mkey_val = key_val.match(/^(.*) *= *(.*)$/)
102
+
103
+ Logging.fatal(1, "Syntax error. Please set your value like: 'key=value' and retry.") if not mkey_val
104
+
105
+ key_to_set = mkey_val[1]
106
+ key_value = mkey_val[2]
107
+
108
+ sBef = "unset"
109
+ sAft = "unset"
110
+
111
+ old_value = oConfig.get(key_to_set)
112
+ sBef = "%s: '%s'" % [oConfig.exist?(key_to_set), oConfig.get(key_to_set)] if oConfig.exist?(key_to_set)
113
+
114
+ if old_value == key_value
115
+ puts "%-15s: No update" % [key_to_set]
116
+ next
117
+ end
118
+
119
+ bDirty = true
120
+
121
+ if key_value != ""
122
+ oConfig.LocalSet(key_to_set, key_value)
123
+ else
124
+ oConfig.LocalDel(key_to_set)
125
+ end
126
+
127
+ sAft = "%s: '%s'" % [oConfig.exist?(key_to_set), oConfig.get(key_to_set)] if oConfig.exist?(key_to_set)
128
+ puts "%-15s: %s => %s" % [key_to_set, sBef, ANSI.bold+sAft+ANSI.clear]
129
+ }
130
+ oConfig.SaveConfig() if bDirty
131
+ end
132
+
133
+ def Settings.account_get_all(oConfig, account_name)
134
+ oConfig.set(:account_name, account_name)
135
+ oForjAccount = ForjAccount.new(oConfig)
136
+ Logging.fatal(1, "Unable to load account '%s'. Not found." % account_name) if not oForjAccount.ac_load
137
+
138
+ puts "legend: default = Application defaults, local = Local default config, %s = '%s' account config\n\n" % [account_name, account_name]
139
+ puts "%s %-15s(%-7s) %-12s:\n----------------------------------------" % ['U', 'key', 'origin', 'section name']
140
+ oForjAccount.metadata_each { | section, mykey, hValue |
141
+ key_exist = oForjAccount.exist?(mykey)
142
+
143
+ sUpdMsg = '+'
144
+ sUpdMsg = ' ' if rhGet(hValue, :readonly)
145
+
146
+ if key_exist
147
+ highlight = ''
148
+ highlight = ANSI.bold if key_exist == account_name
149
+ highlight = ANSI.bold + ANSI.yellow if key_exist == 'local'
150
+ default_key = nil
151
+ default_key = " (from default key '%s')" % rhGet(hValue, :default) if rhExist?(hValue, :default) == 1 and key_exist != account_name
152
+ puts "%s %-15s(%s%-7s%s) %-12s: '%s'%s" % [sUpdMsg, mykey, highlight, key_exist, ANSI.clear, section, oForjAccount.get(mykey), default_key]
153
+ else
154
+ puts "%s %-15s( ) %-12s: unset" % [sUpdMsg, mykey, section]
155
+ end
156
+ }
157
+ puts "\nOn values identified by '+' you can:"
158
+ puts "Use `forj set <key>=<value> -a %s` to update account data." % account_name
159
+ puts "Or `forj set <key>= -a %s` to restore key default value." % account_name
160
+ end
161
+
162
+ def Settings.config_get_all(oConfig)
163
+ puts "legend: default = Application defaults, local = Local default config\n\n"
164
+ puts "%s %-15s(%-7s) %-12s:\n----------------------------------------" % ['U', '''key', 'origin', 'section name']
165
+
166
+ oConfig.meta_each { |section, found_key, hValue|
167
+ sUpdMsg = '+'
168
+ sUpdMsg = ' ' if rhGet(hValue, :readonly)
169
+ found_key = rhGet(hValue, :default) if rhExist?(hValue, :default) == 1
170
+
171
+ where = oConfig.exist?(found_key)
172
+ if where
173
+ highlight = ''
174
+ highlight = ANSI.bold + ANSI.yellow if where == 'local'
175
+ puts "%s %-15s(%s%-7s%s) %-12s: '%s'" % [sUpdMsg, found_key, highlight, where, ANSI.clear, section, oConfig.get(found_key) ]
176
+ else
177
+ puts "%s %-15s( ) %-12s: unset" % [sUpdMsg, found_key, section]
178
+ end
179
+ }
180
+ puts "\nUse 'forj set <key>=<value>' to update defaults on values identified with '+'"
181
+
182
+ end
183
+
184
+ def Settings.account_get(oConfig, account_name, key)
185
+
186
+ oConfig.set(:account_name, account_name)
187
+ oForjAccount = ForjAccount.new(oConfig)
188
+
189
+ Logging.fatal(1, "Unable to load account '%s'. Not found." % account_name) if not oForjAccount.ac_load
190
+
191
+ if oForjAccount.exist?(key)
192
+ puts "%s: '%s'" % [oForjAccount.exist?(key), oForjAccount.get(key)]
193
+ elsif oForjAccount.exist?(key.parameterize.underscore.to_sym)
194
+ key_symb = key.parameterize.underscore.to_sym
195
+ puts "%s: '%s'" % [oForjAccount.exist?(key_symb), oForjAccount.get(key_symb)]
196
+ else
197
+ Logging.message("key '%s' not found"% [key])
198
+ end
199
+ end
200
+
201
+ def Settings.config_get(oConfig, key)
202
+ if oConfig.exist?(key)
203
+ puts "%s:'%s'" % [oConfig.exist?(key), oConfig.get(key)]
204
+ else
205
+ Logging.message("key '%s' not found" % [key])
206
+ end
207
+ end
208
+ end
209
+ end
data/lib/helpers.rb CHANGED
@@ -51,10 +51,6 @@ module Helpers
51
51
  false
52
52
  end
53
53
 
54
- def ensure_dir_exists(path)
55
- if not dir_exists?(path)
56
- FileUtils.mkpath(path) if not File.directory?(path)
57
- end
58
- end
54
+
59
55
 
60
56
  end
data/lib/log.rb CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  require 'rubygems'
22
22
  require 'logger'
23
+ require 'ansi'
23
24
 
24
25
  require 'require_relative'
25
26
 
@@ -32,31 +33,6 @@ include Helpers
32
33
  #
33
34
  module Logging
34
35
 
35
- class SSLErrorMgt
36
-
37
- def initialize()
38
- @iRetry=0
39
- end
40
-
41
- def ErrorDetected(message,backtrace)
42
- if message.match('SSLv2/v3 read server hello A: unknown protocol')
43
- if @iRetry <5
44
- sleep(2)
45
- @iRetry+=1
46
- print "%s/5 try...\r" % @iRetry if $FORJ_LOGGER.level == 0
47
- return false
48
- else
49
- Logging.error('Too many retry. %s' % message)
50
- return true
51
- end
52
- else
53
- Logging.error("%s\n%s" % [message,backtrace.join("\n")])
54
- return true
55
- end
56
- end
57
-
58
- end
59
-
60
36
  class ForjLog
61
37
  # Class used to create 2 log object, in order to keep track of error in a log file and change log output to OUTPUT on needs (option flags).
62
38