bin/oneacct-export in oneacct-export-0.1.0 vs bin/oneacct-export in oneacct-export-0.2.0
- old
+ new
@@ -6,20 +6,23 @@
require 'oneacct_exporter/log'
require 'settings'
require 'fileutils'
require 'oneacct_opts'
+#parse options from command line
options = OneacctOpts.parse(ARGV)
+#initialize default logger
log = Logger.new(STDOUT)
+#initialize specific logger according to the configuration
if Settings['logging'] && Settings['logging']['log_type'] == 'file'
begin
log_file = File.open(Settings['logging']['log_file'], File::WRONLY | File::CREAT | File::APPEND)
log = Logger.new(log_file)
rescue => e
- OneacctExporter::Log.setup_logging(log)
+ OneacctExporter::Log.setup_log_level(log)
log.warn("Unable to create log file #{Settings['logging']['log_file']}: #{e.message}.\
Falling back to STDOUT.")
end
elsif Settings['logging'] && Settings['logging']['log_type'] == 'syslog'
log = Syslogger.new('oneacct-export')
@@ -33,10 +36,11 @@
groups = {}
groups[:include] = options.include_groups if options.include_groups
groups[:exclude] = options.exclude_groups if options.exclude_groups
+#read groups restriction from file if chosen
if options.groups_file
log.debug('Reading groups from file...')
if File.exist?(options.groups_file) && File.readable?(options.groups_file)
file = File.open(options.groups_file, 'r')
file.each_line do |line|
@@ -48,10 +52,11 @@
'Skipping groups restriction...')
groups[groups.keys.first] = []
end
end
+#create output directory
begin
FileUtils.mkdir_p Settings.output['output_dir']
rescue SystemCallError => e
puts "Cannot create an output directory: #{e.message}. Quitting."
exit
@@ -66,7 +71,8 @@
opts[:timeout] = options.timeout
opts[:compatibility] = options.compatibility
log.debug(opts)
+#run the export
oneacct_exporter = OneacctExporter.new(opts, log)
oneacct_exporter.export