From 666291155c48a608bd0fe43ba9aa182bb292b78a Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Sat, 18 May 2002 23:12:59 +0000 Subject: [PATCH] some cleaning --- trunk/ripnews/ripnews.rb | 106 ++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/trunk/ripnews/ripnews.rb b/trunk/ripnews/ripnews.rb index d164a34..a9fc63d 100755 --- a/trunk/ripnews/ripnews.rb +++ b/trunk/ripnews/ripnews.rb @@ -53,29 +53,32 @@ def save_file(dir, name, data) return true end +# meuh, dit werkt nu niet :( mag dit wel in een def staan? def parse_options(options) begin - opts = GetoptLong.new( - [ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ], - [ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ], - [ "-L", "--longname", GetoptLong::NO_ARGUMENT ], - [ "-M", "--multipart", GetoptLong::NO_ARGUMENT ], - [ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ], - [ "-T", "--test", GetoptLong::NO_ARGUMENT ], - [ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ], - [ "-g", "--greedy", GetoptLong::NO_ARGUMENT ] - ) - opts.quiet=true - - opts.each do |opt, arg| - options[opt] = arg - end + opts = GetoptLong.new( + [ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ], + [ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ], + [ "-L", "--longname", GetoptLong::NO_ARGUMENT ], + [ "-C", "--combinedname", GetoptLong::NO_ARGUMENT ], + [ "-M", "--multipart", GetoptLong::NO_ARGUMENT ], + [ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ], + [ "-T", "--test", GetoptLong::NO_ARGUMENT ], + [ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ], + [ "-g", "--greedy", GetoptLong::NO_ARGUMENT ] + ) + opts.quiet=true + opts.each do |opt, arg| + options[opt] = arg + end rescue print "#{opts.error_message}\n" print "\nUsage:\n" exit end + print opts.error_message + print "Remaining args: #{ARGV.join(', ')}\n" return options end @@ -176,22 +179,14 @@ def check_config print "No inclusions given for group #{i}. Won't match anything.\n" exit end - unless @config[i].has_key?("DATADIR") - @config[i]["DATADIR"] ="." - end - unless @config[i].has_key?("PERMISSION") - @config[i]["PERMISSION"] = "0755" - end + @config[i]["DATADIR"] ="." unless @config[i].has_key?("DATADIR") + @config[i]["PERMISSION"] = "0755" unless @config[i].has_key?("PERMISSION") if @config[i].has_key?("EXTENSIONS") @config[i]["-S"] = @config[i]["EXTENSIONS"] @config[i]["-M"] = @config[i]["EXTENSIONS"] end - if @config[i].has_key?("-S") and ! @config[i].has_key?("-M") - @config[i]["-M"] = "(?!.*)" - end - if @config[i].has_key?("-M") and ! @config[i].has_key?("-S") - @config[i]["-S"] = "(?!.*)" - end + @config[i]["-M"] = "(?!.*)" if @config[i].has_key?("-S") and ! @config[i].has_key?("-M") + @config[i]["-S"] = "(?!.*)" if @config[i].has_key?("-M") and ! @config[i].has_key?("-S") } end @@ -220,8 +215,7 @@ def get_multi(subj, group) mode, filename, body = @articles.uudecode(body) return false unless check_ext(filename, "m") return mode, filename, body - end - if @articles.is_yencoded(body) + elsif @articles.is_yencoded(body) mode, filename, body = @articles.ydecode(body) return false unless check_ext(filename, "m") return mode, filename, body @@ -231,32 +225,25 @@ def get_multi(subj, group) else body = @articles.get_group_body_first(subj) return false if body == false - if @articles.is_uuencoded(body) + 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"]) - mode, filename, body = @articles.uudecode(file, fileout) + if @articles.is_uuencoded(body) + mode, filename, body = @articles.uudecode(file, fileout) + elsif @articles.is_yencoded(body) + mode, filename, body = @articles.ydecode(file, fileout) + end return false unless check_ext(filename, "m") body = fileout.path file.close fileout.close return mode, filename, body + else + print " Unknown encoding (not UU, not yEnc), skipping...\n" + return false 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) - return false unless check_ext(filename, "m") - body = fileout.path - file.close - fileout.close - return mode, filename, body - end - print " Unknown encoding (not UU, not yEnc), skipping...\n" - return false end end @@ -267,16 +254,17 @@ def output_data(subject, mode, filename="", body="") print " Filename: '#{filename}'\n" if Debuglevel > 0 if @config[group].has_key?("-L") and @config[group]["-L"] print "longname\n" if Debuglevel > 1 - if save_file("#{@config[group]["DATADIR"]}/#{group}", subject, body) - @articles.group_update_newsrc(subject) - @articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"] - end + outfile = subject + elsif @config[group].has_key?("-C") and @config[group]["-C"] + print "combinedname\n" if Debuglevel > 1 + outfile = "#{subject} [#{filename}]" else print "shortname\n" if Debuglevel > 1 - if save_file("#{@config[group]["DATADIR"]}/#{group}", filename, body) - @articles.group_update_newsrc(subject) - @articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"] - end + outfile = filename + end + if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body) + @articles.group_update_newsrc(subject) + @articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"] end else return false @@ -287,17 +275,9 @@ end def check_ext(filename, mode) case mode when "s" - if @config.has_key?("-S") - return filename =~ /\.(#{@config["-S"]})$/ - else - return true - end + return @config.has_key?("-S") ? filename =~ /\.(#{@config["-S"]})$/ : true when "m" - if @config.has_key?("-M") - return filename =~ /\.(#{@config["-M"]})$/ - else - return true - end + return @config.has_key?("-M") ? filename =~ /\.(#{@config["-M"]})$/ : true else print "Illegal mode \"#{mode}\" in check_ext\n" exit