Exemplo n.º 1
0
 def reportBacklinks(self, new):
     """Report missing back links. This will be called from finish() if
        needed."""
     for code in new.keys():
         pl = new[code]
         if not unequal.bigger(self.inpl, pl):
             shouldlink = new.values() + [self.inpl]
             linked = pl.interwiki()
             for xpl in shouldlink:
                 if xpl != pl and not xpl in linked:
                     for l in linked:
                         if l.code() == xpl.code():
                             print "WARNING:", pl.asasciiselflink(), "does not link to", xpl.asasciilink(), "but to", l.asasciilink()
                             break
                     else:
                         print "WARNING:", pl.asasciiselflink(), "does not link to", xpl.asasciilink()
             # Check for superfluous links
             for xpl in linked:
                 if not xpl in shouldlink:
                     # Check whether there is an alternative page on that language.
                     for l in shouldlink:
                         if l.code() == xpl.code():
                             # Already reported above.
                             break
                     else:
                         # New warning
                         print "WARNING:", pl.asasciiselflink(), "links to incorrect", xpl.asasciilink()
Exemplo n.º 2
0
 def workDone(self, counter):
     """This is called by a worker to tell us that the promised work
        was completed as far as possible. The only argument is an instance
        of a counter class, that has methods minus() and plus() to keep
        counts of the total work todo."""
     # Loop over all the pages that should have been taken care of
     for pl in self.pending:
         # Mark the page as done
         self.done[pl] = pl.code()
         # Register this fact at the todo-counter.
         counter.minus(pl.code())
         # Assume it's not a redirect
         isredirect = 0
         # Now check whether any interwiki links should be added to the
         # todo list.
         if unequal.bigger(self.inpl, pl):
             print "NOTE: %s is bigger than %s, not following references" % (pl, self.inpl)
         else:
             try:
                 iw = pl.interwiki()
             except wikipedia.IsRedirectPage,arg:
                 pl3 = wikipedia.PageLink(pl.code(),arg.args[0])
                 print "NOTE: %s is redirect to %s" % (pl.asasciilink(), pl3.asasciilink())
                 if pl == self.inpl:
                     # This is a redirect page itself. We don't need to
                     # follow the redirection.
                     isredirect = 1
                     # In this case we can also stop all hints!
                     for pl2 in self.todo:
                         counter.minus(pl2.code())
                     self.todo = {}
                     pass
                 elif not globalvar.followredirect:
                     print "NOTE: not following redirects."
                 elif unequal.unequal(self.inpl, pl3):
                     print "NOTE: %s is unequal to %s, not adding it" % (pl3, self.inpl)
                 else:
                     if self.conditionalAdd(pl3, counter):
                         if globalvar.shownew:
                             print "%s: %s gives new redirect %s"% (self.inpl.asasciiselflink(), pl.asasciilink(), pl3.asasciilink())
             except wikipedia.NoPage:
                 print "NOTE: %s does not exist" % pl.asasciilink()
                 #print "DBG> ",pl.urlname()
                 if pl == self.inpl:
                     # This is the home subject page.
                     # In this case we can stop all hints!
                     for pl2 in self.todo:
                         counter.minus(pl2.code())
                     self.todo = {}
                     pass
             except wikipedia.SubpageError:
                 print "NOTE: %s subpage does not exist" % pl.asasciilink()