Revision: 7570
Author: russblau
Date: 2009-10-29 19:06:13 +0000 (Thu, 29 Oct 2009)
Log Message:
-----------
further upload-by-url code; this option doesn't seem to be working on the server side
Modified Paths:
--------------
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-10-29 18:05:43 UTC (rev 7569)
+++ branches/rewrite/pywikibot/site.py 2009-10-29 19:06:13 UTC (rev 7570)
@@ -28,6 +28,7 @@
import re
import sys
import threading
+import time
import urllib
logger = logging.getLogger("pywiki.wiki.site")
@@ -2618,6 +2619,8 @@
raise pywikibot.Error(
"User '%s' is not authorized to upload by URL on site
%s."
% (self.user(), self))
+ # doesn't work yet
+ raise NotImplementedError("Upload by URL not yet implemented")
req = api.Request(site=self, action="upload", token=token,
filename=imagepage.title(withNamespace=False),
url=source_url, comment=comment)
@@ -2632,6 +2635,26 @@
raise
result = result["upload"]
pywikibot.output(result, level=pywikibot.DEBUG)
+ if source_url:
+ # get session key from result
+ key = result["upload_session_key"]
+ pywikibot.output(u"Asynchronous upload started.")
+ time.sleep(1)
+ while True:
+ # get upload status
+ statusrequest = api.Request(site=self, action="upload",
+ token=token, httpstatus="",
+ sessionkey=str(key))
+ status = statusrequest.submit()
+ status = status["upload"]
+ if int(status["loaded"]) !=
int(status["content_length"]):
+ pywikibot.output(
+ u" %(loaded)s out of %(content_length)s bytes loaded..."
+ % status)
+ continue
+ # notify the user, since I have no idea what else to do at this point
+ pywikibot.output(str(status))
+ return
if "warnings" in result:
warning = result["warnings"].keys()[0]
message = result["warnings"][warning]
@@ -2639,7 +2662,7 @@
% {'msg': message})
else:
pywikibot.output(u"Upload: unrecognized response: %s"
- % result["result"])
+ % result)
if result["result"] == "Success":
pywikibot.output(u"Upload successful.")
imagepage._imageinfo = result["imageinfo"]
Show replies by date