Class: Pwrake::Option
- Inherits:
-
Hash
- Object
- Hash
- Pwrake::Option
- Includes:
- DefaultFileSystemOption, GfarmFileSystemOption
- Defined in:
- lib/pwrake/option/option.rb,
lib/pwrake/option/option_gfarm2fs.rb,
lib/pwrake/option/option_default_filesystem.rb
Constant Summary collapse
- DEFAULT_CONFFILES =
["pwrake_conf.yaml","PwrakeConf.yaml"]
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#host_map ⇒ Object
readonly
Returns the value of attribute host_map.
-
#queue_class ⇒ Object
readonly
Returns the value of attribute queue_class.
-
#total_cores ⇒ Object
Returns the value of attribute total_cores.
-
#worker_option ⇒ Object
readonly
Returns the value of attribute worker_option.
-
#worker_progs ⇒ Object
readonly
Returns the value of attribute worker_progs.
Instance Method Summary collapse
- #cwd_relative_if_under_home ⇒ Object
- #cwd_relative_to_home ⇒ Object
- #feedback_options ⇒ Object
- #format_time_pid(v) ⇒ Object
-
#init_filesystem ⇒ Object
———————————————————-.
-
#init_options ⇒ Object
———————————————————-.
-
#init_pass_env ⇒ Object
———————————————————-.
-
#initialize ⇒ Option
constructor
A new instance of Option.
-
#load_pwrake_conf ⇒ Object
—– init —–.
- #mount_type(d = nil) ⇒ Object
- #mountpoint_of_cwd ⇒ Object
- #option_data ⇒ Object
- #parse_opt(s) ⇒ Object
-
#put_log ⇒ Object
———————————————————-.
-
#search_opts(keys) ⇒ Object
Priority of Option: command_option > ENV > pwrake_conf > DEFAULT_OPTIONS.
-
#setup_hosts ⇒ Object
———————————————————-.
Methods included from DefaultFileSystemOption
#max_postprocess_pool, #option_data_filesystem, #postprocess, #set_filesystem_option
Methods included from GfarmFileSystemOption
#clear_gfarm2fs, #max_postprocess_pool, #option_data_filesystem, #postprocess, #set_filesystem_option
Constructor Details
#initialize ⇒ Option
Returns a new instance of Option.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pwrake/option/option.rb', line 12 def initialize load_pwrake_conf init_filesystem init_pass_env if self['SHOW_CONF'] require "yaml" YAML.dump(self,$stdout) exit elsif self['REPORT_DIR'] require 'pwrake/report' Report.new(self,[]).report_html exit end setup_hosts set_filesystem_option end |
Instance Attribute Details
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
30 31 32 |
# File 'lib/pwrake/option/option.rb', line 30 def counter @counter end |
#host_map ⇒ Object (readonly)
Returns the value of attribute host_map.
341 342 343 |
# File 'lib/pwrake/option/option.rb', line 341 def host_map @host_map end |
#queue_class ⇒ Object (readonly)
Returns the value of attribute queue_class.
69 70 71 |
# File 'lib/pwrake/option/option.rb', line 69 def queue_class @queue_class end |
#total_cores ⇒ Object
Returns the value of attribute total_cores.
31 32 33 |
# File 'lib/pwrake/option/option.rb', line 31 def total_cores @total_cores end |
#worker_option ⇒ Object (readonly)
Returns the value of attribute worker_option.
68 69 70 |
# File 'lib/pwrake/option/option.rb', line 68 def worker_option @worker_option end |
#worker_progs ⇒ Object (readonly)
Returns the value of attribute worker_progs.
67 68 69 |
# File 'lib/pwrake/option/option.rb', line 67 def worker_progs @worker_progs end |
Instance Method Details
#cwd_relative_if_under_home ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/pwrake/option/option.rb', line 288 def cwd_relative_if_under_home home = Pathname.new(ENV['HOME']).realpath path = pwd = Pathname.pwd.realpath while path != home if path.root? return pwd.to_s end path = path.parent end return pwd.relative_path_from(home).to_s end |
#cwd_relative_to_home ⇒ Object
284 285 286 |
# File 'lib/pwrake/option/option.rb', line 284 def cwd_relative_to_home Pathname.pwd.relative_path_from(Pathname.new(ENV['HOME'])).to_s end |
#feedback_options ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/pwrake/option/option.rb', line 222 def opts = Rake.application. ['DRYRUN', 'IGNORE_SYSTEM', 'IGNORE_DEPRECATE', 'LOAD_SYSTEM', 'NOSEARCH', 'RAKELIB', 'SHOW_PREREQS', 'SILENT', 'TRACE', 'BACKTRACE', 'TRACE_OUTPUT', 'TRACE_RULES' ].each do |k| if v=self[k] m = (k.downcase+"=").to_sym opts.send(m,v) end end case opts.trace_output when 'stdout' opts.trace_output = $stdout when 'stderr', nil opts.trace_output = $stderr end end |
#format_time_pid(v) ⇒ Object
218 219 220 |
# File 'lib/pwrake/option/option.rb', line 218 def format_time_pid(v) START_TIME.strftime(v).sub("%$","%05d"%Process.pid) end |
#init_filesystem ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/pwrake/option/option.rb', line 58 def init_filesystem @filesystem = Rake.application..filesystem @filesystem ||= mount_type.sub(/fuse\./,"") begin require "pwrake/option/option_#{@filesystem}" rescue LoadError require "pwrake/option/option_default_filesystem" end end |
#init_options ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pwrake/option/option.rb', line 97 def option_data.each do |a| prc = nil keys = [] case a when String keys << a when Array a.each do |x| case x when String keys << x when Proc prc = x end end end key = keys[0] val = search_opts(keys) val = prc.call(val) if prc self[key] = val if !val.nil? instance_variable_set("@"+key.downcase, val) end Rake.verbose(false) if Rake.application..silent end |
#init_pass_env ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/pwrake/option/option.rb', line 302 def init_pass_env if envs = self['PASS_ENV'] pass_env = {} case envs when Array envs.each do |k| k = k.to_s if v = ENV[k] pass_env[k] = v end end when Hash envs.each do |k,v| k = k.to_s if v = ENV[k] || v pass_env[k] = v end end else raise "invalid option for PASS_ENV in pwrake_conf.yaml" end if pass_env.empty? self.delete('PASS_ENV') else self['PASS_ENV'] = pass_env end end end |
#load_pwrake_conf ⇒ Object
—– init —–
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pwrake/option/option.rb', line 37 def load_pwrake_conf # Read pwrake_conf pwrake_conf = Rake.application..pwrake_conf if pwrake_conf if !File.exist?(pwrake_conf) raise "Configuration file not found: #{pwrake_conf}" end else pwrake_conf = DEFAULT_CONFFILES.find{|fn| File.exist?(fn)} end self['PWRAKE_CONF'] = pwrake_conf if pwrake_conf.nil? @yaml = {} else require "yaml" @yaml = open(pwrake_conf){|f| YAML.load(f) } end end |
#mount_type(d = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pwrake/option/option.rb', line 71 def mount_type(d=nil) mtab = '/etc/mtab' if File.exist?(mtab) d ||= mountpoint_of_cwd open(mtab,'r') do |f| f.each_line do |l| a = l.split if a[1] == d return a[2] end end end end nil end |
#mountpoint_of_cwd ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/pwrake/option/option.rb', line 87 def mountpoint_of_cwd d = Pathname.pwd while !d.mountpoint? d = d.parent end d.to_s end |
#option_data ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/pwrake/option/option.rb', line 126 def option_data [ 'DRYRUN', 'IGNORE_SYSTEM', 'IGNORE_DEPRECATE', 'LOAD_SYSTEM', 'NOSEARCH', 'RAKELIB', 'SHOW_PREREQS', 'SILENT', 'TRACE', 'BACKTRACE', 'TRACE_OUTPUT', 'TRACE_RULES', 'SSH_OPTION', 'PASS_ENV', 'GNU_TIME', 'DEBUG', 'PLOT_PARALLELISM', 'SHOW_CONF', ['REPORT_DIR','REPORT'], 'REPORT_IMAGE', 'FAILED_TARGET', # rename(default), delete, leave 'FAILURE_TERMINATION', # wait, kill, continue 'QUEUE_PRIORITY', # RANK(default), FIFO, LIFO, DFS 'NOACTION_QUEUE_PRIORITY', # FIFO(default), LIFO, RAND 'GRAPH_PARTITION', 'PLOT_PARTITION', ['HOSTFILE','HOSTS'], ['LOG_DIR','LOG', proc{|v| if v if v == "" || !v.kind_of?(String) v = "Pwrake%Y%m%d-%H%M%S" end d = v = format_time_pid(v) i = 1 while File.exist?(d) d = "#{v}.#{i}" i += 1 end d end }], ['LOG_FILE', proc{|v| if v.kind_of?(String) && v != "" v else "pwrake.log" end }], ['TASK_CSV_FILE', proc{|v| if v.kind_of?(String) && v != "" v else "task.csv" end }], ['COMMAND_CSV_FILE', proc{|v| if v.kind_of?(String) && v != "" v else "command.csv" end }], ['GC_LOG_FILE', proc{|v| if v if v.kind_of?(String) && v != "" v else "gc.log" end end }], ['NUM_THREADS', proc{|v| v && v.to_i}], ['SHELL_START_INTERVAL', proc{|v| (v || 0.012).to_f}], ['HEARTBEAT', proc{|v| (v || 240).to_i}], ['RETRY', proc{|v| (v || 1).to_i}], ['MASTER_HOSTNAME', proc{|v| (v || begin;`hostname -f`;rescue;end || '').chomp}], ['WORK_DIR', proc{|v| v ||= '%CWD_RELATIVE_TO_HOME' v.sub('%CWD_RELATIVE_TO_HOME',cwd_relative_if_under_home) }], ].concat(option_data_filesystem) end |
#parse_opt(s) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/pwrake/option/option.rb', line 269 def parse_opt(s) case s when /^(false|nil|off)$/i false when /^(true|on)$/i true when $stdout "stdout" when $stderr "stderr" else s end end |
#put_log ⇒ Object
345 346 347 348 349 350 351 352 |
# File 'lib/pwrake/option/option.rb', line 345 def put_log Log.info "Options:" self.each do |k,v| Log.info " #{k} = #{v.inspect}" end Log.debug "@queue_class=#{@queue_class}" Log.debug "@filesystem=#{@filesystem}" end |
#search_opts(keys) ⇒ Object
Priority of Option:
command_option > ENV > pwrake_conf > DEFAULT_OPTIONS
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/pwrake/option/option.rb', line 252 def search_opts(keys) val = Rake.application..send(keys[0].downcase.to_sym) return parse_opt(val) if !val.nil? # keys.each do |k| val = ENV[k.upcase] return parse_opt(val) if !val.nil? end # return nil if !@yaml keys.each do |k| val = @yaml[k.upcase] return val if !val.nil? end nil end |