Revision: 5962 Author: jayvdb Date: 2008-10-14 03:07:44 +0000 (Tue, 14 Oct 2008)
Log Message: ----------- Verify djvu file exists and detect index page name.
Modified Paths: -------------- trunk/pywikipedia/djvutext.py
Modified: trunk/pywikipedia/djvutext.py =================================================================== --- trunk/pywikipedia/djvutext.py 2008-10-14 00:19:59 UTC (rev 5961) +++ trunk/pywikipedia/djvutext.py 2008-10-14 03:07:44 UTC (rev 5962) @@ -161,6 +161,7 @@
def main(): + import os index = None djvu = None pages = None @@ -183,16 +184,33 @@ else: print "Unknown argument %s" % arg
+ # Check the djvu file exists + os.stat(djvu) + + if not index: + import os.path + index = os.path.basename(djvu) + if djvu and index: - index_page = wikipedia.Page(wikipedia.getSite(), index) - if not index_page.exists(): - wikipedia.output("%s does not exist" % index) - raise Exception + site = wikipedia.getSite() + index_page = wikipedia.Page(site, index)
- wikipedia.output("uploading text from %s to %s" % (djvu, index) ) + if site.family.name != 'wikisource': + raise wikipedia.PageNotFound("Found family '%s'; Wikisource required.")
+ if not index_page.exists() and index_page.namespace() == 0: + index_namespace = wikipedia.Page(site, 'MediaWiki:Proofreadpage index namespace').get() + + index_page = wikipedia.Page(wikipedia.getSite(), + u"%s:%s" % (index_namespace, index)) + + if not index_page.exists(): + raise wikipedia.NoPage("Page '%s' does not exist" % index) + + wikipedia.output("uploading text from %s to %s" % (djvu, index_page) ) + bot = DjVuTextBot(djvu, index, pages) - bot.ask = ask + bot.ask = ask bot.run() else: wikipedia.showHelp()