http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10640
Revision: 10640
Author: xqt
Date: 2012-11-01 13:52:18 +0000 (Thu, 01 Nov 2012)
Log Message:
-----------
new site methods:
- has_image_repository returns True if site has a shared image repository like commons
- has_data_repository returns True if site has a shared data repository like wikidata
- image_repository() returns the image repository site object i.e. commons
- data_repository() returns the data repository site object i.e. wikidata
Both repository methods returns None if no repository is assigned to a site.
Now there is only one wikidata client ("wikidata:client") and it's repository is "wikidata:repo"
Modified Paths:
--------------
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2012-11-01 12:19:32 UTC (rev 10639)
+++ branches/rewrite/pywikibot/site.py 2012-11-01 13:52:18 UTC (rev 10640)
@@ -37,7 +37,7 @@
class LoginStatus(object):
""" Enum for Login statuses.
-
+
>>> LoginStatus.NOT_ATTEMPTED
-3
>>> LoginStatus.AS_USER
@@ -1031,6 +1031,36 @@
lang = property(fget=language, doc=language.__doc__)
+ @property
+ def has_image_repository(self):
+ """Return True if site has a shared image repository like commons"""
+ code, fam = self.family.shared_image_repository(self.code)
+ return bool(code or fam)
+
+ @property
+ def has_data_repository(self):
+ """Return True if site has a shared image repository like wikidata"""
+ code, fam = self.family.shared_data_repository(self.code)
+ return bool(code or fam)
+
+ def image_repository(self):
+ """Return Site object for image repository e.g. commons."""
+
+ code, fam = self.family.shared_image_repository(self.code)
+ if bool(code or fam):
+ return pywikibot.Site(code, fam, self.user())
+ else:
+ return None
+
+ def data_repository(self):
+ """Return Site object for data repository e.g. wikidata."""
+
+ code, fam = self.family.shared_data_repository(self.code)
+ if bool(code or fam):
+ return pywikibot.Site(code, fam, self.user())
+ else:
+ return None
+
def nice_get_address(self, title):
"""Return shorter URL path to retrieve page titled 'title'."""
# 'title' is expected to be URL-encoded already
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10639
Revision: 10639
Author: xqt
Date: 2012-11-01 12:19:32 +0000 (Thu, 01 Nov 2012)
Log Message:
-----------
shared_data_repository depends on code
Modified Paths:
--------------
branches/rewrite/pywikibot/families/wikidata_family.py
Modified: branches/rewrite/pywikibot/families/wikidata_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikidata_family.py 2012-11-01 12:12:57 UTC (rev 10638)
+++ branches/rewrite/pywikibot/families/wikidata_family.py 2012-11-01 12:19:32 UTC (rev 10639)
@@ -18,4 +18,4 @@
def shared_data_repository(self, code):
# for here an now we just use the test repo
# for wikimedia families the method can return wikidata itself
- return ('repo', 'wikidata')
+ return ('repo', 'wikidata') if code == 'client' else (None, None)