Revision: 6455
Author: nicdumz
Date: 2009-02-28 22:47:55 +0000 (Sat, 28 Feb 2009)
Log Message:
-----------
Deprecating family.server_time(), introducing Site.getcurrenttime()
Modified Paths:
--------------
branches/rewrite/pywikibot/family.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/family.py
===================================================================
--- branches/rewrite/pywikibot/family.py 2009-02-28 17:06:03 UTC (rev 6454)
+++ branches/rewrite/pywikibot/family.py 2009-02-28 22:47:55 UTC (rev 6455)
@@ -7,7 +7,7 @@
import re
import urllib
-from datetime import datetime, timedelta
+import pywikibot
logger = logging.getLogger("wiki.family")
@@ -49,10 +49,10 @@
]
self.langs = {}
- # The timedelta to GMT of the server.
- # Exemple for a server running CET :
- # timedelta(hours=+1)
- self.servergmtoffset = timedelta()
+## # The timedelta to GMT of the server.
+## # Exemple for a server running CET :
+## # timedelta(hours=+1)
+## self.servergmtoffset = timedelta()
# letters that can follow a wikilink and are regarded as part of
# this link # This depends on the linktrail setting in LanguageXx.php and on # [[MediaWiki:Linktrail]].
@@ -1005,9 +1005,11 @@
return (None, None)
def server_time(self, code):
- """Return a datetime object representing server time"""
- # TODO : If the local computer time is wrong, result will be wrong
- return datetime.utcnow() + self.servergmtoffset
+ """
+ DEPRECATED, use Site.getcurrenttime() instead
+ Return a datetime object representing server time"""
+ pywikibot.deprecated("Site.getcurrenttime()")
+ return pywikibot.Site(code, self).getcurrenttime()
def isPublic(self, code):
"""Does the wiki require logging in before viewing it?"""
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-02-28 17:06:03 UTC (rev 6454)
+++ branches/rewrite/pywikibot/site.py 2009-02-28 22:47:55 UTC (rev 6455)
@@ -28,6 +28,7 @@
import sys
import threading
import urllib
+from datetime import datetime
logger = logging.getLogger("wiki.site")
@@ -789,6 +790,11 @@
result = r.submit()
return re.search('\d+', result['parse']['text']['*']).group()
+ def getcurrenttime(self):
+ """Returns a datetime object representing server time"""
+ ts = self.getcurrenttimestamp()
+ return datetime.strptime(ts, "%Y%m%d%H%M%S")
+
def _getsiteinfo(self):
"""Retrieve siteinfo and namespaces from site."""
sirequest = api.Request(
Bugs item #2636116, was opened at 2009-02-25 07:41
Message generated for change (Comment added) made by nobody
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2636116&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: outdated family file on sah-wiki
Initial Comment:
There are outdated namespaces [-2] and [9] on sah-wiki. (family.py r6421)
<w:de:user:xqt>
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2009-02-28 14:51
Message:
Here are some others (py version r6443):
ml-wiki namespace 14..15
dv-wiki namespace 6..13
ps-wiki namespace 6..7
za-wiki namespace -2..15
<w:de:user:xqt>
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2636116&group_…
Revision: 6449
Author: russblau
Date: 2009-02-27 16:55:46 +0000 (Fri, 27 Feb 2009)
Log Message:
-----------
add Category.members() method to generate both subcategories and articles;
fix problems with templatesWithParams() methods;
default to groups of 50 when preloading;
fix output formatting problems and other minor bugs
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2009-02-27 16:53:22 UTC (rev 6448)
+++ branches/rewrite/pywikibot/__init__.py 2009-02-27 16:55:46 UTC (rev 6449)
@@ -33,10 +33,12 @@
classname = f.f_locals['self'].__class__.__name__
funcname = f.f_code.co_name
if instead:
- logging.warning("%s.%s is DEPRECATED, use %s instead" % \
- (classname, funcname, instead))
+ output(u"%s.%s is DEPRECATED, use %s instead."
+ % (classname, funcname, instead),
+ level=WARNING)
else:
- logging.warning("%s.%s is DEPRECATED." % (classname, funcname))
+ output(u"%s.%s is DEPRECATED." % (classname, funcname),
+ level=WARNING)
def deprecate_arg(old_arg, new_arg):
"""Decorator to declare old_arg deprecated and replace it with new_arg"""
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2009-02-27 16:53:22 UTC (rev 6448)
+++ branches/rewrite/pywikibot/page.py 2009-02-27 16:55:46 UTC (rev 6449)
@@ -808,11 +808,22 @@
parameters as the second entry.
"""
+ # WARNING: may not return all templates used in particularly
+ # intricate cases such as template substitution
+ titles = list(t.title() for t in self.templates())
templates = pywikibot.extract_templates_and_params(self.text)
# backwards-compatibility: convert the dict returned as the second
# element into a list in the format used by old scripts
result = []
for template in templates:
+ link = pywikibot.Link(template[0], self.site(),
+ defaultNamespace=10)
+ try:
+ if link.canonical_title() not in titles:
+ continue
+ except pywikibot.Error:
+ # this is a parser function or magic word, not template name
+ continue
args = template[1]
positional = []
named = {}
@@ -825,10 +836,7 @@
positional.append(args[key])
for name in named:
positional.append("%s=%s" % (name, named[name]))
- result.append((pywikibot.Page(
- pywikibot.Link(template[0], self.site(),
- defaultNamespace=10)),
- positional))
+ result.append((pywikibot.Page(link, self.site()), positional))
return result
@deprecate_arg("nofollow_redirects", None)
@@ -1425,6 +1433,17 @@
for article in subcat.articles(recurse):
yield article
+ def members(self, recurse=False):
+ """Yield all category contents (subcats, pages, and files)."""
+ for member in self.site().categorymembers(self):
+ yield member
+ if recurse:
+ if not isinstance(recurse, bool) and recurse:
+ recurse = recurse - 1
+ for subcat in self.subcategories():
+ for article in subcat.members(recurse):
+ yield article
+
def isEmptyCategory(self):
"""Return True if category has no members (including subcategories)."""
for member in self.site().categorymembers(self, limit=1):
@@ -1802,7 +1821,8 @@
# "empty" local links can only be self-links
# with a fragment identifier.
if not t and self._site == self._source and self._namespace != 0:
- raise ValueError("Invalid link (no page title): '%s'" % self._text)
+ raise pywikibot.Error("Invalid link (no page title): '%s'"
+ % self._text)
self._title = t
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-02-27 16:53:22 UTC (rev 6448)
+++ branches/rewrite/pywikibot/site.py 2009-02-27 16:55:46 UTC (rev 6449)
@@ -1,4 +1,4 @@
- # -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
"""
Objects representing MediaWiki sites (wikis) and families (groups of wikis
on the same topic in different languages).
@@ -994,7 +994,7 @@
api.update_page(target, pagedata)
page._redir = target
- def preloadpages(self, pagelist, groupsize=60):
+ def preloadpages(self, pagelist, groupsize=50):
"""Return a generator to a list of preloaded pages.
Note that [at least in current implementation] pages may be iterated
@@ -1401,10 +1401,12 @@
def categoryinfo(self, category):
if not hasattr(category, "_catinfo"):
self.getcategoryinfo(category)
+ if not hasattr(category, "_catinfo"):
+ # a category that exists but has no contents returns no API result
+ return {'size':0, 'pages':0, 'files':0, 'subcats':0}
return category._catinfo
@deprecate_arg("throttle", None)
- @deprecate_arg("includeredirects", "filterredir")
def allpages(self, start="!", prefix="", namespace=0, filterredir=None,
filterlanglinks=None, minsize=None, maxsize=None,
protect_type=None, protect_level=None, limit=None,
Revision: 6448
Author: russblau
Date: 2009-02-27 16:53:22 +0000 (Fri, 27 Feb 2009)
Log Message:
-----------
some wikis seem to have a problem with more than 50 titles in a request
Modified Paths:
--------------
branches/rewrite/pywikibot/pagegenerators.py
Modified: branches/rewrite/pywikibot/pagegenerators.py
===================================================================
--- branches/rewrite/pywikibot/pagegenerators.py 2009-02-27 13:39:21 UTC (rev 6447)
+++ branches/rewrite/pywikibot/pagegenerators.py 2009-02-27 16:53:22 UTC (rev 6448)
@@ -647,7 +647,7 @@
yield page.toggleTalkPage()
-def PreloadingGenerator(generator, pageNumber=60, lookahead=10):
+def PreloadingGenerator(generator, pageNumber=50, lookahead=10):
"""Yield preloaded pages taken from another generator."""
# pages may be on more than one site, for example if an interwiki