11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|
# File 'lib/zillabyte/cli/config.rb', line 11
def self.get_config_info(dir, session = nil, options = {})
conf_file = nil
if options[:config_file] and File.exists?(options[:config_file])
conf_file = options[:config_file]
else
conf_file = File.join(dir, options[:config_file] || DEFAULT_CONFIG_FILE)
end
type = options[:output_type]
return nil unless File.exists?(conf_file)
require("yaml")
hash = YAML.load_file(conf_file)
hash['pwd'] = dir
top_dir = File.expand_path(hash['top_dir'] || ".", dir)
require("pathname")
top_path = Pathname.new(top_dir)
rel_dir = Pathname.new(dir).relative_path_from(top_path).to_s
ignore_files = if hash.has_key?("ignore_files")
ignore_files = hash["ignore_files"]
ignore_files_array = ignore_files.respond_to?(:to_a) ? ignore_files.to_a() : [ignore_files]
ignore_files_array.map { |path_arg|
begin
path_string = path_arg.to_s()
path = Pathname.new(File.expand_path(path_string))
path.relative_path_from(top_path).to_s()
rescue Exception => e
session.error(e.message() + "\n" + e.backtrace.join("\n"), type) if session
nil
end
}.compact()
else
[]
end
hash["rel_dir"] = rel_dir
hash['top_dir'] = top_dir
hash["home_dir"] = dir
hash["ignore_files"] = ignore_files
return hash
end
|