Use class methods of File
over Kernel.open
and IO.read
This commit is contained in:
parent
a0b0365e90
commit
d752cf7601
Notes:
git
2022-11-30 17:29:08 +00:00
@ -49,7 +49,7 @@ at_exit do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
open(cfile, "w") do |out|
|
File.open(cfile, "w") do |out|
|
||||||
covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx|
|
covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx|
|
||||||
cov += pcov || 0 if cov
|
cov += pcov || 0 if cov
|
||||||
cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9)
|
cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9)
|
||||||
|
@ -62,7 +62,7 @@ def from_main
|
|||||||
if File.exist?(file)
|
if File.exist?(file)
|
||||||
atime = File.atime(file)
|
atime = File.atime(file)
|
||||||
mtime = File.mtime(file)
|
mtime = File.mtime(file)
|
||||||
open(file, "r") do |f|
|
File.open(file, "r") do |f|
|
||||||
until f.eof?
|
until f.eof?
|
||||||
header = {}
|
header = {}
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
|
@ -2,11 +2,29 @@
|
|||||||
# split into multi part
|
# split into multi part
|
||||||
# usage: mpart.rb [-nnn] file..
|
# usage: mpart.rb [-nnn] file..
|
||||||
|
|
||||||
|
class MPart < File
|
||||||
|
def self.new(basename, extname, part, parts)
|
||||||
|
super(sprintf("%s.%s%02d", basename, extname, part), "w").
|
||||||
|
begin_mpart(basename, part, parts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def begin_mpart(basename, part, parts)
|
||||||
|
printf("%s part%02d/%02d\n", basename, part, parts)
|
||||||
|
write("BEGIN--cut here--cut here\n")
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
write("END--cut here--cut here\n")
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
lines = 1000
|
lines = 1000
|
||||||
|
|
||||||
if (ARGV[0] =~ /^-(\d+)$/ )
|
if (ARGV[0] =~ /^-(\d+)$/ )
|
||||||
lines = $1.to_i;
|
lines = $1.to_i
|
||||||
ARGV.shift;
|
ARGV.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
basename = ARGV[0]
|
basename = ARGV[0]
|
||||||
@ -14,31 +32,23 @@ extname = "part"
|
|||||||
|
|
||||||
part = 1
|
part = 1
|
||||||
line = 0
|
line = 0
|
||||||
|
ofp = nil
|
||||||
|
|
||||||
fline = 0
|
fline = 0
|
||||||
for i in ifp = open(basename)
|
File.foreach(basename) {fline += 1}
|
||||||
fline = fline + 1
|
|
||||||
end
|
|
||||||
ifp.close
|
|
||||||
|
|
||||||
parts = fline / lines + 1
|
parts = fline / lines + 1
|
||||||
|
|
||||||
for i in ifp = open(basename)
|
File.foreach(basename) do |i|
|
||||||
if line == 0
|
if line == 0
|
||||||
ofp = open(sprintf("%s.%s%02d", basename, extname, part), "w")
|
ofp = MPart.new(basename, extname, part, parts)
|
||||||
printf(ofp, "%s part%02d/%02d\n", basename, part, parts)
|
|
||||||
ofp.write("BEGIN--cut here--cut here\n")
|
|
||||||
end
|
end
|
||||||
ofp.write(i)
|
ofp.write(i)
|
||||||
line = line + 1
|
line += 1
|
||||||
if line >= lines and !ifp.eof?
|
if line >= lines
|
||||||
ofp.write("END--cut here--cut here\n")
|
|
||||||
ofp.close
|
ofp.close
|
||||||
part = part + 1
|
part += 1
|
||||||
line = 0
|
line = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ofp.write("END--cut here--cut here\n")
|
|
||||||
ofp.close
|
ofp.close
|
||||||
|
|
||||||
ifp.close
|
|
||||||
|
@ -15,7 +15,7 @@ while line = gets()
|
|||||||
if out_stdout
|
if out_stdout
|
||||||
out = STDOUT
|
out = STDOUT
|
||||||
else
|
else
|
||||||
out = open($file, "w") if $file != ""
|
out = File.open($file, "w") if $file != ""
|
||||||
end
|
end
|
||||||
out.binmode
|
out.binmode
|
||||||
break
|
break
|
||||||
|
@ -729,7 +729,7 @@ module Test
|
|||||||
return result
|
return result
|
||||||
ensure
|
ensure
|
||||||
if file = @options[:timetable_data]
|
if file = @options[:timetable_data]
|
||||||
open(file, 'w'){|f|
|
File.open(file, 'w'){|f|
|
||||||
@records.each{|(worker, suite), (st, ed)|
|
@records.each{|(worker, suite), (st, ed)|
|
||||||
f.puts '[' + [worker.dump, suite.dump, st.to_f * 1_000, ed.to_f * 1_000].join(", ") + '],'
|
f.puts '[' + [worker.dump, suite.dump, st.to_f * 1_000, ed.to_f * 1_000].join(", ") + '],'
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ module WEBrick
|
|||||||
def load_mime_types(file)
|
def load_mime_types(file)
|
||||||
# note: +file+ may be a "| command" for now; some people may
|
# note: +file+ may be a "| command" for now; some people may
|
||||||
# rely on this, but currently we do not use this method by default.
|
# rely on this, but currently we do not use this method by default.
|
||||||
open(file){ |io|
|
File.open(file){ |io|
|
||||||
hash = Hash.new
|
hash = Hash.new
|
||||||
io.each{ |line|
|
io.each{ |line|
|
||||||
next if /^#/ =~ line
|
next if /^#/ =~ line
|
||||||
|
@ -276,10 +276,10 @@ def mk_builtin_header file
|
|||||||
collect_builtin(base, Ripper.sexp(code), 'top', bs = {}, inlines = {})
|
collect_builtin(base, Ripper.sexp(code), 'top', bs = {}, inlines = {})
|
||||||
|
|
||||||
begin
|
begin
|
||||||
f = open(ofile, 'w')
|
f = File.open(ofile, 'w')
|
||||||
rescue Errno::EACCES
|
rescue SystemCallError # EACCES, EPERM, EROFS, etc.
|
||||||
# Fall back to the current directory
|
# Fall back to the current directory
|
||||||
f = open(File.basename(ofile), 'w')
|
f = File.open(File.basename(ofile), 'w')
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
if File::ALT_SEPARATOR
|
if File::ALT_SEPARATOR
|
||||||
|
@ -85,12 +85,12 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
|
|||||||
"Content-Type: text/plain\r\n" \
|
"Content-Type: text/plain\r\n" \
|
||||||
"Content-Range: bytes 0-0/#{filesize}\r\n" \
|
"Content-Range: bytes 0-0/#{filesize}\r\n" \
|
||||||
"\r\n" \
|
"\r\n" \
|
||||||
"#{IO.read(__FILE__, 1)}\r\n" \
|
"#{File.read(__FILE__, 1)}\r\n" \
|
||||||
"--#{boundary}\r\n" \
|
"--#{boundary}\r\n" \
|
||||||
"Content-Type: text/plain\r\n" \
|
"Content-Type: text/plain\r\n" \
|
||||||
"Content-Range: bytes #{off}-#{last}/#{filesize}\r\n" \
|
"Content-Range: bytes #{off}-#{last}/#{filesize}\r\n" \
|
||||||
"\r\n" \
|
"\r\n" \
|
||||||
"#{IO.read(__FILE__, 2, off)}\r\n" \
|
"#{File.read(__FILE__, 2, off)}\r\n" \
|
||||||
"--#{boundary}--\r\n"
|
"--#{boundary}--\r\n"
|
||||||
assert_equal exp, body
|
assert_equal exp, body
|
||||||
end
|
end
|
||||||
|
@ -245,7 +245,7 @@ GET /
|
|||||||
|
|
||||||
_end_of_message_
|
_end_of_message_
|
||||||
msg.gsub!(/^ {6}/, "")
|
msg.gsub!(/^ {6}/, "")
|
||||||
open(__FILE__){|io|
|
File.open(__FILE__){|io|
|
||||||
while chunk = io.read(100)
|
while chunk = io.read(100)
|
||||||
msg << chunk.size.to_s(16) << crlf
|
msg << chunk.size.to_s(16) << crlf
|
||||||
msg << chunk << crlf
|
msg << chunk << crlf
|
||||||
|
@ -725,7 +725,7 @@ def citrus_decode_mapsrc(ces, csid, mapsrcs)
|
|||||||
path << ".src"
|
path << ".src"
|
||||||
path[path.rindex('/')] = '%'
|
path[path.rindex('/')] = '%'
|
||||||
STDOUT.puts 'load mapsrc %s' % path if VERBOSE_MODE > 1
|
STDOUT.puts 'load mapsrc %s' % path if VERBOSE_MODE > 1
|
||||||
open(path, 'rb') do |f|
|
File.open(path, 'rb') do |f|
|
||||||
f.each_line do |l|
|
f.each_line do |l|
|
||||||
break if /^BEGIN_MAP/ =~ l
|
break if /^BEGIN_MAP/ =~ l
|
||||||
end
|
end
|
||||||
|
@ -53,7 +53,7 @@ end
|
|||||||
[$so_name, '.dll', 'VFT_DLL', 'DLL', dll_icons.join],
|
[$so_name, '.dll', 'VFT_DLL', 'DLL', dll_icons.join],
|
||||||
].each do |base, ext, type, desc, icon|
|
].each do |base, ext, type, desc, icon|
|
||||||
next if $output and $output != base
|
next if $output and $output != base
|
||||||
open(base + '.rc', "w") { |f|
|
File.open(base + '.rc', "w") { |f|
|
||||||
f.binmode if /mingw/ =~ RUBY_PLATFORM
|
f.binmode if /mingw/ =~ RUBY_PLATFORM
|
||||||
|
|
||||||
f.print <<EOF
|
f.print <<EOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user