Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: shell.rb
#
[0] Fix | Delete
# shell.rb -
[1] Fix | Delete
# $Release Version: 0.6.0 $
[2] Fix | Delete
# $Revision: 1.8 $
[3] Fix | Delete
# $Date: 2001/03/19 09:01:11 $
[4] Fix | Delete
# by Keiju ISHITSUKA(Nippon Rational Inc.)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
[11] Fix | Delete
require "e2mmap"
[12] Fix | Delete
require "thread"
[13] Fix | Delete
[14] Fix | Delete
require "shell/error"
[15] Fix | Delete
require "shell/command-processor"
[16] Fix | Delete
require "shell/process-controller"
[17] Fix | Delete
[18] Fix | Delete
class Shell
[19] Fix | Delete
@RCS_ID='-$Id: shell.rb,v 1.8 2001/03/19 09:01:11 keiju Exp keiju $-'
[20] Fix | Delete
[21] Fix | Delete
include Error
[22] Fix | Delete
extend Exception2MessageMapper
[23] Fix | Delete
[24] Fix | Delete
# @cascade = true
[25] Fix | Delete
# debug: true -> normal debug
[26] Fix | Delete
# debug: 1 -> eval definition debug
[27] Fix | Delete
# debug: 2 -> detail inspect debug
[28] Fix | Delete
@debug = false
[29] Fix | Delete
@verbose = true
[30] Fix | Delete
[31] Fix | Delete
class << Shell
[32] Fix | Delete
attr :cascade, true
[33] Fix | Delete
attr :debug, true
[34] Fix | Delete
attr :verbose, true
[35] Fix | Delete
[36] Fix | Delete
# alias cascade? cascade
[37] Fix | Delete
alias debug? debug
[38] Fix | Delete
alias verbose? verbose
[39] Fix | Delete
@verbose = true
[40] Fix | Delete
[41] Fix | Delete
def debug=(val)
[42] Fix | Delete
@debug = val
[43] Fix | Delete
@verbose = val if val
[44] Fix | Delete
end
[45] Fix | Delete
[46] Fix | Delete
def cd(path)
[47] Fix | Delete
sh = new
[48] Fix | Delete
sh.cd path
[49] Fix | Delete
sh
[50] Fix | Delete
end
[51] Fix | Delete
[52] Fix | Delete
def default_system_path
[53] Fix | Delete
if @default_system_path
[54] Fix | Delete
@default_system_path
[55] Fix | Delete
else
[56] Fix | Delete
ENV["PATH"].split(":")
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
def default_system_path=(path)
[61] Fix | Delete
@default_system_path = path
[62] Fix | Delete
end
[63] Fix | Delete
[64] Fix | Delete
def default_record_separator
[65] Fix | Delete
if @default_record_separator
[66] Fix | Delete
@default_record_separator
[67] Fix | Delete
else
[68] Fix | Delete
$/
[69] Fix | Delete
end
[70] Fix | Delete
end
[71] Fix | Delete
[72] Fix | Delete
def default_record_separator=(rs)
[73] Fix | Delete
@default_record_separator = rs
[74] Fix | Delete
end
[75] Fix | Delete
end
[76] Fix | Delete
[77] Fix | Delete
def initialize
[78] Fix | Delete
@cwd = Dir.pwd
[79] Fix | Delete
@dir_stack = []
[80] Fix | Delete
@umask = nil
[81] Fix | Delete
[82] Fix | Delete
@system_path = Shell.default_system_path
[83] Fix | Delete
@record_separator = Shell.default_record_separator
[84] Fix | Delete
[85] Fix | Delete
@command_processor = CommandProcessor.new(self)
[86] Fix | Delete
@process_controller = ProcessController.new(self)
[87] Fix | Delete
[88] Fix | Delete
@verbose = Shell.verbose
[89] Fix | Delete
@debug = Shell.debug
[90] Fix | Delete
end
[91] Fix | Delete
[92] Fix | Delete
attr_reader :system_path
[93] Fix | Delete
[94] Fix | Delete
def system_path=(path)
[95] Fix | Delete
@system_path = path
[96] Fix | Delete
rehash
[97] Fix | Delete
end
[98] Fix | Delete
[99] Fix | Delete
attr :umask, true
[100] Fix | Delete
attr :record_separator, true
[101] Fix | Delete
[102] Fix | Delete
attr :verbose, true
[103] Fix | Delete
attr :debug, true
[104] Fix | Delete
[105] Fix | Delete
def debug=(val)
[106] Fix | Delete
@debug = val
[107] Fix | Delete
@verbose = val if val
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
alias verbose? verbose
[111] Fix | Delete
alias debug? debug
[112] Fix | Delete
[113] Fix | Delete
attr_reader :command_processor
[114] Fix | Delete
attr_reader :process_controller
[115] Fix | Delete
[116] Fix | Delete
def expand_path(path)
[117] Fix | Delete
File.expand_path(path, @cwd)
[118] Fix | Delete
end
[119] Fix | Delete
[120] Fix | Delete
# Most Shell commands are defined via CommandProcessor
[121] Fix | Delete
[122] Fix | Delete
#
[123] Fix | Delete
# Dir related methods
[124] Fix | Delete
#
[125] Fix | Delete
# Shell#cwd/dir/getwd/pwd
[126] Fix | Delete
# Shell#chdir/cd
[127] Fix | Delete
# Shell#pushdir/pushd
[128] Fix | Delete
# Shell#popdir/popd
[129] Fix | Delete
# Shell#mkdir
[130] Fix | Delete
# Shell#rmdir
[131] Fix | Delete
[132] Fix | Delete
attr :cwd
[133] Fix | Delete
alias dir cwd
[134] Fix | Delete
alias getwd cwd
[135] Fix | Delete
alias pwd cwd
[136] Fix | Delete
[137] Fix | Delete
attr :dir_stack
[138] Fix | Delete
alias dirs dir_stack
[139] Fix | Delete
[140] Fix | Delete
# If called as iterator, it restores the current directory when the
[141] Fix | Delete
# block ends.
[142] Fix | Delete
def chdir(path = nil)
[143] Fix | Delete
if iterator?
[144] Fix | Delete
cwd_old = @cwd
[145] Fix | Delete
begin
[146] Fix | Delete
chdir(path)
[147] Fix | Delete
yield
[148] Fix | Delete
ensure
[149] Fix | Delete
chdir(cwd_old)
[150] Fix | Delete
end
[151] Fix | Delete
else
[152] Fix | Delete
path = "~" unless path
[153] Fix | Delete
@cwd = expand_path(path)
[154] Fix | Delete
notify "current dir: #{@cwd}"
[155] Fix | Delete
rehash
[156] Fix | Delete
self
[157] Fix | Delete
end
[158] Fix | Delete
end
[159] Fix | Delete
alias cd chdir
[160] Fix | Delete
[161] Fix | Delete
def pushdir(path = nil)
[162] Fix | Delete
if iterator?
[163] Fix | Delete
pushdir(path)
[164] Fix | Delete
begin
[165] Fix | Delete
yield
[166] Fix | Delete
ensure
[167] Fix | Delete
popdir
[168] Fix | Delete
end
[169] Fix | Delete
elsif path
[170] Fix | Delete
@dir_stack.push @cwd
[171] Fix | Delete
chdir path
[172] Fix | Delete
notify "dir stack: [#{@dir_stack.join ', '}]"
[173] Fix | Delete
self
[174] Fix | Delete
else
[175] Fix | Delete
if pop = @dir_stack.pop
[176] Fix | Delete
@dir_stack.push @cwd
[177] Fix | Delete
chdir pop
[178] Fix | Delete
notify "dir stack: [#{@dir_stack.join ', '}]"
[179] Fix | Delete
self
[180] Fix | Delete
else
[181] Fix | Delete
Shell.Fail DirStackEmpty
[182] Fix | Delete
end
[183] Fix | Delete
end
[184] Fix | Delete
end
[185] Fix | Delete
alias pushd pushdir
[186] Fix | Delete
[187] Fix | Delete
def popdir
[188] Fix | Delete
if pop = @dir_stack.pop
[189] Fix | Delete
chdir pop
[190] Fix | Delete
notify "dir stack: [#{@dir_stack.join ', '}]"
[191] Fix | Delete
self
[192] Fix | Delete
else
[193] Fix | Delete
Shell.Fail DirStackEmpty
[194] Fix | Delete
end
[195] Fix | Delete
end
[196] Fix | Delete
alias popd popdir
[197] Fix | Delete
[198] Fix | Delete
[199] Fix | Delete
#
[200] Fix | Delete
# process management
[201] Fix | Delete
#
[202] Fix | Delete
def jobs
[203] Fix | Delete
@process_controller.jobs
[204] Fix | Delete
end
[205] Fix | Delete
[206] Fix | Delete
def kill(sig, command)
[207] Fix | Delete
@process_controller.kill_job(sig, command)
[208] Fix | Delete
end
[209] Fix | Delete
[210] Fix | Delete
#
[211] Fix | Delete
# command definitions
[212] Fix | Delete
#
[213] Fix | Delete
def Shell.def_system_command(command, path = command)
[214] Fix | Delete
CommandProcessor.def_system_command(command, path)
[215] Fix | Delete
end
[216] Fix | Delete
[217] Fix | Delete
def Shell.undef_system_command(command)
[218] Fix | Delete
CommandProcessor.undef_system_command(command)
[219] Fix | Delete
end
[220] Fix | Delete
[221] Fix | Delete
def Shell.alias_command(ali, command, *opts, &block)
[222] Fix | Delete
CommandProcessor.alias_command(ali, command, *opts, &block)
[223] Fix | Delete
end
[224] Fix | Delete
[225] Fix | Delete
def Shell.unalias_command(ali)
[226] Fix | Delete
CommandProcessor.unalias_command(ali)
[227] Fix | Delete
end
[228] Fix | Delete
[229] Fix | Delete
def Shell.install_system_commands(pre = "sys_")
[230] Fix | Delete
CommandProcessor.install_system_commands(pre)
[231] Fix | Delete
end
[232] Fix | Delete
[233] Fix | Delete
#
[234] Fix | Delete
def inspect
[235] Fix | Delete
if debug.kind_of?(Integer) && debug > 2
[236] Fix | Delete
super
[237] Fix | Delete
else
[238] Fix | Delete
to_s
[239] Fix | Delete
end
[240] Fix | Delete
end
[241] Fix | Delete
[242] Fix | Delete
def self.notify(*opts, &block)
[243] Fix | Delete
Thread.exclusive do
[244] Fix | Delete
if opts[-1].kind_of?(String)
[245] Fix | Delete
yorn = verbose?
[246] Fix | Delete
else
[247] Fix | Delete
yorn = opts.pop
[248] Fix | Delete
end
[249] Fix | Delete
return unless yorn
[250] Fix | Delete
[251] Fix | Delete
_head = true
[252] Fix | Delete
print opts.collect{|mes|
[253] Fix | Delete
mes = mes.dup
[254] Fix | Delete
yield mes if iterator?
[255] Fix | Delete
if _head
[256] Fix | Delete
_head = false
[257] Fix | Delete
"shell: " + mes
[258] Fix | Delete
else
[259] Fix | Delete
" " + mes
[260] Fix | Delete
end
[261] Fix | Delete
}.join("\n")+"\n"
[262] Fix | Delete
end
[263] Fix | Delete
end
[264] Fix | Delete
[265] Fix | Delete
CommandProcessor.initialize
[266] Fix | Delete
CommandProcessor.run_config
[267] Fix | Delete
end
[268] Fix | Delete
[269] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function