Class: AptControl::CLI::Root
Defined Under Namespace
Classes: FSListenerFactory
Constant Summary
collapse
- DEFAULT_CONFIG_FILE_LOCATION =
'/etc/apt_control/config.yaml'
Instance Method Summary
collapse
configs
Instance Method Details
#apt_site ⇒ Object
155
156
157
|
# File 'lib/apt_control/cli.rb', line 155
def apt_site
@apt_site ||= AptSite.new(config[:apt_site_dir], logger)
end
|
#build_archive ⇒ Object
163
164
165
|
# File 'lib/apt_control/cli.rb', line 163
def build_archive
@build_archive ||= BuildArchive.new(config[:build_archive_dir], logger)
end
|
#build_config ⇒ Object
Read yaml file if one exists, then apply overrides from the command line
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/apt_control/cli.rb', line 110
def build_config
file = [options[:config_file], DEFAULT_CONFIG_FILE_LOCATION].
compact.find {|f| File.exists?(f) }
hash =
if file
YAML.load_file(file).each do |key, value|
stderr.puts("Warn: Unknown key in config file: #{key}") unless
self.class.configs.find {|opt| opt.first.to_s == key.to_s }
end
else
{}
end
options[:config_option].map {|str| str.split('=') }.
inject(hash) {|m, (k,v)| m.merge(k.to_sym => v) }
end
|
#config ⇒ Object
103
104
105
|
# File 'lib/apt_control/cli.rb', line 103
def config
@config ||= build_config
end
|
#control_file ⇒ Object
159
160
161
|
# File 'lib/apt_control/cli.rb', line 159
def control_file
@control_file ||= ControlFile.new(config[:control_file], logger)
end
|
#fs_listener_factory ⇒ Object
196
197
198
199
|
# File 'lib/apt_control/cli.rb', line 196
def fs_listener_factory
@fs_listener_factory ||= FSListenerFactory.new(
disable_inotify: config[:disable_inotify].to_s == 'true')
end
|
#includer ⇒ Object
172
173
174
|
# File 'lib/apt_control/cli.rb', line 172
def includer
@includer ||= Includer.new(apt_site, build_archive)
end
|
#logger ⇒ Object
143
144
145
146
147
|
# File 'lib/apt_control/cli.rb', line 143
def logger
@logger ||= Logger.new(config[:log_file] || STDOUT).tap do |logger|
logger.level = Logger::DEBUG
end
end
|
#notifier ⇒ Object
167
168
169
170
|
# File 'lib/apt_control/cli.rb', line 167
def notifier
@notify ||= Jabber.new(:jid => config[:jabber_id], :logger => logger,
:password => config[:jabber_password], :room_jid => config[:jabber_chatroom_id])
end
|
#notify(message) ⇒ Object
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/apt_control/cli.rb', line 201
def notify(message)
logger.info("notify: #{message}")
return unless config[:jabber_enabled].to_s == 'true'
begin
notifier.send_message(message)
rescue => e
logger.error("Unable to send notification to jabber: #{e}")
logger.error(e)
end
end
|
#package_states ⇒ Object
149
150
151
152
153
|
# File 'lib/apt_control/cli.rb', line 149
def package_states
@package_states ||= PackageStates.new(apt_site: apt_site,
build_archive: build_archive,
control_file: control_file)
end
|
#validate_config! ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/apt_control/cli.rb', line 128
def validate_config!
self.class.configs.each do |key, desc, options|
if options[:required]
config[key] or raise Climate::ExitException, "Error: No config supplied for #{key}"
end
end
if config[:jabber_enabled]
self.class.configs.each do |key, desc, options|
next unless key.to_s['jabber_']
config[key] or raise Climate::ExitException, "Error: you must supply all jabber options if jabber is enabled"
end
end
end
|