Module: MCMD

Defined in:
lib/nysol/margs.rb,
lib/nysol/mtemp.rb,
lib/nysol/mutils.rb,
lib/nysol/mnettools.rb,
lib/nysol/mrubyparse.rb,
lib/nysol/msysteminfo.rb,
lib/nysol/mparallelmanager.rb,
ext/mcsvin/mcsvin.cpp,
ext/mtable/mtable.cpp,
ext/mcsvout/mcsvout.cpp,
ext/mmethods/mmethods.cpp

Overview

vm_stat output

Mach Virtual Memory Statistics: (page size of 4096 bytes) Pages free: 640719. Pages active: 550274. Pages inactive: 246385. Pages speculative: 140973. Pages throttled: 0. Pages wired down: 518097. Pages purgeable: 32227. “Translation faults”: 5375781. Pages copy-on-write: 220656. Pages zero filled: 3602918. Pages reactivated: 2. Pages purged: 0. File-backed pages: 350402. Anonymous pages: 587230. Pages stored in compressor: 0. Pages occupied by compressor: 0. Decompressions: 0. Compressions: 0. Pageins: 138994. Pageouts: 0. Swapins: 0. Swapouts: 0.

Pages freeの行をメモリ空きとする

Defined Under Namespace

Modules: NetTools, SysInfo Classes: Margs, Mcsvin, Mcsvout, MparallelManager, MparallelManagerByFile, MpcManager, MrubyParse, Mtable, Mtemp

Class Method Summary collapse

Class Method Details

.chkCmdExe(cmd, type, arg1 = nil) ⇒ Object

コマンド実行チェック 実行可能ならtrue else false



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/nysol/mutils.rb', line 117

def MCMD::chkCmdExe(cmd,type,arg1=nil)
	ret=true
	if(type=="executable")
		system "#{cmd} 2>/dev/null"
		if($?.exitstatus==127)
			MCMD::errorLog("command not found (type=#{type}): '#{cmd}'.")
			ret=false
		end
	elsif(type=="wc")
		log=`#{cmd} #{type} 2>&1`
		if log.chomp.size()<arg1
 			MCMD::errorLog("command not found (type=#{type}): '#{cmd}'.")
			ret=false
		end
	else
		log=`#{cmd} #{type} 2>&1`
		if log.chomp!=arg1
 			MCMD::errorLog("command version mismatch: '#{cmd}': needs '#{arg1}', but '#{log}.")
			ret=false
		end
	end

	return ret
end

.chkRexe(libs) ⇒ Object

rの実行チェックとr ライブラリのインストールチェック



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
# File 'lib/nysol/mutils.rb', line 143

def MCMD::chkRexe(libs)
	log=`R --version 2>&1`
	if log.chomp.size()<100
		MCMD::errorLog("R is not installed.")
		return false
	end

	libStr=""
	libs.split(",").each{|lib|
		libStr << "p=packageVersion(\"#{lib}\")\n"
	}

	wf=MCMD::Mtemp.new
	xxscp=wf.file
	File.open(xxscp,"w"){|fpw|
		fpw.puts <<EOF
		tryCatch({
			#{libStr}
		},
		error=function(e){
 			message(e)
			quit(save="no", status=1)
		})
		quit(save="no", status=0)
EOF
	}				

	# it will be aborted here if the library is not found
	ret=system "R -q --vanilla --slave --no-save --no-restore < #{xxscp}"
	unless ret
		puts "\n"
		MCMD::errorLog("R package shown above is not installed.")
	end

	# return true if nothing happened
	return ret
end

.endLog(msg = "") ⇒ Object



85
86
87
88
89
90
# File 'lib/nysol/mutils.rb', line 85

def MCMD::endLog(msg="")
	vbl=ENV["KG_ScpVerboseLevel"]
	if(not vbl or vbl.to_i>=3) then
		STDERR.puts "#END# #{msg}; #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}"
	end
end

.errorLog(msg = "") ⇒ Object



71
72
73
74
75
76
# File 'lib/nysol/mutils.rb', line 71

def MCMD::errorLog(msg="")
	vbl=ENV["KG_ScpVerboseLevel"]
	if(not vbl or vbl.to_i>=1) then
		STDERR.puts "#ERROR# #{msg}; #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}"
	end
end

.mcat(fName, oFile) ⇒ Object

mcat i=のファイル名文字列がbashの位置行文字数制限(たぶん1024くらい?)に引っかかるのを回避するmcat date,noが指定されれば、date,no以前のデータをmcatし、oFileに出力する。 マッチしたファイル名配列を返す。



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
# File 'lib/nysol/mutils.rb', line 184

