cleanup junk
add -T option to skip writing to the .newsrc file
This commit is contained in:
parent
55d8d6790d
commit
4da31a02dd
1 changed files with 56 additions and 42 deletions
|
|
@ -7,6 +7,7 @@ require 'date'
|
|||
require 'getoptlong'
|
||||
require 'news/article'
|
||||
require 'news/newsrc'
|
||||
require 'tempfile'
|
||||
|
||||
|
||||
###########################################################################
|
||||
|
|
@ -39,9 +40,7 @@ def save_file(dir, name, data)
|
|||
when "Array"
|
||||
if file = File.new("#{dir}/#{newname}", "w", "0644")
|
||||
print " Saving as: '#{newname}'\n"
|
||||
for i in data
|
||||
file.print "#{i}"
|
||||
end
|
||||
data.collect{|i| file.print "#{i}"}
|
||||
else
|
||||
print "couldn't open file for writeing\n"
|
||||
end
|
||||
|
|
@ -50,26 +49,26 @@ def save_file(dir, name, data)
|
|||
end
|
||||
end
|
||||
|
||||
def tmp_file(dir)
|
||||
name = "riptmp"
|
||||
print "tmpname: #{name}\n" if Debuglevel > 1
|
||||
nname = name.gsub(/\//, "-")
|
||||
print "nname: #{nname}\n" if Debuglevel > 1
|
||||
newname = nname
|
||||
count = 1
|
||||
|
||||
while FileTest.exists?("#{dir}/#{newname}")
|
||||
newname = "#{nname}-#{count}"
|
||||
count += 1
|
||||
end
|
||||
print "name: #{newname}\n" if Debuglevel > 1
|
||||
fullname ="#{dir}/#{newname}"
|
||||
if file = File.new(fullname, "w+", "0644")
|
||||
return file, fullname
|
||||
else
|
||||
print "couldn't open tempfile for writeing\n"
|
||||
end
|
||||
end
|
||||
#def tmp_file(dir)
|
||||
# name = "riptmp"
|
||||
# print "tmpname: #{name}\n" if Debuglevel > 1
|
||||
# nname = name.gsub(/\//, "-")
|
||||
# print "nname: #{nname}\n" if Debuglevel > 1
|
||||
# newname = nname
|
||||
# count = 1
|
||||
#
|
||||
# while FileTest.exists?("#{dir}/#{newname}")
|
||||
# newname = "#{nname}-#{count}"
|
||||
# count += 1
|
||||
# end
|
||||
# print "name: #{newname}\n" if Debuglevel > 1
|
||||
# fullname ="#{dir}/#{newname}"
|
||||
# if file = File.new(fullname, "w+", "0644")
|
||||
# return file, fullname
|
||||
# else
|
||||
# print "couldn't open tempfile for writeing\n"
|
||||
# end
|
||||
#end
|
||||
|
||||
def parse_options(options)
|
||||
begin
|
||||
|
|
@ -78,6 +77,7 @@ def parse_options(options)
|
|||
[ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ "-L", "--longname", GetoptLong::NO_ARGUMENT ],
|
||||
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
|
||||
[ "-T", "--test", GetoptLong::NO_ARGUMENT ],
|
||||
[ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ "-g", "--greedy", GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
|
|
@ -235,21 +235,38 @@ for group in config.keys.sort
|
|||
print "Match: #{i}\n" if Debuglevel > 0
|
||||
if articles.group_complete(i)
|
||||
print " Fetching: #{i}\n"
|
||||
if config[group].has_key?("TEMPDIR")
|
||||
file, fullname = tmp_file(config[group]["TEMPDIR"])
|
||||
fileout, fullnameout = tmp_file(config[group]["TEMPDIR"])
|
||||
else
|
||||
file=nil
|
||||
fullname = ""
|
||||
fileout=nil
|
||||
fullnameout = ""
|
||||
end
|
||||
mode, filename, body = articles.uudecode_group(i, file, fileout)
|
||||
|
||||
if file
|
||||
file.close
|
||||
fileout.close
|
||||
body = fullnameout
|
||||
if articles.group_singlepart(i)
|
||||
print " Singlepart!\n"
|
||||
body = articles.get_group_body(i)
|
||||
if articles.is_uuencoded(body)
|
||||
mode, filename, body = articles.uudecode(body)
|
||||
else
|
||||
print "Not UUencoded!\n"
|
||||
end
|
||||
elsif articles.group_multipart(i)
|
||||
print " Multipart!\n"
|
||||
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
|
||||
fileout.close
|
||||
else
|
||||
print "Multipart article not UUencoded!\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mode
|
||||
|
|
@ -265,11 +282,8 @@ for group in config.keys.sort
|
|||
end
|
||||
marked = articles.get_group_ids(i)
|
||||
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"}
|
||||
# rm file & fileout
|
||||
File.delete(fullname)
|
||||
#File.delete(fullnameout)
|
||||
else
|
||||
print " Not complete: #{i}\n"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue