- This is a personal developmental wiki, it may often be in an unstable or experimental state and the lack of meaningful content on a page is often intentional; however, you can participate. Please: 1) create an account, 2) confirm your e-mail, 3) send Deirdre and e-mail telling her who you are and why you are interested. Thanks, --Deirdre(talk contribs)

Miszatest

From DeeDeeswiki
Revision as of 21:37, 3 December 2011 by Deirdre (Talk | contribs) (wrap in pre)

Jump to: navigation, search
#!/usr/bin/env python

import sys, os
sys.stderr = sys.stdout

import cgitb
cgitb.enable()

from cgi import escape

print "Content-type: text/html"
print

import urllib, re
import monobook, misza

DST_PREFIX = 'Python:'
UPDATE = u"""{{update|file=%(file)s|rev=%(rev)s|sig=[[User:Doug|Doug.]]<sup>([[User talk:Doug|talk]] <small>•</small> [[Special:Contributions/Doug|contribs]])</sup> 21:37, 3 December 2011 (EST)|wikirev=}}

<source lang="python">
%(newdata)s
</source>
"""

def update(site, filename):
    par = {
            'site' : 'http://svn.wikimedia.org',
            'module' : '/viewvc/pywikipedia/trunk/pywikipedia',
            'file' : filename,
            }
    url = '%(site)s%(module)s/%(file)s?view=log' % par
    data = urllib.urlopen(url).read()
    rx = re.search(r'Revision <a href=".*?"><strong>(?P<rev>.+?)</strong></a>.*?\(<a href="(?P<checkouturl>[^\s]*?)">download</a>\)',data,re.DOTALL)
    if rx:
        par['rev'] = rx.group('rev')
        par['checkouturl'] = rx.group('checkouturl')
        url = '%(site)s%(checkouturl)s' % par
        newdata = urllib.urlopen(url).read().decode('utf-8')
        par['newdata'] = newdata

        pg = wikipedia.Page(site,DST_PREFIX+filename)
        try:
            oldtxt = pg.get()
        except:
            oldtxt = u''
        rx = re.search('<source lang="python">\n(?P<olddata>.*)\n</source>',oldtxt,re.DOTALL)
        if rx and newdata==rx.group('olddata'):
            return False, 'No need to update.'

        cmt = 'Update from SVN tree (%(rev)s)' % par
        pg.put(UPDATE % par,comment=cmt,minorEdit=False)
        return True, 'Updated successfully.'
    else:
        return False, 'File not found.'


if os.environ['QUERY_STRING'].startswith('file='):
    filename = os.environ['QUERY_STRING'][5:]
else:
    filename = None


print monobook.doc_start()

print monobook.head(u"Botwiki source updater")

content = u"""
<h1>Botwiki updater</h1>

This script updates source code on the <a href="http://botwiki.sno.cc/wiki/Main_Page">botwiki</a> with the latest SVN revision - just fill in the file name below:

<form action="botwikiupdate.py" method="GET">
<table cellspacing="1">
<tr><td><input name="file" id="file" type="text" value=\""""
if filename:
    content += filename
content += u"""" /></td></tr>
<tr><td><input type="submit" /></td></tr>
</table>
</form>
"""

if filename:
    try:
        os.chdir('/home/misza13/SVNbot')
        sys.path.append('/home/misza13/pywikipedia')
        print "<!-- Commenting out pywikipedia gibberish..."
        import wikipedia
        try:
            status, reply = update(wikipedia.getSite(),filename)
            print "-->"
            content += '<hr />\n<a href="http://botwiki.sno.cc/wiki/%s%s">%s</a>' % (DST_PREFIX,filename,reply)
        finally:
            wikipedia.stopme()
    finally:
        pass

print monobook.body(
        content = content,
        navigation = misza.navigation(),
        footer = misza.footer(),
        )

print monobook.doc_end()