jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/356987 )
Change subject: FilePage.download(): add revision parameter to download arbitrary
revision
......................................................................
FilePage.download(): add revision parameter to download arbitrary revision
The parameter will default to the latest revision when unprovided,
so that this method remain backwards-compatiable. The revision
(instance of FileInfo) will provide the url and sha1 for the download
and verification process.
Bug: T166939
Change-Id: I25842ae4276fbb45ba69a31d66b67401723e3ee5
---
M pywikibot/page.py
1 file changed, 14 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 78c2f79..ddd24d9 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2634,7 +2634,7 @@
return self.site.upload(self, source_filename=filename, source_url=url,
**kwargs)
- def download(self, filename=None, chunk_size=100 * 1024):
+ def download(self, filename=None, chunk_size=100 * 1024, revision=None):
"""
Download to filename file of FilePage.
@@ -2642,7 +2642,14 @@
None: self.title(as_filename=True, withNamespace=False)
will be used
str: provided filename will be used.
- @type None or str
+ @type filename: None or str
+ @param chunk_size: the size of each chunk to be received and
+ written to file.
+ @type chunk_size: int
+ @param revision: file revision to download:
+ None: self.latest_file_info will be used
+ FileInfo: provided revision will be used.
+ @type revision: None or FileInfo
@return: True if download is successful, False otherwise.
@raise: IOError if filename cannot be written for any reason.
"""
@@ -2651,7 +2658,10 @@
filename = os.path.expanduser(filename)
- req = http.fetch(self.latest_file_info.url, stream=True)
+ if revision is None:
+ revision = self.latest_file_info
+
+ req = http.fetch(revision.url, stream=True)
if req.status == 200:
try:
with open(filename, 'wb') as f:
@@ -2661,7 +2671,7 @@
raise e
sha1 = compute_file_hash(filename)
- return sha1 == self.latest_file_info.sha1
+ return sha1 == revision.sha1
else:
pywikibot.warning('Unsuccesfull request (%s): %s' % (req.status,
req.uri))
return False
--
To view, visit
https://gerrit.wikimedia.org/r/356987
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I25842ae4276fbb45ba69a31d66b67401723e3ee5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>