From: <jj...@us...> - 2004-02-03 18:13:01
|
Update of /cvsroot/ngetsuite/ngetsuite/ngetsuite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9158/ngetsuite Modified Files: group.rb ngetcache.rb Log Message: added callbacks (o...k...) Index: group.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/group.rb,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** group.rb 3 Feb 2004 12:58:45 -0000 1.24 --- group.rb 3 Feb 2004 16:33:28 -0000 1.25 *************** *** 180,233 **** def mknewscache debug "Beginning mknewscache at #{Time.now.strftime('%H:%M:%S')}" - cache = NgetCache.new(@_fullname, @cachedir) - puts "The cache file for #{@_fullname} seems corrupted !" if not cache.sane sth = Db.dbh.prepare 'insert into articles(`group`, `mid`, `nbparts`, `size`, `subject`, `from`, `time`, `rls_subject`) values (?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?)' ! cache.files.each { |f| ! next if f.req < 1 ! partcnt, size, a = 0, 0, nil ! rsubj = f.subject.gsub(/^(.* )(- .*)?".*$/, '\1').gsub(/\d{1,3}(\/| of )\d{1,3}/, '#\1#').gsub(/ \d\d? /, ' # ') ! f.parts.each { |p| ! next if p.articles.empty? a = p.articles[0] ! size += a.bytes / ( a.bytes<100*a.lines ? 1.39 : 1.0334) ! partcnt += 1 ! if partcnt >= f.req ! sth.execute(@_fullname, p.mid, f.req, size, f.subject, f.author, p.date, rsubj) end - } - } - if false - while (cachefile.gets != ".\n") - end - while line = cachefile.gets - next if line !~ /^(\d+)\t0\t/ or $1.to_i < 1 - parts, subject, from = line.split(/\t/).values_at(0, 3, 4) - parts = parts.to_i - while (cachefile.gets != ".\n") end ! partcnt = 0 ! size = 0 ! line = cachefile.gets ! while line != ".\n" ! line =~ /^\d+\t(.*)\t(.*)$/ ! time, mid = $1, $2 ! while (line = cachefile.gets) != ".\n" ! serverid, bytes, lines = line.split(/\t/).values_at(1,2,3).collect {|x| x.to_i} ! end ! lines = 1 if lines < 1 ! linelength = (bytes / lines).to_i ! size = size.to_i + (bytes / ( linelength < 100 ? 1.39 : 1.0334 )) ! partcnt += 1 ! ! if parts <= partcnt ! # info about file if file is complete ! # make the release subject from the subject ! rsubj = subject.gsub(/^(.* )(- .*)?".*$/, '\1').gsub(/\d{1,3}(\/| of )\d{1,3}/, '#\1#').gsub(/ \d\d? /, ' # ') ! sth.execute(@_fullname, mid, parts, size.to_i, subject, from, time, rsubj) ! end ! end ! end ! end debug "End mknewscache at #{Time.now.strftime('%H:%M:%S')}" end --- 180,207 ---- def mknewscache debug "Beginning mknewscache at #{Time.now.strftime('%H:%M:%S')}" sth = Db.dbh.prepare 'insert into articles(`group`, `mid`, `nbparts`, `size`, `subject`, `from`, `time`, `rls_subject`) values (?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?)' ! filecallback = Proc.new{ |f| ! if f.req < 1 ! @cachecb_invalid = true ! else ! @cachecb_invalid = false ! end ! @cachecb_file = f ! @cachecb_rsubj = f.subject.gsub(/^(.* )(- .*)?".*$/, '\1').gsub(/\d{1,3}(\/| of )\d{1,3}/, '#\1#').gsub(/ \d\d? /, ' # ') ! @cachecb_partcnt = 0 ! @cachecb_size = 0 ! } ! partcallback = Proc.new{ |p| ! unless @cachecb_invalid or p.articles.empty? a = p.articles[0] ! @cachecb_size += a.bytes / ( a.bytes < 100*a.lines ? 1.39 : 1.0334 ) ! @cachecb_partcnt += 1 ! if @cachecb_partcnt >= @cachecb_file.req ! sth.execute(@_fullname, p.mid, @cachecb_file.req, @cachecb_size, @cachecb_file.subject, @cachecb_file.author, p.date, @cachecb_rsubj) end end + } ! NgetCache.new(@_fullname, @cachedir, nil, filecallback, partcallback) debug "End mknewscache at #{Time.now.strftime('%H:%M:%S')}" end Index: ngetcache.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/ngetcache.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ngetcache.rb 3 Feb 2004 12:58:45 -0000 1.2 --- ngetcache.rb 3 Feb 2004 16:33:28 -0000 1.3 *************** *** 18,24 **** CacheArticle = Struct.new('CacheArticle', 'serverid', 'articlenum', 'bytes', 'lines') ! def initialize(groupname, path='.', sanitycheck = true, limit=nil) @servers = Array.new @files = Array.new @sane = true --- 18,25 ---- CacheArticle = Struct.new('CacheArticle', 'serverid', 'articlenum', 'bytes', 'lines') ! def initialize(groupname, path='.', limit=nil, filecallback=nil, partcallback=nil, articlecallback=nil) @servers = Array.new @files = Array.new + @filecallback, @partcallback, @articlecallback = filecallback, partcallback, articlecallback @sane = true *************** *** 57,61 **** # files list while (file = read_file) ! @files << file if limit break if (limit -= 1) < 0 --- 58,62 ---- # files list while (file = read_file) ! @files << file unless @filecallback if limit break if (limit -= 1) < 0 *************** *** 83,86 **** --- 84,89 ---- end + @filecallback.call(file) if @filecallback + # parts of the file while (part = read_part) *************** *** 105,108 **** --- 108,112 ---- part.articles << article end + @partcallback.call(part) if @partcallback part end *************** *** 111,115 **** return unless readline raise BadNgetCache.new('invalid article description') unless @line =~ /^(\d+)\t(\d+)\t(\d+)\t(\d+)$/ ! CacheArticle.new($1.to_i, $2.to_i, $3.to_i, $4.to_i) end --- 115,121 ---- return unless readline raise BadNgetCache.new('invalid article description') unless @line =~ /^(\d+)\t(\d+)\t(\d+)\t(\d+)$/ ! article = CacheArticle.new($1.to_i, $2.to_i, $3.to_i, $4.to_i) ! @articlecallback.call(article) if @articlecallback ! article end |