cleanup junk

add -T option to skip writing to the .newsrc file
This commit is contained in:
Ward Wouts 2002-05-01 22:14:44 +00:00
parent 55d8d6790d
commit 4da31a02dd

View file

@ -7,6 +7,7 @@ require 'date'
require 'getoptlong' require 'getoptlong'
require 'news/article' require 'news/article'
require 'news/newsrc' require 'news/newsrc'
require 'tempfile'
########################################################################### ###########################################################################
@ -39,9 +40,7 @@ def save_file(dir, name, data)
when "Array" when "Array"
if file = File.new("#{dir}/#{newname}", "w", "0644") if file = File.new("#{dir}/#{newname}", "w", "0644")
print " Saving as: '#{newname}'\n" print " Saving as: '#{newname}'\n"
for i in data data.collect{|i| file.print "#{i}"}
file.print "#{i}"
end
else else
print "couldn't open file for writeing\n" print "couldn't open file for writeing\n"
end end
@ -50,26 +49,26 @@ def save_file(dir, name, data)
end end
end end
def tmp_file(dir) #def tmp_file(dir)
name = "riptmp" # name = "riptmp"
print "tmpname: #{name}\n" if Debuglevel > 1 # print "tmpname: #{name}\n" if Debuglevel > 1
nname = name.gsub(/\//, "-") # nname = name.gsub(/\//, "-")
print "nname: #{nname}\n" if Debuglevel > 1 # print "nname: #{nname}\n" if Debuglevel > 1
newname = nname # newname = nname
count = 1 # count = 1
#
while FileTest.exists?("#{dir}/#{newname}") # while FileTest.exists?("#{dir}/#{newname}")
newname = "#{nname}-#{count}" # newname = "#{nname}-#{count}"
count += 1 # count += 1
end # end
print "name: #{newname}\n" if Debuglevel > 1 # print "name: #{newname}\n" if Debuglevel > 1
fullname ="#{dir}/#{newname}" # fullname ="#{dir}/#{newname}"
if file = File.new(fullname, "w+", "0644") # if file = File.new(fullname, "w+", "0644")
return file, fullname # return file, fullname
else # else
print "couldn't open tempfile for writeing\n" # print "couldn't open tempfile for writeing\n"
end # end
end #end
def parse_options(options) def parse_options(options)
begin begin
@ -78,6 +77,7 @@ def parse_options(options)
[ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ], [ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ],
[ "-L", "--longname", GetoptLong::NO_ARGUMENT ], [ "-L", "--longname", GetoptLong::NO_ARGUMENT ],
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ], [ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
[ "-T", "--test", GetoptLong::NO_ARGUMENT ],
[ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ], [ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ],
[ "-g", "--greedy", GetoptLong::NO_ARGUMENT ] [ "-g", "--greedy", GetoptLong::NO_ARGUMENT ]
) )
@ -235,21 +235,38 @@ for group in config.keys.sort
print "Match: #{i}\n" if Debuglevel > 0 print "Match: #{i}\n" if Debuglevel > 0
if articles.group_complete(i) if articles.group_complete(i)
print " Fetching: #{i}\n" print " Fetching: #{i}\n"
if config[group].has_key?("TEMPDIR") if articles.group_singlepart(i)
file, fullname = tmp_file(config[group]["TEMPDIR"]) print " Singlepart!\n"
fileout, fullnameout = tmp_file(config[group]["TEMPDIR"]) body = articles.get_group_body(i)
if articles.is_uuencoded(body)
mode, filename, body = articles.uudecode(body)
else else
file=nil print "Not UUencoded!\n"
fullname = ""
fileout=nil
fullnameout = ""
end end
mode, filename, body = articles.uudecode_group(i, file, fileout) elsif articles.group_multipart(i)
print " Multipart!\n"
if file if config[group]["TEMPDIR"] == nil or config[group]["TEMPDIR"] == ""
body = get_group_body(i)
if articles.is_uuencoded(body)
mode, filename, body = articles.uudecode(body)
else
print "Multipart article not UUencoded!\n"
end
else
body = articles.get_group_body_first(i)
if articles.is_uuencoded(body)
file = Tempfile.new("#{config[group]["TEMPDIR"]}/riptmp")
body.collect{|x| file.print "#{x}\n"}
articles.get_group_body_rest(i, file)
fileout = Tempfile.new("#{config[group]["TEMPDIR"]}/riptmp")
mode, filename, body = articles.uudecode(file, fileout)
body = fileout.path
file.close file.close
fileout.close fileout.close
body = fullnameout else
print "Multipart article not UUencoded!\n"
end
end
end end
if mode if mode
@ -265,11 +282,8 @@ for group in config.keys.sort
end end
marked = articles.get_group_ids(i) marked = articles.get_group_ids(i)
newsrc.mark_list(group, marked) newsrc.mark_list(group, marked)
newsrc.save newsrc.save unless config[group].has_key?("-T") and config[group]["-T"]
#marked.collect!{|x| print "marked: #{x}\n"} #marked.collect!{|x| print "marked: #{x}\n"}
# rm file & fileout
File.delete(fullname)
#File.delete(fullnameout)
else else
print " Not complete: #{i}\n" print " Not complete: #{i}\n"
end end