def wrapper(*args, **kwargs): funcname = method.__name__ classname = args[0].__class__.__name__ if instead: warning(u"%s.%s is DEPRECATED, use %s instead." % (classname, funcname, instead)) else: warning(u"%s.%s is DEPRECATED." % (classname, funcname)) return method(*args, **kwargs)
def treat_page(self): try: self.process_page(self.current_page) except NotEligible as e: bot.log(str(e)) except TooManyTemplates as e: bot.log(str(e)) except MinorProblem as e: bot.warning(str(e)) except MajorProblem as e: bot.error(str(e))
def on_change(self, change): debug('Received change %r' % change, _logger) if not thread.running: debug('Thread in shutdown mode; ignoring change.', _logger) return thread.count += 1 thread.queue.put(change) if thread.queue.qsize() > thread.warn_queue_length: warning('%r queue length exceeded %i' % (thread, thread.warn_queue_length), _logger=_logger) thread.warn_queue_length = thread.warn_queue_length + 100 if thread.total is not None and thread.count >= thread.total: thread.stop() return
def on_change(self, change): debug('Received change {0!r}'.format(change), _logger) if not thread.running: debug('Thread in shutdown mode; ignoring change.', _logger) return thread.count += 1 thread.queue.put(change) if thread.queue.qsize() > thread.warn_queue_length: warning('{0!r} queue length exceeded {1:d}'.format(thread, thread.warn_queue_length), _logger=_logger) thread.warn_queue_length = thread.warn_queue_length + 100 if thread.total is not None and thread.count >= thread.total: thread.stop() return
def wrapper(*__args, **__kw): meth_name = method.__name__ if old_arg in __kw: if new_arg: if new_arg in __kw: warning( u"%(new_arg)s argument of %(meth_name)s replaces %(old_arg)s; cannot use both." % locals()) else: warning( u"%(old_arg)s argument of %(meth_name)s is deprecated; use %(new_arg)s instead." % locals()) __kw[new_arg] = __kw[old_arg] else: debug( u"%(old_arg)s argument of %(meth_name)s is deprecated." % locals(), _logger) del __kw[old_arg] return method(*__args, **__kw)
def treat_page(self): try: gridimage_id = -1 if hasattr(self.current_page, 'gridimage_id'): gridimage_id = self.current_page.gridimage_id if self.current_page.namespace() != 6: return # Not a file page self.process_page(FilePage(self.current_page)) except NotEligible as e: print("%d: %s" % (gridimage_id, str(e)), file=whynot) bot.log(str(e)) except MinorProblem as e: print("%d: %s" % (gridimage_id, str(e)), file=whynot) bot.warning(str(e)) except MajorProblem as e: print("%d: %s" % (gridimage_id, str(e)), file=whynot) bot.error(str(e)) except HTTPError as e: print("%d: %s" % (gridimage_id, str(e)), file=whynot) bot.error(str(e))
def Site(code=None, fam=None, user=None, sysop=None, interface=None, url=None): """A factory method to obtain a Site object. Site objects are cached and reused by this method. By default rely on config settings. These defaults may all be overridden using the method parameters. @param code: language code (override config.mylang) @type code: string @param fam: family name or object (override config.family) @type fam: string or Family @param user: bot user name to use on this site (override config.usernames) @type user: unicode @param sysop: sysop user to use on this site (override config.sysopnames) @type sysop: unicode @param interface: site class or name of class in pywikibot.site (override config.site_interface) @type interface: subclass of L{pywikibot.site.BaseSite} or string @param url: Instead of code and fam, does try to get a Site based on the URL. Still requires that the family supporting that URL exists. @type url: string """ # Either code and fam or only url assert (not url or (not code and not fam)) _logger = "wiki" if url: if url in _url_cache: cached = _url_cache[url] if cached: code = cached[0] fam = cached[1] else: raise SiteDefinitionError("Unknown URL '{0}'.".format(url)) else: # Iterate through all families and look, which does apply to # the given URL for fam in config.family_files: try: family = pywikibot.family.Family.load(fam) code = family.from_url(url) if code: _url_cache[url] = (code, fam) break except Exception as e: pywikibot.warning('Error in Family(%s).from_url: %s' % (fam, e)) else: _url_cache[url] = None # TODO: As soon as AutoFamily is ready, try and use an # AutoFamily raise SiteDefinitionError("Unknown URL '{0}'.".format(url)) else: # Fallback to config defaults code = code or config.mylang fam = fam or config.family interface = interface or config.site_interface # config.usernames is initialised with a dict for each family name family_name = str(fam) if family_name in config.usernames: user = user or config.usernames[family_name].get(code) \ or config.usernames[family_name].get('*') sysop = sysop or config.sysopnames[family_name].get(code) \ or config.sysopnames[family_name].get('*') if not isinstance(interface, type): # If it isnt a class, assume it is a string try: tmp = __import__('pywikibot.site', fromlist=[interface]) interface = getattr(tmp, interface) except ImportError: raise ValueError("Invalid interface name '%(interface)s'" % locals()) if not issubclass(interface, pywikibot.site.BaseSite): warning('Site called with interface=%s' % interface.__name__) user = pywikibot.tools.normalize_username(user) key = '%s:%s:%s:%s' % (interface.__name__, fam, code, user) if key not in _sites or not isinstance(_sites[key], interface): _sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop) debug( u"Instantiated %s object '%s'" % (interface.__name__, _sites[key]), _logger) if _sites[key].code != code: warn( 'Site %s instantiated using different code "%s"' % (_sites[key], code), UserWarning, 2) return _sites[key]
def Site(code=None, fam=None, user=None, sysop=None, interface=None, url=None): """A factory method to obtain a Site object. Site objects are cached and reused by this method. By default rely on config settings. These defaults may all be overriden using the method parameters. @param code: language code (override config.mylang) @type code: string @param fam: family name or object (override config.family) @type fam: string or Family @param user: bot user name to use on this site (override config.usernames) @type user: unicode @param sysop: sysop user to use on this site (override config.sysopnames) @type sysop: unicode @param interface: site class or name of class in pywikibot.site (override config.site_interface) @type interface: subclass of L{pywikibot.site.BaseSite} or string @param url: Instead of code and fam, does try to get a Site based on the URL. Still requires that the family supporting that URL exists. @type url: string """ # Either code and fam or only url assert(not url or (not code and not fam)) _logger = "wiki" if url: if url in _url_cache: cached = _url_cache[url] if cached: code = cached[0] fam = cached[1] else: raise Error("Unknown URL '{0}'.".format(url)) else: # Iterate through all families and look, which does apply to # the given URL for fam in config.family_files: family = pywikibot.family.Family.load(fam) code = family.from_url(url) if code: _url_cache[url] = (code, fam) break else: _url_cache[url] = None # TODO: As soon as AutoFamily is ready, try and use an # AutoFamily raise Error("Unknown URL '{0}'.".format(url)) else: # Fallback to config defaults code = code or config.mylang fam = fam or config.family interface = interface or config.site_interface # config.usernames is initialised with a dict for each family name family_name = str(fam) if family_name in config.usernames: user = user or config.usernames[family_name].get(code) \ or config.usernames[family_name].get('*') sysop = sysop or config.sysopnames[family_name].get(code) \ or config.sysopnames[family_name].get('*') if not isinstance(interface, type): # If it isnt a class, assume it is a string try: tmp = __import__('pywikibot.site', fromlist=[interface]) interface = getattr(tmp, interface) except ImportError: raise ValueError("Invalid interface name '%(interface)s'" % locals()) if not issubclass(interface, pywikibot.site.BaseSite): warning('Site called with interface=%s' % interface.__name__) key = '%s:%s:%s:%s' % (interface.__name__, fam, code, user) if key not in _sites or not isinstance(_sites[key], interface): _sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop) debug(u"Instantiated %s object '%s'" % (interface.__name__, _sites[key]), _logger) return _sites[key]
def Site(code=None, fam=None, user=None, sysop=None, interface=None, url=None): """A factory method to obtain a Site object. Site objects are cached and reused by this method. By default rely on config settings. These defaults may all be overridden using the method parameters. @param code: language code (override config.mylang) @type code: string @param fam: family name or object (override config.family) @type fam: string or Family @param user: bot user name to use on this site (override config.usernames) @type user: unicode @param sysop: sysop user to use on this site (override config.sysopnames) @type sysop: unicode @param interface: site class or name of class in pywikibot.site (override config.site_interface) @type interface: subclass of L{pywikibot.site.BaseSite} or string @param url: Instead of code and fam, does try to get a Site based on the URL. Still requires that the family supporting that URL exists. @type url: string """ # Either code and fam or only url if url and (code or fam): raise ValueError('URL to the wiki OR a pair of code and family name ' 'should be provided') _logger = "wiki" if url: if url not in _url_cache: matched_sites = [] # Iterate through all families and look, which does apply to # the given URL for fam in config.family_files: family = pywikibot.family.Family.load(fam) code = family.from_url(url) if code is not None: matched_sites += [(code, fam)] if matched_sites: if len(matched_sites) > 1: pywikibot.warning( 'Found multiple matches for URL "{0}": {1} (use first)' .format(url, ', '.join(str(s) for s in matched_sites))) _url_cache[url] = matched_sites[0] else: # TODO: As soon as AutoFamily is ready, try and use an # AutoFamily _url_cache[url] = None cached = _url_cache[url] if cached: code = cached[0] fam = cached[1] else: raise SiteDefinitionError("Unknown URL '{0}'.".format(url)) else: # Fallback to config defaults code = code or config.mylang fam = fam or config.family interface = interface or config.site_interface # config.usernames is initialised with a dict for each family name family_name = str(fam) if family_name in config.usernames: user = user or config.usernames[family_name].get(code) \ or config.usernames[family_name].get('*') sysop = sysop or config.sysopnames[family_name].get(code) \ or config.sysopnames[family_name].get('*') if not isinstance(interface, type): # If it isnt a class, assume it is a string try: tmp = __import__('pywikibot.site', fromlist=[interface]) interface = getattr(tmp, interface) except ImportError: raise ValueError("Invalid interface name '%(interface)s'" % locals()) if not issubclass(interface, pywikibot.site.BaseSite): warning('Site called with interface=%s' % interface.__name__) user = pywikibot.tools.normalize_username(user) key = '%s:%s:%s:%s' % (interface.__name__, fam, code, user) if key not in _sites or not isinstance(_sites[key], interface): _sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop) debug(u"Instantiated %s object '%s'" % (interface.__name__, _sites[key]), _logger) if _sites[key].code != code: warn('Site %s instantiated using different code "%s"' % (_sites[key], code), UserWarning, 2) return _sites[key]
def treat_page(self): t = mwparserfromhell.parse(self.current_page.text) info = tlgetone(t, infoboxes) others = [f for f in otherfieldses if info.has(f)] if len(others) > 1: bot.warning("excess other_fields in %s" % (self.current_page, ))