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