def MCMD::mcat(fName,oFile)
	files=[]
	if fName.class.name=="Array"
		fName.each{|name|
			files.concat(Dir["#{name}"])
		}
	else
		files=Dir["#{fName}"]
	end

	wf=MCMD::Mtemp.new
	xxbase=wf.file
	xxbaseX=wf.file

	split=20
	collect_path =[]
	(0...files.size).each{|i|
		if i==0
			system("cp #{files[0]} #{xxbase}")
			next
		end
		collect_path << "#{files[i]}"
		if i%split == 0 or i==files.size-1 then
			system("mcat i=#{xxbase},#{collect_path.join(",")} -skip_fnf o=#{xxbaseX}")
			system("cp #{xxbaseX} #{xxbase}")
			collect_path = []
		end
	}
	system("cp #{xxbase} #{oFile}") if files.size>0

	return files
end

.mkDir(path, rm = false) ⇒ Object

ディレクトリの作成



104
105
106
107
108
109
110
111
112
113
# File 'lib/nysol/mutils.rb', line 104

def MCMD::mkDir(path,rm=false)
	if File.exist?(path)
		if rm
			FileUtils.rm_rf(path) if rm
			FileUtils.mkdir_p(path)
		end
	else
		FileUtils.mkdir_p(path)
	end
end

.msgLog(msg = "", time = true, header = true) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/nysol/mutils.rb', line 92

def MCMD::msgLog(msg="",time=true,header=true)
	vbl=ENV["KG_ScpVerboseLevel"]
	if(not vbl or vbl.to_i>=4) then
		str=""
		str << "#MSG# " if header
		str << msg
		str << "; #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}" if time
		STDERR.puts str
	end
end

.outputblk(inf, lin, outf, kwd, values = []) ⇒ Object

inf:ソースファイル , lin:読み込み開始業 out:出力ファイル名 kwd:m2each,出力するローカル変数



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/nysol/mrubyparse.rb', line 283

