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
|
||||
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 = ""
|
||||
|
|
@ -244,8 +253,8 @@ for group in config.keys
|
|||
end
|
||||
|
||||
if mode
|
||||
print "mode: #{mode}\n" if Debuglevel > 0
|
||||
print "filename: #{filename}\n"
|
||||
print " mode: #{mode}\n" if Debuglevel > 0
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue