much beter configurability
This commit is contained in:
parent
6d7e67a90b
commit
df8c6c10d0
1 changed files with 195 additions and 92 deletions
|
|
@ -70,9 +70,7 @@ def tmp_file(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def parse_options
|
def parse_options(options)
|
||||||
options = {}
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
opts = GetoptLong.new(
|
opts = GetoptLong.new(
|
||||||
[ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ],
|
[ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ],
|
||||||
|
|
@ -96,72 +94,178 @@ def parse_options
|
||||||
return options
|
return options
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_config(options)
|
#def read_config(options)
|
||||||
unless options.has_key?("-c")
|
# unless options.has_key?("-c")
|
||||||
options["-c"]=".ripnewsrc"
|
# options["-c"]=".ripnewsrc"
|
||||||
|
# end
|
||||||
|
# begin
|
||||||
|
# config = IO.readlines("#{options[\"-c\"]}")
|
||||||
|
# for i in config
|
||||||
|
# if i =~ /^OPT_(.)=?(.*)$/
|
||||||
|
# options["-#{$1}"]=$2 unless
|
||||||
|
# options.has_key?("-#{$1}")
|
||||||
|
# else
|
||||||
|
# i =~ /([^=]*)=(.*)/
|
||||||
|
# options["#{$1}"]=$2
|
||||||
|
# end
|
||||||
|
# print "#{$1}=", options["#{$1}"], "\n" if Debuglevel > 1
|
||||||
|
# end
|
||||||
|
# rescue
|
||||||
|
# print "Coudn't open config file: #{options[\"-c\"]}\n"
|
||||||
|
# exit
|
||||||
|
# end
|
||||||
|
# return options
|
||||||
|
#end
|
||||||
|
|
||||||
|
def parse_config(default = {})
|
||||||
|
file = File.new("#{default[\"-c\"]}")
|
||||||
|
lines = file.readlines
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
group = ""
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
lines.collect!{|x| x.sub!(/^\s*/, ""); x.chomp}
|
||||||
|
while i < lines.length
|
||||||
|
line = lines[i]
|
||||||
|
while line.sub!(/\s*\\$/, "") != nil
|
||||||
|
line += lines[i+1]
|
||||||
|
i += 1
|
||||||
end
|
end
|
||||||
begin
|
line.sub!(/\s*$/, "")
|
||||||
config = IO.readlines("#{options[\"-c\"]}")
|
i += 1
|
||||||
for i in config
|
if line =~ /^OPT_(.*?)=(.*)/
|
||||||
if i =~ /^OPT_(.)=?(.*)$/
|
line = "-#{$1}=#{$2}"
|
||||||
options["-#{$1}"]=$2 unless
|
end
|
||||||
options.has_key?("-#{$1}")
|
print "#{i}: #{line}\n" if Debuglevel > 1
|
||||||
|
if line =~ /(.*?)\s*\+=\s*(.*)/
|
||||||
|
if group == ""
|
||||||
|
default[$1] += $2
|
||||||
else
|
else
|
||||||
i =~ /([^=]*)=(.*)/
|
for g in group.split
|
||||||
options["#{$1}"]=$2
|
if config[g].has_key?($1)
|
||||||
|
config[g][$1] += $2
|
||||||
|
elsif default.has_key?($1)
|
||||||
|
config[g][$1] = default[$1] + $2
|
||||||
|
else
|
||||||
|
config[g][$1] = $2
|
||||||
end
|
end
|
||||||
print "#{$1}=", options["#{$1}"], "\n" if Debuglevel > 1
|
|
||||||
end
|
end
|
||||||
rescue
|
end
|
||||||
print "Coudn't open config file: #{options[\"-c\"]}\n"
|
elsif line =~ /(.*?)\s*=\s*(.*)/
|
||||||
|
if group == ""
|
||||||
|
default[$1] = $2
|
||||||
|
else
|
||||||
|
for g in group.split
|
||||||
|
config[g][$1] = $2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elsif line =~ /(.*?)\s*\{/
|
||||||
|
group = $1
|
||||||
|
for g in group.split
|
||||||
|
unless config.has_key?(g)
|
||||||
|
config[g] = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elsif line =~ /^}$/
|
||||||
|
default.each_key{|x|
|
||||||
|
for g in group.split
|
||||||
|
unless config[g].has_key?(x)
|
||||||
|
config[g][x] = default[x]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
group = ""
|
||||||
|
elsif line =~ /^$/
|
||||||
|
next
|
||||||
|
else
|
||||||
|
print "Error parsing config on line: #{i}\n"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
return options
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def check_options(options)
|
if group != ""
|
||||||
if (Debuglevel > 1)
|
print "Error parsing config: group not terminated on line #{i}\n"
|
||||||
for i in options.keys
|
|
||||||
print "Opt: #{i} Value: #{options[i]}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
unless options.has_key?("-I")
|
|
||||||
print "No inclusions given. Won't match anything.\n"
|
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
unless options.has_key?("DATADIR")
|
|
||||||
options["DATADIR"] ="."
|
if Debuglevel > 2
|
||||||
|
config.each_key{|x|
|
||||||
|
print "Group: #{x}\n"
|
||||||
|
config[x].each_key{|y|
|
||||||
|
print "Key: '#{y}' => Value: '#{config[x][y]}'\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
# exit # zeer tijdelijk voor snel testen
|
|
||||||
|
return config
|
||||||
end
|
end
|
||||||
|
|
||||||
options = {}
|
#def check_options(options)
|
||||||
options = parse_options
|
# if (Debuglevel > 1)
|
||||||
options = read_config(options)
|
# for i in options.keys
|
||||||
check_options(options)
|
# print "Opt: #{i} Value: #{options[i]}\n"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# unless options.has_key?("-I")
|
||||||
|
# print "No inclusions given. Won't match anything.\n"
|
||||||
|
# exit
|
||||||
|
# end
|
||||||
|
# unless options.has_key?("DATADIR")
|
||||||
|
# options["DATADIR"] ="."
|
||||||
|
# end
|
||||||
|
## exit # zeer tijdelijk voor snel testen
|
||||||
|
#end
|
||||||
|
|
||||||
if Debuglevel > 1
|
def check_config(config)
|
||||||
for i in options.keys
|
config.each_key {|i|
|
||||||
print "Opt: #{i} val: #{options[i]}\n"
|
unless config[i].has_key?("-I")
|
||||||
|
print "No inclusions given for group #{i}. Won't match anything.\n"
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
|
unless config[i].has_key?("DATADIR")
|
||||||
|
config[i]["DATADIR"] ="."
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defaults = {'-c' => '.ripnewsrc'}
|
||||||
|
defaults = parse_options(defaults)
|
||||||
|
#options = read_config(options)
|
||||||
|
config = parse_config(defaults)
|
||||||
|
check_config(config)
|
||||||
|
|
||||||
|
if Debuglevel > 2
|
||||||
|
config.each_key{|i|
|
||||||
|
print "Group: #{i}\n"
|
||||||
|
config[i].each_key{|j|
|
||||||
|
print "Opt: #{j} val: #{config[i][j]}\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
newsrc = News::Newsrc.new(".newsrc")
|
newsrc = News::Newsrc.new(".newsrc")
|
||||||
|
|
||||||
articles = Article.new(options["NNTPSERVER"])
|
for group in config.keys
|
||||||
#articles.get_articles("alt.binaries.e-book.flood")
|
print "Getting articles for #{group}\n"
|
||||||
articles.set_skip_ids(newsrc.marked_articles("alt.binaries.e-book.technical"))
|
articles = Article.new(config[group]["NNTPSERVER"])
|
||||||
articles.get_articles("alt.binaries.e-book.technical")
|
articles.set_skip_ids(newsrc.marked_articles(group))
|
||||||
|
articles.get_articles(group, config[group]["CACHEDIR"])
|
||||||
|
|
||||||
for i in articles.get_group_subjects
|
unless FileTest.directory?("#{config[group]["DATADIR"]}/#{group}") or
|
||||||
print "#{i}\n" if Debuglevel > 1
|
Dir.mkdir("#{config[group]["DATADIR"]}/#{group}")
|
||||||
if i =~ /#{options["-I"]}/i
|
print "eeeps, couldn't create dir\n"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
for i in articles.get_group_subjects
|
||||||
|
print "#{i}\n" if Debuglevel > 2
|
||||||
|
if i =~ /#{config[group]["-I"]}/i
|
||||||
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 "Complete: #{i}\n" if Debuglevel > 0
|
print "Complete: #{i}\n" if Debuglevel > 0
|
||||||
if options.has_key?("TMPDIR")
|
if config[group].has_key?("TMPDIR")
|
||||||
file, fullname = tmp_file(options["TMPDIR"])
|
file, fullname = tmp_file(config[group]["TMPDIR"])
|
||||||
fileout, fullnameout = tmp_file(options["TMPDIR"])
|
fileout, fullnameout = tmp_file(config[group]["TMPDIR"])
|
||||||
else
|
else
|
||||||
file=nil
|
file=nil
|
||||||
fullname = ""
|
fullname = ""
|
||||||
|
|
@ -179,17 +283,17 @@ for i in articles.get_group_subjects
|
||||||
if mode
|
if mode
|
||||||
print "mode: #{mode}\n" if Debuglevel > 0
|
print "mode: #{mode}\n" if Debuglevel > 0
|
||||||
print "filename: #{filename}\n"
|
print "filename: #{filename}\n"
|
||||||
if options.has_key?("-L")
|
if config[group].has_key?("-L")
|
||||||
print "longname\n" if Debuglevel > 1
|
print "longname\n" if Debuglevel > 1
|
||||||
save_file(options["DATADIR"], i, body)
|
save_file("#{config[group]["DATADIR"]}/#{group}", i, body)
|
||||||
else
|
else
|
||||||
print "shortname\n" if Debuglevel > 1
|
print "shortname\n" if Debuglevel > 1
|
||||||
save_file(options["DATADIR"], filename, body)
|
save_file("#{config[group]["DATADIR"]}/#{group}", filename, body)
|
||||||
end
|
end
|
||||||
marked = articles.get_group_ids(i)
|
marked = articles.get_group_ids(i)
|
||||||
newsrc.mark_list("alt.binaries.e-book.technical", marked)
|
newsrc.mark_list(group, marked)
|
||||||
newsrc.save
|
newsrc.save
|
||||||
marked.collect!{|x| print "marked: #{x}\n"}
|
#marked.collect!{|x| print "marked: #{x}\n"}
|
||||||
end
|
end
|
||||||
# rm file & fileout
|
# rm file & fileout
|
||||||
File.delete(fullname)
|
File.delete(fullname)
|
||||||
|
|
@ -198,7 +302,6 @@ for i in articles.get_group_subjects
|
||||||
end
|
end
|
||||||
print "\n"
|
print "\n"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
articles.quit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
articles.quit
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue