module GitThinUtils
Constants
- LOGA
- LOGC
- LOGN
- LOGNone
- LOGPRUNE
Public Instance Methods
logC(text,note = true)
click to toggle source
# File lib/git-thin/utils/utils.rb, line 126 def logC(text,note = true) if note logInner '34',"[COMMAND] #{text}" else print(text) end end
logE(text,note = true )
click to toggle source
打印不同级别的 log。根据级别不同,样式(颜色)不同
# File lib/git-thin/utils/utils.rb, line 97 def logE(text,note = true ) if note logInner '31',"[ERROR] !!#{text}" else print(text) end end
logInner(color_code,text)
click to toggle source
# File lib/git-thin/utils/utils.rb, line 90 def logInner(color_code,text) clolr="\033[#{color_code}m" nc="\033[0m" puts "#{clolr}#{text}#{nc}" end
logN(text,note = true)
click to toggle source
# File lib/git-thin/utils/utils.rb, line 118 def logN(text,note = true) if note logInner '32',"[NOTE] #{text}" else print(text) end end
logP(text)
click to toggle source
# File lib/git-thin/utils/utils.rb, line 105 def logP(text) print("\r") print(text) STDOUT.flush end
logW(text,note = true )
click to toggle source
# File lib/git-thin/utils/utils.rb, line 110 def logW(text,note = true ) if note logInner '33',"[WARNING] #{text}" else print(text) end end
print_console(str)
click to toggle source
# File lib/git-thin/utils/utils.rb, line 86 def print_console(str) run_shell "echo #{str}" end
run_shell(command,force = 0,log_type = LOGA,retryCount = 0 ) { |out_lines, error_lines,exitstatus| ... }
click to toggle source
# File lib/git-thin/utils/utils.rb, line 16 def run_shell(command,force = 0,log_type = LOGA,retryCount = 0 ) if log_type === false log_type = LOGPRUNE elsif log_type === true log_type = LOGNone end if (log_type & LOGC ) == LOGC logC command+"\n",(log_type & LOGPRUNE )!=LOGPRUNE end stdin, stdout, stderr,wait_thr = Open3.popen3(command) pid = wait_thr[:pid] out_lines = [] error_lines = [] stdout.sync = true stderr.sync = true out = Thread.new do # while !stdout.eof? # c = stdout.getc # putc c # stdout.flush # end stdout.each do |line| out_lines.push line if log_type && log_type > LOGC logN line,(log_type & LOGPRUNE )!=LOGPRUNE end end end err = Thread.new do # while !stderr.eof? # c = stderr.getc # putc c # stderr.flush # end stderr.each do |line| error_lines.push line if log_type logW line,(log_type & LOGPRUNE )!=LOGPRUNE end end end out.join err.join stderr.close stdin.close stdout.close status = wait_thr.value if status.exitstatus != 0 if !force if retryCount > 0 sleep 1 run_shell command,force,log_type,retryCount-1 return else logE error_lines,(log_type & LOGPRUNE ) exit 1 end end end unless block_given? return [out_lines,error_lines,status.exitstatus] else yield out_lines, error_lines,status.exitstatus end end
set_progress(index, char = '*')
click to toggle source
# File lib/git-thin/utils/utils.rb, line 12 def set_progress(index, char = '*') print (char * (index / 2.5).floor).ljust(40, " "), " #{index}%\r" end