Revision: 7990 Author: xqt Date: 2010-03-12 08:58:10 +0000 (Fri, 12 Mar 2010)
Log Message: ----------- ignore edit conficts at throttle.ctrl
Modified Paths: -------------- branches/rewrite/pywikibot/site.py branches/rewrite/pywikibot/throttle.py
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2010-03-11 19:16:15 UTC (rev 7989) +++ branches/rewrite/pywikibot/site.py 2010-03-12 08:58:10 UTC (rev 7990) @@ -4,7 +4,7 @@ on the same topic in different languages). """ # -# (C) Pywikipedia bot team, 2008 +# (C) Pywikipedia bot team, 2008-2010 # # Distributed under the terms of the MIT license. # @@ -876,7 +876,7 @@ def redirect(self, default=True): """Return the preferred localized #REDIRECT keyword.
- Argument is ignored (but maintained for backwards-compatibility. + Argument is ignored (but maintained for backwards-compatibility).
""" # return the magic word without the preceding '#' character @@ -888,8 +888,7 @@ Group 1 in the regex match object will be the target title.
""" - #TODO: is this needed, since the API identifies redirects? - # (maybe, the API can give false positives) + #NOTE: this is needed, since the API can give false positives! try: keywords = set(s.lstrip("#") for s in self.getmagicwords("redirect"))
Modified: branches/rewrite/pywikibot/throttle.py =================================================================== --- branches/rewrite/pywikibot/throttle.py 2010-03-11 19:16:15 UTC (rev 7989) +++ branches/rewrite/pywikibot/throttle.py 2010-03-12 08:58:10 UTC (rev 7990) @@ -47,6 +47,8 @@ if self.maxdelay is None: self.maxdelay = config.maxthrottle self.writedelay = writedelay + if self.writedelay is None: + self.writedelay = config.put_throttle self.last_read = 0 self.last_write = 0 self.next_multiplicity = 1.0 @@ -56,8 +58,10 @@ self.releasepid = 1200 # Free the process id after this many seconds self.lastwait = 0.0 self.delay = 0 + self.checktime = 0 self.verbosedelay = verbosedelay - if multiplydelay: + self.multiplydelay = multiplydelay + if self.multiplydelay: self.checkMultiplicity() self.setDelays()
@@ -95,8 +99,8 @@ if now - ptime > self.releasepid: continue # process has expired, drop from file if now - ptime <= self.dropdelay \ - and this_site == mysite \ - and this_pid != pid: + and this_site == mysite \ + and this_pid != pid: count += 1 if this_site != self.mysite or this_pid != pid: processes.append({'pid': this_pid, @@ -111,15 +115,18 @@ processes.append({'pid': pid, 'time': self.checktime, 'site': mysite}) - f = open(self.ctrlfilename, 'w') processes.sort(key=lambda p:(p['pid'], p['site'])) - for p in processes: - f.write("%(pid)s %(time)s %(site)s\n" % p) + try: + f = open(self.ctrlfilename, 'w') + for p in processes: + f.write("%(pid)s %(time)s %(site)s\n" % p) + except IOError: + pass f.close() self.process_multiplicity = count if self.verbosedelay: pywikibot.output( -u"Found %(count)s %(mysite)s processes running, including this one." + u"Found %(count)s %(mysite)s processes running, including this one." % locals()) finally: self.lock.release() @@ -156,7 +163,7 @@ thisdelay = self.writedelay else: thisdelay = self.delay - if pid: # If set, we're checking for multiple processes + if pid and self.multiplydelay: # We're checking for multiple processes if time.time() > self.checktime + self.checkdelay: self.checkMultiplicity() if thisdelay < (self.mindelay * self.next_multiplicity): @@ -203,14 +210,17 @@ continue # Sometimes the file gets corrupted # ignore that line if now - ptime <= self.releasepid \ - and this_pid != pid: + and this_pid != pid: processes.append({'pid': this_pid, 'time': ptime, 'site': this_site}) - f = open(self.ctrlfilename, 'w') processes.sort(key=lambda p:p['pid']) - for p in processes: - f.write("%(pid)s %(time)s %(site)s\n" % p) + try: + f = open(self.ctrlfilename, 'w') + for p in processes: + f.write("%(pid)s %(time)s %(site)s\n" % p) + except IOError: + pass f.close()
def __call__(self, requestsize=1, write=False): @@ -235,10 +245,10 @@ # Announce the delay if it exceeds a preset limit if wait > config.noisysleep: pywikibot.output(u"Sleeping for %(wait).1f seconds, %(now)s" - % {'wait': wait, - 'now': time.strftime("%Y-%m-%d %H:%M:%S", + % {'wait': wait, + 'now' : time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) - } ) + } ) time.sleep(wait) if write: self.last_write = time.time() @@ -264,11 +274,11 @@ if wait > 0: if wait > config.noisysleep: pywikibot.output( - u"Sleeping for %(wait).1f seconds, %(now)s" - % {'wait': wait, - 'now': time.strftime("%Y-%m-%d %H:%M:%S", - time.localtime()) - } ) + u"Sleeping for %(wait).1f seconds, %(now)s" + % {'wait': wait, + 'now': time.strftime("%Y-%m-%d %H:%M:%S", + time.localtime()) + } ) time.sleep(wait) finally: self.lock.release()
pywikipedia-svn@lists.wikimedia.org