def MCMD::outputblk(inf,lin,outf,kwd,values=[])

	
	s_char_ex = ["\\s+class\\s+|^class\\s+|\\s+class$|^class$",
							"\\s+module\\s+|^module\\s+|\\s+module$|^module$",
							"\\s+if\\s+|^if\\s+|\\s+if$|^if$",
							"\\s+def\\s+|^def\\s+|\\s+def$|^def$" ]
	e_char_ex = ["\\s+end\\s+|^end\\s+|\\s+end\.|^end\.|\\s+end$|^end$"]


	s_char = ["\\s*{\\s*","\\s+do\\s+|^do\\s+|\\s+do$|^do$" ]
	e_char = ["\\s*}\\s*","\\s+end\\s+|^end\\s+|\\s+end\.|^end\.|\\s+end$|^end$"]
	regpos = 0
	nowL=0
	start = false
	arg   = false
	arg_s   = false
	blk_e   = false
	s_ch_cnt= 0
	e_ch_cnt= 0
	oscript = "" 
	args=[]
	reqiureinfo=[]
	afterinfo=[]
	stcnt_ex =0
	edcnt_ex =0
	outF=false
	reccnt=0
	#開始行kwdの位置を決定してその後ブロックを抜き出す
	File.open(outf,"w"){|ofp|
	File.open(inf,"r"){|ifp|
		while ldata = ifp.gets do
			nowL+=1
			if nowL	< lin then
				if ldata =~ /^\s*require\s|^\s*#/
					reqiureinfo << ldata 
					reccnt +=1
					next
				end
				ofset_e=0
				out_e=""
				loop {
					pos_e = ldata.index(/(#{s_char_ex.join('|')}|#{e_char_ex[0]})/,ofset_e)
					if pos_e != nil then
						while pos_e < ldata.length do 
							break unless ldata[pos_e].match(/\s/)
							pos_e+=1
						end
						case ldata[pos_e]
						when "c" then
							pos_e+=5
							stcnt_ex+=1
							outF = true
							out_e << ldata[0...pos_e] if outF
						when "m" then
							pos_e+=6
							stcnt_ex+=1
							outF = true
							out_e << ldata[0...pos_e] if outF
						when "d" then
							pos_e+=3
							stcnt_ex+=1
							outF = true
							out_e << ldata[0...pos_e] if outF
						when "i" then
							## 後ろif(空白以外あり)
							if ldata[0...pos_e].index(/\S/) != nil then
								pos_e+=2
								out_e << ldata[0...pos_e]	if outF
							else
								pos_e+=2
								out_e << ldata[0...pos_e]	if outF	
								stcnt_ex+=1							
							end
							
						when "e" then
							pos_e+=3
							edcnt_ex+=1
							out_e << ldata[0...pos_e] if outF
							outF = false if stcnt_ex == edcnt_ex
							
						end
					else
						out_e << ldata if outF
						reqiureinfo << out_e 
						reccnt +=1
						reccnt =0 if stcnt_ex == edcnt_ex
						break
					end
					ldata=ldata[pos_e..-1]
				}
				next
			end
			# 開始チェック
			unless start  then
				# start 位置 "v1".m2each"v2" "v3"
				sp = ldata.match(/(.*)#{kwd}(#{s_char[0]}|#{s_char[1]})(.*)/)
				sp = ldata.match(/(.*)#{kwd}\s*\(.*\)\s*(#{s_char[0]}|#{s_char[1]})(.*)/) if sp == nil
				regpos = 1 if sp[2].include?("do")
				ldata = sp[3]
				start = true 
				outF =false
				s_ch_cnt+=1
				reccnt.times{ reqiureinfo.pop }
				reqiureinfo.each{|ld| ofp.puts(ld) }
				values.each{|ld| ofp.puts(ld) }
			end 
			# argsチェック
			unless arg then
				ldata.lstrip!
				next if ldata.length == 0 
				unless arg_s then
					raise "format error" if ldata[0]!="|"
					ldata = ldata[1..-1]
					arg_s =true
				end
				pos=0
				out =""
				while pos < ldata.length do 
					case ldata[pos]
					when ","
						args << out
						out =""	
					when "|"
						args << out
						out =""	
						arg = true
						pos += 1
						break
					else
						out << ldata[pos]
					end
					pos += 1
				end
				next unless arg
				ldata =ldata[pos..-1]
				args.each_with_index{|d,i|
					if i==0 then
						ofp.puts("#{d} = ARGV[#{i}].split(',')")
						ofp.puts("#{d} = #{d}[0] if #{d}.size==1")

					else 
						ofp.puts("#{d} = ARGV[#{i}].to_i")						
					end
				}
			end
			unless blk_e then
				offset=0
				out =""
				loop {
					pos = ldata.index(/#{s_char[regpos]}|#{e_char[regpos]}/,offset)
					if pos == nil then
						out = ldata
						break	
					end
					while pos < ldata.length do 
						break unless ldata[pos].match(/\s/)
						pos+=1
					end
					case ldata[pos]
					when "d" then
						s_ch_cnt+= 1	
						offset = pos+2
					when "e" then
						e_ch_cnt+= 1
						offset = pos+3			
					when "{" then
						s_ch_cnt+= 1
						offset = pos+1
					when "}" then
						e_ch_cnt+= 1						
						offset = pos+1
					end
					if s_ch_cnt == e_ch_cnt then
						out = ldata[0...pos]
						ldata =ldata[pos..-1]
						break
					end
				}
				ofp.puts out
				blk_e = true if s_ch_cnt == e_ch_cnt
				next unless blk_e					
			end
			# block以降
			if ldata =~ /^\s*require\s|^\s*#/
				afterinfo << ldata 
				reccnt +=1
				next
			end
			ofset_e=0
			out_e=""
			loop {
				pos_e = ldata.index(/(#{s_char_ex.join('|')}|#{e_char_ex[0]})/,ofset_e)
				if pos_e != nil then
					while pos_e < ldata.length do 
						break unless ldata[pos_e].match(/\s/)
						pos_e+=1
					end
					case ldata[pos_e]
						when "c" then
							pos_e+=5
							stcnt_ex+=1
							out_e << ldata[0...pos_e] if outF
						when "m" then
							pos_e+=6
							stcnt_ex+=1
							out_e << ldata[0...pos_e] if outF
						when "d" then
							pos_e+=3
							stcnt_ex+=1
							out_e << ldata[0...pos_e] if outF
						when "i" then
							## 後ろif(空白以外あり)
							if ldata[0...pos_e].index(/\S/) != nil then
								pos_e+=2
								out_e << ldata[0...pos_e]	if outF
							else
								pos_e+=2
								out_e << ldata[0...pos_e]	if outF
								stcnt_ex+=1							
							end
							
						when "e" then
							pos_e+=3
							edcnt_ex+=1
							out_e << ldata[0...pos_e] if outF
							outF = false if stcnt_ex == edcnt_ex
							
						end
					else
						out_e << ldata if stcnt_ex != edcnt_ex &&  outF
						afterinfo << out_e 
						reccnt +=1
						reccnt =0 if stcnt_ex == edcnt_ex
						break
					end
					ldata=ldata[pos_e..-1]
			}
		end
		afterinfo.each{|ld| ofp.puts(ld) }
	}
	}

end

.warningLog(msg = "") ⇒ Object



78
79
80
81
82
83
# File 'lib/nysol/mutils.rb', line 78

def MCMD::warningLog(msg="")
	vbl=ENV["KG_ScpVerboseLevel"]
	if(not vbl or vbl.to_i>=2) then
		STDERR.puts "#WARNING# #{msg}; #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}"
	end
end