Class: Konfabulator
- Inherits:
-
Object
- Object
- Konfabulator
- Defined in:
- lib/vcseif/utils/konfigger.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_name ⇒ Object
readonly
Returns the value of attribute config_name.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#top_level_sequence ⇒ Object
Returns the value of attribute top_level_sequence.
-
#vcs_header ⇒ Object
readonly
Returns the value of attribute vcs_header.
Instance Method Summary collapse
- #connectionClassName(section_name) ⇒ Object
-
#initialize(config_spec, logger) ⇒ Konfabulator
constructor
A new instance of Konfabulator.
- #topLevel(section_name) ⇒ Object
- #topLevels ⇒ Object
Constructor Details
#initialize(config_spec, logger) ⇒ Konfabulator
Returns a new instance of Konfabulator.
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 |
# File 'lib/vcseif/utils/konfigger.rb', line 36 def initialize(config_spec, logger) """ config_spec is a Hash """ @config = config_spec @config_name = config_spec['ConfigName'] @log = logger @top_level_sequence = [] content = [] begin cf = File.open(config_spec['ConfigPath'], "r") @content = cf.readlines() cf.close() rescue IOError => ex raise end conf_lines = @content.select { |line| line.class.name == "String" and line !~ /^\s*#/ } section_headers = conf_lines.select { |line| line =~ /^[A-Z][A-Za-z_]+.+\s*:/} if section_headers.length < 2 problem = 'Insufficient content in config file: %s' % @config['ConfigPath'] confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem end if section_headers.length > 5 admonition = 'Excess content in config file: %s' % @config['ConfigPath'] confex = VCSEIF_Exceptions::NonFatalConfigurationError.new(admonition) raise confex, admonition end section_headers = section_headers.collect {|sh| sh.strip().sub(/\s*:.*$/, '')} connector_ident_header = section_headers.shift() if connector_ident_header !~ /Connector/ problem = 'First section in config file must identify the Connector type' confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem end rally_header = section_headers.shift() if not rally_header.start_with?('Rally') problem = 'Second section in config file must be Rally section' confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem end @top_level_sequence << 'Rally' @vcs_header = section_headers.shift known = SUPPORTED_VCS_TARGETS.include?(@vcs_header) if known.nil? or not known problem = 'Third section in config file must identify a known VCS identifier' confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem end @top_level_sequence << @vcs_header # set up defaults for the Services and Transforms sections if those sections aren't in the config file if not @config.has_key?('Services') @config['Services'] = {} @config['Services']['LogLevel'] = 'Info' @config['Services']['Preview'] = false @config['Services']['PostBatchExtension'] = nil @log.info('no Services section specified in the config, using default settings') @top_level_sequence << 'Services' end if not @config.has_key?('Transforms') @config['Transforms'] = {} @log.info('no Transforms section specified in the config') @top_level_sequence << 'Transforms' end while section_headers.length > 0 do header = section_headers.shift begin if not ['Services', 'Transforms'].include?(header) problem = 'Unrecognized section header "%s" found in config' % header confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem else @top_level_sequence << header end rescue VCSEIF_Exceptions::ConfigurationError => ex # noop end end checkRallySectionSanity checkTargetVCSSectionSanity # defuzz the passwords for our internal use if they are fuzzed, # and if they are not, fuzz them in the file defuzzPasswords() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
34 35 36 |
# File 'lib/vcseif/utils/konfigger.rb', line 34 def config @config end |
#config_name ⇒ Object (readonly)
Returns the value of attribute config_name.
34 35 36 |
# File 'lib/vcseif/utils/konfigger.rb', line 34 def config_name @config_name end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
34 35 36 |
# File 'lib/vcseif/utils/konfigger.rb', line 34 def content @content end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
34 35 36 |
# File 'lib/vcseif/utils/konfigger.rb', line 34 def log @log end |
#top_level_sequence ⇒ Object
Returns the value of attribute top_level_sequence.
33 34 35 |
# File 'lib/vcseif/utils/konfigger.rb', line 33 def top_level_sequence @top_level_sequence end |
#vcs_header ⇒ Object (readonly)
Returns the value of attribute vcs_header.
34 35 36 |
# File 'lib/vcseif/utils/konfigger.rb', line 34 def vcs_header @vcs_header end |
Instance Method Details
#connectionClassName(section_name) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/vcseif/utils/konfigger.rb', line 282 def connectionClassName(section_name) if not @config.has_key?(section_name) problem = 'Attempt to identify connection class name for %s, operation not supported' confex = VCSEIF_Exceptions::ConfigurationError.new(problem % section_name) raise confex, problem % section_name end if not ['Rally', @vcs_header].include?(section_name) problem ='Candidate connection class name "%s" not viable for operation' % section_name confex = VCSEIF_Exceptions::ConfigurationError.new(problem) raise confex, problem % section_name end section = @config[section_name] if section.has_key?('Class') class_name = section['Class'] else class_name = 'RallyVCSConnection' if section_name != 'Rally' class_name = '%sConnection' % @vcs_header end end return class_name end |
#topLevel(section_name) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/vcseif/utils/konfigger.rb', line 265 def topLevel(section_name) if section_name == 'VCS' non_vcs_sections = ['Rally', 'Transforms', 'Services'] sections = topLevels().select {|name| non_vcs_sections.include?(name) == false} section_name = sections.first end if @top_level_sequence.include?(section_name) and @config.has_key?(section_name) return @config[section_name] else problem = 'Attempt to retrieve non-existent top level config section for %s' confex = VCSEIF_Exceptions::ConfigurationError.new(problem % section_name) raise confex, problem % section_name end end |
#topLevels ⇒ Object
260 261 262 |
# File 'lib/vcseif/utils/konfigger.rb', line 260 def topLevels() return @top_level_sequence end |