some cleaning

This commit is contained in:
Ward Wouts 2002-05-18 23:12:59 +00:00
parent af0eb1f1c7
commit 666291155c

View file

@ -53,12 +53,14 @@ def save_file(dir, name, data)
return true return true
end end
# meuh, dit werkt nu niet :( mag dit wel in een def staan?
def parse_options(options) def parse_options(options)
begin begin
opts = GetoptLong.new( opts = GetoptLong.new(
[ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ], [ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ],
[ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ], [ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ],
[ "-L", "--longname", GetoptLong::NO_ARGUMENT ], [ "-L", "--longname", GetoptLong::NO_ARGUMENT ],
[ "-C", "--combinedname", GetoptLong::NO_ARGUMENT ],
[ "-M", "--multipart", GetoptLong::NO_ARGUMENT ], [ "-M", "--multipart", GetoptLong::NO_ARGUMENT ],
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ], [ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
[ "-T", "--test", GetoptLong::NO_ARGUMENT ], [ "-T", "--test", GetoptLong::NO_ARGUMENT ],
@ -70,12 +72,13 @@ def parse_options(options)
opts.each do |opt, arg| opts.each do |opt, arg|
options[opt] = arg options[opt] = arg
end end
rescue rescue
print "#{opts.error_message}\n" print "#{opts.error_message}\n"
print "\nUsage:\n" print "\nUsage:\n"
exit exit
end end
print opts.error_message
print "Remaining args: #{ARGV.join(', ')}\n"
return options return options
end end
@ -176,22 +179,14 @@ def check_config
print "No inclusions given for group #{i}. Won't match anything.\n" print "No inclusions given for group #{i}. Won't match anything.\n"
exit exit
end end
unless @config[i].has_key?("DATADIR") @config[i]["DATADIR"] ="." unless @config[i].has_key?("DATADIR")
@config[i]["DATADIR"] ="." @config[i]["PERMISSION"] = "0755" unless @config[i].has_key?("PERMISSION")
end
unless @config[i].has_key?("PERMISSION")
@config[i]["PERMISSION"] = "0755"
end
if @config[i].has_key?("EXTENSIONS") if @config[i].has_key?("EXTENSIONS")
@config[i]["-S"] = @config[i]["EXTENSIONS"] @config[i]["-S"] = @config[i]["EXTENSIONS"]
@config[i]["-M"] = @config[i]["EXTENSIONS"] @config[i]["-M"] = @config[i]["EXTENSIONS"]
end end
if @config[i].has_key?("-S") and ! @config[i].has_key?("-M") @config[i]["-M"] = "(?!.*)" if @config[i].has_key?("-S") and ! @config[i].has_key?("-M")
@config[i]["-M"] = "(?!.*)" @config[i]["-S"] = "(?!.*)" if @config[i].has_key?("-M") and ! @config[i].has_key?("-S")
end
if @config[i].has_key?("-M") and ! @config[i].has_key?("-S")
@config[i]["-S"] = "(?!.*)"
end
} }
end end
@ -220,8 +215,7 @@ def get_multi(subj, group)
mode, filename, body = @articles.uudecode(body) mode, filename, body = @articles.uudecode(body)
return false unless check_ext(filename, "m") return false unless check_ext(filename, "m")
return mode, filename, body return mode, filename, body
end elsif @articles.is_yencoded(body)
if @articles.is_yencoded(body)
mode, filename, body = @articles.ydecode(body) mode, filename, body = @articles.ydecode(body)
return false unless check_ext(filename, "m") return false unless check_ext(filename, "m")
return mode, filename, body return mode, filename, body
@ -231,34 +225,27 @@ def get_multi(subj, group)
else else
body = @articles.get_group_body_first(subj) body = @articles.get_group_body_first(subj)
return false if body == false return false if body == false
if @articles.is_uuencoded(body) or @articles.is_yencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
if @articles.is_uuencoded(body) if @articles.is_uuencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
mode, filename, body = @articles.uudecode(file, fileout) mode, filename, body = @articles.uudecode(file, fileout)
return false unless check_ext(filename, "m") elsif @articles.is_yencoded(body)
body = fileout.path
file.close
fileout.close
return mode, filename, body
end
if @articles.is_yencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
mode, filename, body = @articles.ydecode(file, fileout) mode, filename, body = @articles.ydecode(file, fileout)
end
return false unless check_ext(filename, "m") return false unless check_ext(filename, "m")
body = fileout.path body = fileout.path
file.close file.close
fileout.close fileout.close
return mode, filename, body return mode, filename, body
end else
print " Unknown encoding (not UU, not yEnc), skipping...\n" print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false return false
end end
end end
end
def output_data(subject, mode, filename="", body="") def output_data(subject, mode, filename="", body="")
if mode if mode
@ -267,17 +254,18 @@ def output_data(subject, mode, filename="", body="")
print " Filename: '#{filename}'\n" if Debuglevel > 0 print " Filename: '#{filename}'\n" if Debuglevel > 0
if @config[group].has_key?("-L") and @config[group]["-L"] if @config[group].has_key?("-L") and @config[group]["-L"]
print "longname\n" if Debuglevel > 1 print "longname\n" if Debuglevel > 1
if save_file("#{@config[group]["DATADIR"]}/#{group}", subject, body) outfile = subject
@articles.group_update_newsrc(subject) elsif @config[group].has_key?("-C") and @config[group]["-C"]
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"] print "combinedname\n" if Debuglevel > 1
end outfile = "#{subject} [#{filename}]"
else else
print "shortname\n" if Debuglevel > 1 print "shortname\n" if Debuglevel > 1
if save_file("#{@config[group]["DATADIR"]}/#{group}", filename, body) outfile = filename
end
if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body)
@articles.group_update_newsrc(subject) @articles.group_update_newsrc(subject)
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"] @articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
end end
end
else else
return false return false
end end
@ -287,17 +275,9 @@ end
def check_ext(filename, mode) def check_ext(filename, mode)
case mode case mode
when "s" when "s"
if @config.has_key?("-S") return @config.has_key?("-S") ? filename =~ /\.(#{@config["-S"]})$/ : true
return filename =~ /\.(#{@config["-S"]})$/
else
return true
end
when "m" when "m"
if @config.has_key?("-M") return @config.has_key?("-M") ? filename =~ /\.(#{@config["-M"]})$/ : true
return filename =~ /\.(#{@config["-M"]})$/
else
return true
end
else else
print "Illegal mode \"#{mode}\" in check_ext\n" print "Illegal mode \"#{mode}\" in check_ext\n"
exit exit