From: <ys...@us...> - 2004-02-04 03:10:27
|
Update of /cvsroot/ngetsuite/ngetsuite/ngetsuite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3058/ngetsuite Modified Files: core.rb group.rb web.rb Added Files: articles.rb Log Message: Now recognizing releases! Web interface improved! J'ai toujours pas de stage! Make sure you've updated your dbs. --- NEW FILE: articles.rb --- require 'ngetsuite/utils' require 'ngetsuite/db' module NgetSuite class ArticleList < Db::DbList def getclass Article end end class Article include Utils include Db Db.autotable(Article, 'articles') def initialize(group, mid, fetch_from_db = false, nbparts = 0, rlsnb = 0, size = 0, subject = nil, from = nil, time = nil, release = nil) @_mid = mid @_group = group @_nbparts = nbparts @_size = size @_subject = subject @_from = from @_time = time @_release = release update_from_db if fetch_from_db end def to_s @_subject # TODO one day... end end class Release include Utils include Db Db.autotable(Release, 'releases') def initialize(group, mid, fetch_from_db = false ) @files = Array.new @_mid = mid @_group = group @_size = 0 @_nbexpected = 0 @_nbactual = 0 @_time = Time.gm("1980") update_from_db if fetch_from_db end def pushart(art, pos) art._rlsnb = pos art._release = @_mid @_size += art._size @_nbactual += 1 @_time = art._time if art._time > @_time @_completeness = @_nbactual.to_f / @_nbexpected.to_f * 100.to_f if @_nbexpected > 0 and @_nbactual <= @_nbexpected if @_rlsmap @_rlsmap[pos-1] = '#' if pos > 0 and pos <= @_rlsmap.size end @files.push art end # Returns the index of current file/nb of files # if guessed from the subject (0 if not) def Release.filenb_from_subject(subject) subject =~ /[\[\(]?(\d+)([\/]|\s*of\s*)(\d+)[\]\)]?/ return [$1.to_i, $3.to_i] end # Returns the common part between this subject and # the reference subject. We work with arrays of words def compare_subjects(subject) common = Array.new i = 0 while @refsubject[i] != nil and subject[i] != nil and @refsubject[i] == subject[i] common.push subject[i] i += 1 end return common end # Magic function to tell if an article belongs to a release # It adds it and return true if it does, return false if not def add?(art) fn = Release.filenb_from_subject(art._subject) if !@files.empty? # Deal with trivial cases # if the file sequence number is present and # seems correct, we can add the article without # further investigation return false if art._from != @poster if fn[1] > 0 and fn[0] > 0 return false if fn[1] != @_nbexpected return false if fn[0] <= @lastnb pushart(art,fn[0]) return true end else # First article: add it, # and keep the subject's words @refsubject = art._subject.split(' ') @poster = art._from @_nbexpected = fn[1] if fn[1] > 0 @lastnb = fn[0] if fn[0] > 0 @_rlsmap = '_' * @_nbexpected pushart(art,fn[0]) return true end # If we're here, the file sequence number # ("[xx/xx]"-like thing) was not found in the subject # We have to compare it with the reference subject # This is ugly and *a little* error prone, but hell... if @files.size == 1 # Second article: update the reference by storing # only the common words between the 2 subjects, # and add the article if there are any of these @refsubject = compare_subjects(art._subject.split(' ')) if @refsubject.size > 0 pushart(art,fn[0]) return true else return false end else # Already 2 or more articles in the release # Add the article if the common words between # its subject and the reference *is* the reference if compare_subjects(art._subject.split(' ')) == @refsubject pushart(art,fn[0]) return true else return false end end end def insert_to_db(only_mandatory = false) # A release contains at least 3 articles return if @files.size < 3 super(only_mandatory) # Update the articles too @files.each { |art| art.sync_to_db } end def to_s @_mid + ": " + @_nbactual.to_s + "/" + @_nbexpected.to_s + " [" + @_rlsmap + ']' end end end Index: core.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/core.rb,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** core.rb 4 Feb 2004 01:45:38 -0000 1.27 --- core.rb 4 Feb 2004 03:07:57 -0000 1.28 *************** *** 20,23 **** --- 20,36 ---- end + class NoSuchArticleException < Exception + attr_reader :number + + def initialize(number) + @number = number + end + + def message + "No such article : #{@number}" + end + end + + class NoSuchNfoException < Exception attr_reader :number Index: group.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/group.rb,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** group.rb 4 Feb 2004 01:45:39 -0000 1.26 --- group.rb 4 Feb 2004 03:07:57 -0000 1.27 *************** *** 1,4 **** --- 1,5 ---- require 'ngetsuite/utils' require 'ngetsuite/queue' + require 'ngetsuite/articles' require 'ngetsuite/ngetcache' *************** *** 141,147 **** clear_articles clear_nfos announceupdate mknewscache ! fetchnfos @_date_updated = Time.now sync_to_db --- 142,150 ---- clear_articles clear_nfos + clear_releases announceupdate mknewscache ! fetchnfos unless $config['extern_nfo_fetch'].split(',').include?(@_shortname) ! recognizereleases @_date_updated = Time.now sync_to_db *************** *** 162,165 **** --- 165,176 ---- end + + def clear_releases + debug "Beginning clear_releases at #{Time.now.strftime('%H:%M:%S')}" + nb_rows = Db.dbh.do "delete from `releases` where `group` = '#{@_fullname}'" + debug "#{nb_rows} releases deleted" + debug "End clear_releases at #{Time.now.strftime('%H:%M:%S')}" + + end def queue_regexp(regexp, prio) *************** *** 180,187 **** 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 - rsubj = f.subject.gsub(/^(.* )(- .*)?".*$/, '\1').gsub(/\d{1,3}(\/| of )\d{1,3}/, '#\1#').gsub(/ \d\d? /, ' # ') partcnt = 0 size = 0 --- 191,197 ---- 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 partcnt = 0 size = 0 *************** *** 193,197 **** partcnt += 1 if partcnt >= f.req ! sth.execute(@_fullname, p.mid, f.req, size, f.subject, f.author, p.date, rsubj) end end --- 203,207 ---- partcnt += 1 if partcnt >= f.req ! sth.execute(@_fullname, p.mid, f.req, size, f.subject, f.author, p.date) end end *************** *** 237,240 **** --- 247,271 ---- Dir.chdir(pwd) end + + def recognizereleases + articles = NgetSuite::ArticleList.new("where `group`='#{@_fullname}' order by `subject`") + @rls = nil + articles.each { |art| + @rls = NgetSuite::Release.new(art._group, art._mid) if !@rls + + if @rls.add?(art) == false then + # New release! Commit the current one to the db + @rls.insert_to_db + + # And make another + @rls = NgetSuite::Release.new(art._group, art._mid) + @rls.add?(art) + end + } + + @rls.insert_to_db + @rls = nil + end + end # class Index: web.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/web.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** web.rb 27 Dec 2003 00:41:05 -0000 1.3 --- web.rb 4 Feb 2004 03:07:57 -0000 1.4 *************** *** 8,12 **** class Web include Utils ! attr_reader :group, :offset, :articles_by_page, :filter def initialize(servlet_request) --- 8,12 ---- class Web include Utils ! attr_reader :group, :rlsmid, :offset, :articles_by_page, :filter, :date def initialize(servlet_request) *************** *** 14,17 **** --- 14,19 ---- @query = servlet_request.query + @date = "any" + @ids = @query['id' ].list() if @query.has_key? 'id' @selected = @query['selected'].list() if @query.has_key? 'selected' *************** *** 21,24 **** --- 23,28 ---- @value = @query['value' ].list() if @query.has_key? 'value' @filter = @query['filter' ].to_s if @query.has_key? 'filter' + @date = @query['date' ].to_s if @query.has_key? 'date' + @rlsmid = @query['rlsmid' ].to_s if @query.has_key? 'rlsmid' @group = NgetSuite::Group.getgroup(@query['group'].to_s) if @query.has_key? 'group' *************** *** 103,106 **** --- 107,119 ---- end + def date_str + if @date == "any" + "All articles" + else + y, m, d = date.split('-') + Time.local(y,m,d).strftime("%A, %B %d") + end + end + end #class |