Module: DLDInternet::AWS::EC2::Instance_Types::MixIns::NoCommands

Includes:
Mixlib::Logging
Defined in:
lib/dldinternet/aws/ec2/instance_types/mixins/no_commands.rb

Instance Method Summary collapse

Instance Method Details

#parse_optionsObject



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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dldinternet/aws/ec2/instance_types/mixins/no_commands.rb', line 30

def parse_options
  if options[:help]
    Cli.start(['help'])
    exit 0
  end
  validate_options

  lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
      :trace => :blue,
      :debug => :cyan,
      :info  => :green,
      :step  => :green,
      :warn  => :yellow,
      :error => :red,
      :fatal => :red,
      :todo  => :purple,
  })
  scheme = lcs.scheme
  scheme['trace'] = "\e[38;5;33m"
  scheme['fatal'] = "\e[38;5;89m"
  scheme['todo']  = "\e[38;5;55m"
  lcs.scheme scheme
  @config         = @options.dup
  @config[:log_opts] = lambda{|mlll| {
      :pattern      => "%#{mlll}l: %m %g\n",
      :date_pattern => '%Y-%m-%d %H:%M:%S',
      :color_scheme => 'compiler',
      :trace        => (@config[:trace].nil? ? false : @config[:trace]),
      # [2014-06-30 Christo] DO NOT do this ... it needs to be a FixNum!!!!
      # If you want to do ::Logging.init first then fine ... go ahead :)
      # :level        => @config[:log_level],
  }
  }
  @logger = getLogger(@config)

  if @options[:inifile]
    @options[:inifile] = File.expand_path(@options[:inifile])
    unless File.exist?(@options[:inifile])
      raise "#{@options[:inifile]} not found!"
    end
    begin
      ini = ::IniFile.load(@options[:inifile])
      ini['global'].each{ |key,value|
        @options[key.to_s]=value
      }
      def _expand(k,v,regex,rerun)
        matches = v.match(regex)
        if matches
          var = matches[1]
          if options[var]
            options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
          else
            rerun[var] = 1
          end
        end
      end

      pending = nil
      rerun = {}
      begin
        pending = rerun
        rerun = {}
        options.to_hash.each{|k,v|
          if v.to_s.match(/\%/)
            _expand(k,v,%r'[^\\]\%\((\w+)\)', rerun)
            _expand(k,v,%r'[^\\]\%(\w+)',     rerun)
          end
        }
        # Should break out the first time that we make no progress!
      end while pending != rerun
    rescue ::IniFile::Error => e
      # noop
    rescue ::Exception => e
      @logger.error "#{e.class.name} #{e.message}"
      raise e
    end
  end

  if options[:verbose]
    @logger.info "Options:\n#{options.ai}"
  end

end

#validate_optionsObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dldinternet/aws/ec2/instance_types/mixins/no_commands.rb', line 18

def validate_options
  _options = options.dup
  if options[:log_level]
    log_level = options[:log_level].to_sym
    raise "Invalid log-level: #{log_level}" unless LOG_LEVELS.include?(log_level)
    _options[:log_level] = log_level
  else
    _options[:log_level] ||= :step
  end
  @options = _options
end