def update(): scriptpage = Page(site, "User:Legoktm/BOTFAQ/Code/redir.py") text = file('redir.py').read() text = '<source lang="python">\n' + text + '</sou' + 'rce>' # Split to confuse MW parser if scriptpage.get() != text: summary = 'Updating source' scriptpage.put(text, summary)
# recompute and substitute that at each entry into this loop. imgidx = 0 for i in range(0,len(wikilines)): if re_imagematch.search(wikilines[i]): wikilines[i] = re_imagematch.sub('[[Image:%s_%s.%s]]' % (outname, imgidx, images[imgidx].extension()), wikilines[i]) imgidx += 1 if imgidx != len(images): # Mismatch between found images and found image tags print "Did not find match for all images!" sys.exit(1) # Attempt the base page upload with IOWrapper("Uploading page..."): try: p = Page(site, outname) p.put(''.join(wikilines), comment='Uploaded by word2mediawiki', minorEdit=True, force=True) except PageNotSaved: # Ok, failed. So let's retry with another name continue # Now that the page is created, we will no longer be able to retry # with a better name, so let's just abort if things fail from here on. # Thus, drop out of the loop break # Upload the base document, assuming nobody else has uploaded a document # between us checking it and actuall uploading. with IOWrapper("Uploading base document..."): bot = UploadRobot(inputfile, description='Uploaded by word2mediawiki', useFilename="%s.%s" % (outname, docextension),