2009-04-03 16:27:49 +00:00
|
|
|
|
|
|
|
require 'optparse'
|
|
|
|
require 'ostruct'
|
|
|
|
require 'pp'
|
|
|
|
require 'find'
|
|
|
|
|
2011-08-07 15:06:30 +00:00
|
|
|
#require 'rdebug/base'
|
2012-07-23 23:13:08 +00:00
|
|
|
require 'qasim'
|
2011-03-07 23:51:29 +00:00
|
|
|
|
2011-07-21 14:36:33 +00:00
|
|
|
module Qasim
|
2009-05-22 21:01:23 +00:00
|
|
|
class Config
|
2011-03-10 16:56:34 +00:00
|
|
|
|
2009-12-14 23:56:06 +00:00
|
|
|
attr_reader :maps_active
|
|
|
|
attr_reader :maps
|
2011-07-24 15:41:33 +00:00
|
|
|
attr_reader :mnt_dir
|
2011-03-10 16:56:34 +00:00
|
|
|
|
2011-03-07 23:25:47 +00:00
|
|
|
def initialize
|
2011-03-10 16:56:34 +00:00
|
|
|
|
2009-04-03 16:27:49 +00:00
|
|
|
|
2011-09-04 02:50:38 +00:00
|
|
|
@mnt_dir = File.join ENV['HOME'], "mnt"
|
2009-05-22 21:01:23 +00:00
|
|
|
|
2011-09-04 02:50:38 +00:00
|
|
|
@config_dir = APP_CONFIG_DIR
|
2010-01-24 21:00:47 +00:00
|
|
|
@config_file = nil
|
2009-12-14 23:56:06 +00:00
|
|
|
@maps = []
|
|
|
|
@initialize_enable = false
|
|
|
|
@umount_enable = false
|
|
|
|
@target = nil
|
|
|
|
@verbose_enable = false
|
2011-03-07 23:51:29 +00:00
|
|
|
@debug = false
|
2009-05-22 21:01:23 +00:00
|
|
|
end
|
2009-04-03 16:27:49 +00:00
|
|
|
|
2011-07-24 15:41:33 +00:00
|
|
|
def parse_maps &blk
|
2011-08-07 15:06:30 +00:00
|
|
|
#rdebug "Config: #{@config_dir}/config"
|
2009-05-22 21:01:23 +00:00
|
|
|
|
2011-03-15 16:57:02 +00:00
|
|
|
@maps = []
|
2012-07-27 09:41:34 +00:00
|
|
|
map_dirs = [@config_dir, APP_SYSCONFIG_DIR].select{ |d|
|
2014-10-27 20:04:09 +00:00
|
|
|
File.exist? d and File.directory? d
|
2012-07-27 09:41:34 +00:00
|
|
|
}
|
|
|
|
Find.find( *map_dirs ) do |path|
|
2011-03-07 23:25:47 +00:00
|
|
|
if File.file? path
|
2009-05-22 21:01:23 +00:00
|
|
|
if File.basename( path ) =~ /.map$/
|
2009-12-14 23:56:06 +00:00
|
|
|
begin
|
2011-07-24 16:49:07 +00:00
|
|
|
map = Map.new self, path
|
2011-03-07 23:51:29 +00:00
|
|
|
yield map if block_given?
|
|
|
|
maps.push map
|
2009-12-14 23:56:06 +00:00
|
|
|
rescue
|
|
|
|
# error while parsing map
|
2009-09-19 23:51:18 +00:00
|
|
|
end
|
2009-05-22 21:01:23 +00:00
|
|
|
end
|
|
|
|
#total_size += FileTest.size(path)
|
2009-04-03 16:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|