Class: Fairy::BaseAPP

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy/share/base-app.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseAPP

Returns a new instance of BaseAPP.



26
27
28
29
30
# File 'lib/fairy/share/base-app.rb', line 26

def initialize
  @home = nil
  @conf = nil
  @CONF = {}
end

Class Method Details

.startObject



9
10
11
12
13
14
15
# File 'lib/fairy/share/base-app.rb', line 9

def self.start
  @@APP = new
  @@APP.parse_arg
  @@APP.load_conf
  @@APP.configure_conf
  @@APP.start
end

.start_subcommand(prog, *opts) ⇒ Object



17
18
19
# File 'lib/fairy/share/base-app.rb', line 17

def self.start_subcommand(prog, *opts)
  @@APP.start_subcommand(prog, *opts)
end

.start_subcommand2(prog, *opts) ⇒ Object



20
21
22
23
24
# File 'lib/fairy/share/base-app.rb', line 20

def self.start_subcommand2(prog, *opts)
  Process.fork do
	start_subcommand(prog, *opts)
  end
end

Instance Method Details

#conf_to_argObject



50
51
52
# File 'lib/fairy/share/base-app.rb', line 50

def conf_to_arg
  @CONF.collect{|prop, source| "--CONF.#{prop}=#{source}"}
end

#configure_confObject



84
85
86
# File 'lib/fairy/share/base-app.rb', line 84

def configure_conf
  Conf.configure_common_conf
end

#load_confObject



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
# File 'lib/fairy/share/base-app.rb', line 54

def load_conf
  if @home
	ENV["FAIRY_HOME"] = @home
#	ENV["FAIRY_HOME"] = File.expand_path(@home)
	conf = @home+"/etc/fairy.conf"
	if File.exists?(conf)
	  CONF.load_conf conf
	end
  end
	
  if @conf
	ENV["FAIRY_CONF"] = @conf
	CONF.load_conf @conf
  end

  @CONF.each do |key, value|
	begin
	  eval "CONF.#{key}=#{value}"
	rescue
	  puts "CONF.#{key}=#{value} が不正です."
	  exit 1
	end
  end
  if  ENV["RUBYLIB"]
	ENV["RUBYLIB"] = CONF.LIB + ":" + ENV["RUBYLIB"]
  else
	ENV["RUBYLIB"] = CONF.LIB
  end
end

#option_parserObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fairy/share/base-app.rb', line 37

def option_parser
  opt = OptionParser.new{|opt|
	opt.on("--home=VAL"){|val| @home = val}
	opt.on("--conf=VAL"){|val| @conf = val}
	CONF.props.each do |prop|
	  opt.on("--CONF.#{prop}=VAL") {|val| @CONF[prop] = val}
	end
  }
  if block_given?
	yield opt
  end
end

#parse_argObject



32
33
34
35
# File 'lib/fairy/share/base-app.rb', line 32

def parse_arg
  @opt = option_parser
  @opt.order!(ARGV)
end

#startObject



88
89
90
# File 'lib/fairy/share/base-app.rb', line 88

def start
  ERR::Raise ERR::INTERNAL::ShouldDefineSubclass
end

#start_subcommand(prog, *opts) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fairy/share/base-app.rb', line 92

def start_subcommand(prog, *opts)
  opts.push *conf_to_arg
#       Process.fork do
# 	Log.stop_export
# 	ObjectSpace.each_object(IO) do |io|
# 	  begin
# 	    if ![0, 1, 2].include?(io.fileno )
# 	      io.close
# 	    end
# 	  rescue
# 	  end
# 	end
# 	exec(prog, *opts)
#       end

  Process.spawn(prog, *opts)
#      system("#{prog} #{opts.join(' ')}&")

end