some cleanup

exclude option
permission option for dir create
This commit is contained in:
Ward Wouts 2002-04-30 21:10:49 +00:00
parent 0679c27187
commit 22f4154597

View file

@ -17,6 +17,8 @@ def save_file(dir, name, data)
print "savename: #{name}\n" if Debuglevel > 1
nname = name.gsub(/\//, "-")
print "nname: #{nname}\n" if Debuglevel > 1
nname.sub!(/\s*$/, "")
nname.sub!(/^\s*/, "")
newname = nname
count = 1
d = Date.today
@ -30,13 +32,13 @@ def save_file(dir, name, data)
case data.type.to_s
when "String"
if File.rename(data, "#{dir}/#{newname}")
print "Saving: #{newname}\n"
print " Saving as: '#{newname}'\n"
else
print "couldn't rename tempfile\n"
end
when "Array"
if file = File.new("#{dir}/#{newname}", "w", "0644")
print "Saving: #{newname}\n"
print " Saving as: '#{newname}'\n"
for i in data
file.print "#{i}"
end
@ -76,6 +78,7 @@ def parse_options(options)
[ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ],
[ "-L", "--longname", GetoptLong::NO_ARGUMENT ],
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
[ "-X", "--exclude", GetoptLong::REQUIRED_ARGUMENT ],
[ "-g", "--greedy", GetoptLong::NO_ARGUMENT ]
)
opts.quiet=true
@ -190,6 +193,12 @@ def check_config(config)
unless config[i].has_key?("DATADIR")
config[i]["DATADIR"] ="."
end
unless config[i].has_key?("NEWSRCNAME")
config[i]["NEWSRCNAME"] = "~/.newsrc"
end
unless config[i].has_key?("PERMISSION")
config[i]["PERMISSION"] = "0755"
end
}
end
@ -207,28 +216,28 @@ if Debuglevel > 2
}
end
newsrc = News::Newsrc.new(".newsrc")
for group in config.keys
for group in config.keys.sort
newsrc = News::Newsrc.new(config[group]["NEWSRCNAME"])
print "Getting articles for #{group}\n"
articles = Article.new(config[group]["NNTPSERVER"])
articles.set_skip_ids(newsrc.marked_articles(group))
articles.get_articles(group, config[group]["CACHEDIR"])
unless FileTest.directory?("#{config[group]["DATADIR"]}/#{group}") or
Dir.mkdir("#{config[group]["DATADIR"]}/#{group}")
Dir.mkdir("#{config[group]["DATADIR"]}/#{group}", config[group]["PERMISSION"].oct)
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
if !(config[group].has_key?("-X") and i =~ /#{config[group]["-X"]}/) and
i =~ /#{config[group]["-I"]}/
print "Match: #{i}\n" if Debuglevel > 0
if articles.group_complete(i)
print " Fetching: #{i}\n"
if config[group].has_key?("TMPDIR")
file, fullname = tmp_file(config[group]["TMPDIR"])
fileout, fullnameout = tmp_file(config[group]["TMPDIR"])
if config[group].has_key?("TEMPDIR")
file, fullname = tmp_file(config[group]["TEMPDIR"])
fileout, fullnameout = tmp_file(config[group]["TEMPDIR"])
else
file=nil
fullname = ""
@ -245,7 +254,7 @@ for group in config.keys
if mode
print " mode: #{mode}\n" if Debuglevel > 0
print "filename: #{filename}\n"
print " Filename: '#{filename}'\n" if Debuglevel > 0
if config[group].has_key?("-L") and config[group]["-L"]
print "longname\n" if Debuglevel > 1
save_file("#{config[group]["DATADIR"]}/#{group}", i, body)
@ -260,6 +269,7 @@ for group in config.keys
#marked.collect!{|x| print "marked: #{x}\n"}
# rm file & fileout
File.delete(fullname)
#File.delete(fullnameout)
else
print " Not complete: #{i}\n"
end