some cleaning
This commit is contained in:
parent
af0eb1f1c7
commit
666291155c
1 changed files with 43 additions and 63 deletions
|
|
@ -53,29 +53,32 @@ 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 ],
|
||||||
[ "-M", "--multipart", GetoptLong::NO_ARGUMENT ],
|
[ "-C", "--combinedname", GetoptLong::NO_ARGUMENT ],
|
||||||
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
|
[ "-M", "--multipart", GetoptLong::NO_ARGUMENT ],
|
||||||
[ "-T", "--test", GetoptLong::NO_ARGUMENT ],
|
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
|
||||||
[ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ],
|
[ "-T", "--test", GetoptLong::NO_ARGUMENT ],
|
||||||
[ "-g", "--greedy", GetoptLong::NO_ARGUMENT ]
|
[ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ],
|
||||||
)
|
[ "-g", "--greedy", GetoptLong::NO_ARGUMENT ]
|
||||||
opts.quiet=true
|
)
|
||||||
|
opts.quiet=true
|
||||||
opts.each do |opt, arg|
|
|
||||||
options[opt] = arg
|
|
||||||
end
|
|
||||||
|
|
||||||
|
opts.each do |opt, arg|
|
||||||
|
options[opt] = arg
|
||||||
|
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,32 +225,25 @@ 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)
|
if @articles.is_uuencoded(body) or @articles.is_yencoded(body)
|
||||||
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
||||||
body.collect{|x| file.print "#{x}\n"}
|
body.collect{|x| file.print "#{x}\n"}
|
||||||
return false unless @articles.get_group_body_rest(subj, file)
|
return false unless @articles.get_group_body_rest(subj, file)
|
||||||
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
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")
|
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
|
||||||
|
else
|
||||||
|
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||||
|
return false
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -267,16 +254,17 @@ 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
|
||||||
@articles.group_update_newsrc(subject)
|
end
|
||||||
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
|
if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body)
|
||||||
end
|
@articles.group_update_newsrc(subject)
|
||||||
|
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue