Revision: 6486
Author: nicdumz
Date: 2009-03-04 07:38:10 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
implementing BlockEntry methods.
Modified Paths:
--------------
branches/rewrite/pywikibot/data/logentries.py
Modified: branches/rewrite/pywikibot/data/logentries.py
===================================================================
--- branches/rewrite/pywikibot/data/logentries.py 2009-03-04 01:43:01 UTC (rev 6485)
+++ branches/rewrite/pywikibot/data/logentries.py 2009-03-04 07:38:10 UTC (rev 6486)
@@ -14,11 +14,14 @@
from pywikibot import date
class LogDict(dict):
- """Simple custom dictionary that raises a custom Error instead of a KeyError"""
+ """
+ Simple custom dictionary that raises a custom KeyError and logs
+ debugging information when a key is missing
+ """
def __missing__(self, key):
pywikibot.output(u"API log entry received:\n" + repr(self),
level=pywikibot.DEBUG)
- raise Error("Log entry has no '%s' key" % key)
+ raise KeyError("Log entry has no '%s' key" % key, key)
class LogEntry(object):
"""Generic log entry"""
@@ -71,7 +74,75 @@
class BlockEntry(LogEntry):
_expectedType = 'block'
+ def __init__(self, apidata):
+ super(BlockEntry, self).__init__(apidata)
+ # see http://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&… :
+ # When an autoblock is removed, the "title" field is not a page title
+ # ( https://bugzilla.wikimedia.org/show_bug.cgi?id=17781 )
+ pos = self.data['title'].find('#')
+ self.isAutoblockRemoval = pos > 0
+ if self.isAutoblockRemoval:
+ self._blockid = int(self.data['title'][pos+1:])
+ def title(self):
+ """
+ * Returns the Page object of username or IP
+ if this block action targets a username or IP.
+ * Returns the blockid if this log reflects the removal of an autoblock
+ """
+ #TODO what for IP ranges ?
+ if self.isAutoblockRemoval:
+ return self._blockid
+ else:
+ return super(BlockEntry, self).title()
+
+ def isAutoblockRemoval(self):
+ return self.isAutoblockRemoval
+
+ def _getBlockDetails(self):
+ try:
+ return self.data['block']
+ except KeyError:
+ # No 'block' key means this is an unblocking log entry
+ if self.action() == 'unblock':
+ raise Error("action='unblock': this log entry has no block details such as flags, duration, or expiry!")
+ raise
+
+ def flags(self):
+ """
+ Returns a list of (str) flags associated with the block entry.
+ Raises an Error if the entry is an unblocking log entry
+ """
+ if hasattr(self, '_flags'):
+ return self._flags
+ self._flags = self._getBlockDetails()['flags'].split(',')
+ return self._flags
+
+ def duration(self):
+ """
+ Returns a datetime.timedelta representing the block duration,
+ or None if block is indefinite
+ Raises an Error if the entry is an unblocking log entry
+ """
+ if hasattr(self, '_duration'):
+ return self._duration
+ if self._getBlockDetails()['duration'] == 'indefinite':
+ self._duration = None
+ else:
+ # Doing the difference is easier than parsing the string
+ self._duration = self.expiry() - self.timestamp()
+ return self._duration
+
+ def expiry(self):
+ """
+ Returns a datetime.datetime representing the block expiry date
+ Raises an Error if the entry is an unblocking log entry
+ """
+ if hasattr(self, '_expiry'):
+ return self._expiry
+ self._expiry = date.ISO2datetime(self._getBlockDetails()['expiry'])
+ return self._expiry
+
class ProtectEntry(LogEntry):
_expectedType = 'protect'
Revision: 6485
Author: nicdumz
Date: 2009-03-04 01:43:01 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
Implememting MoveEntry methods
Modified Paths:
--------------
branches/rewrite/pywikibot/data/logentries.py
Modified: branches/rewrite/pywikibot/data/logentries.py
===================================================================
--- branches/rewrite/pywikibot/data/logentries.py 2009-03-03 22:45:15 UTC (rev 6484)
+++ branches/rewrite/pywikibot/data/logentries.py 2009-03-04 01:43:01 UTC (rev 6485)
@@ -87,6 +87,25 @@
class MoveEntry(LogEntry):
_expectedType = 'move'
+ def new_ns(self):
+ return self.data['move']['new_ns']
+
+ def new_title(self):
+ """Page object of the new title"""
+ if not hasattr(self, '_new_title'):
+ self._new_title = pywikibot.Page(pywikibot.Link( \
+ self.data['move']['new_title']))
+ return self._new_title
+
+ def suppressedredirect(self):
+ """
+ Returns True if no redirect was created from the old title
+ to the new title during the move
+ """
+ # Introduced in MW r47901, not yet live on WM sites.
+ return self.data['move'].has_key('suppressedredirect')
+
+
class ImportEntry(LogEntry):
_expectedType = 'import'
Feature Requests item #2658361, was opened at 2009-03-03 18:45
Message generated for change (Comment added) made by purodha
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603141&aid=2658361&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: interwiki
Group: None
>Status: Closed
Priority: 4
Private: No
Submitted By: Purodha B Blissenbach (purodha)
>Assigned to: Purodha B Blissenbach (purodha)
Summary: store language in file without_interwiki.txt
Initial Comment:
When saving page names to file without_interwiki.txt , language prfixes should be
stored as well. The list is extended by every bot run if nothing special is done to
prevent that. Since each bot run can be having another target directory, the
cumulated data is not very useful unless the language is included.
----------------------------------------------------------------------
>Comment By: Purodha B Blissenbach (purodha)
Date: 2009-03-03 22:15
Message:
Done with revision 6482.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603141&aid=2658361&group_…
Revision: 6481
Author: russblau
Date: 2009-03-03 18:48:44 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
fix sorting problem (if the pages come in the form of a dict, there is no way to recover the original order in which the API returned them, so we sort by the dict's keys for lack of a better option)
Modified Paths:
--------------
branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2009-03-03 16:50:18 UTC (rev 6480)
+++ branches/rewrite/pywikibot/data/api.py 2009-03-03 18:48:44 UTC (rev 6481)
@@ -443,9 +443,7 @@
logger.debug(u"%s received %s; limit=%s"
% (self.__class__.__name__, pagedata.keys(),
self.limit))
- pagedata = pagedata.values()
- if self.resultkey == "pages":
- pagedata.sort(key=lambda i:int(i["pageid"]))
+ pagedata = [pagedata[k] for k in sorted(pagedata.keys())]
else:
logger.debug(u"%s received %s; limit=%s"
% (self.__class__.__name__, pagedata, self.limit))
Feature Requests item #2658361, was opened at 2009-03-03 18:45
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603141&aid=2658361&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: interwiki
Group: None
Status: Open
Priority: 4
Private: No
Submitted By: Purodha B Blissenbach (purodha)
Assigned to: Nobody/Anonymous (nobody)
Summary: store language in file without_interwiki.txt
Initial Comment:
When saving page names to file without_interwiki.txt , language prfixes should be
stored as well. The list is extended by every bot run if nothing special is done to
prevent that. Since each bot run can be having another target directory, the
cumulated data is not very useful unless the language is included.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603141&aid=2658361&group_…