~ubuntu-branches/ubuntu/precise/moin/precise-security

« back to all changes in this revision

Viewing changes to MoinMoin/action/pollsistersites.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - "pollsistersites" action
 
4
 
 
5
    This action fetches lists of page urls and page names from sister sites,
 
6
    so we can implement SisterWiki functionality.
 
7
    See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
 
8
 
 
9
    @copyright: 2007 MoinMoin:ThomasWaldmann
 
10
    @license: GNU GPL, see COPYING for details.
 
11
"""
 
12
 
 
13
import time, urllib
 
14
 
 
15
from MoinMoin import caching
 
16
from MoinMoin.util import timefuncs
 
17
 
 
18
def execute(pagename, request):
 
19
    status = []
 
20
    for sistername, sisterurl in request.cfg.sistersites:
 
21
        arena = 'sisters'
 
22
        key = sistername
 
23
        cache = caching.CacheEntry(request, arena, key, scope='farm', use_pickle=True)
 
24
        if cache.exists():
 
25
            data = cache.content()
 
26
        else:
 
27
            data = {'lastmod': ''}
 
28
        uo = urllib.URLopener()
 
29
        uo.version = 'MoinMoin SisterPage list fetcher 1.0'
 
30
        lastmod = data['lastmod']
 
31
        if lastmod:
 
32
            uo.addheader('If-Modified-Since', lastmod)
 
33
        try:
 
34
            sisterpages = {}
 
35
            f = uo.open(sisterurl)
 
36
            for line in f:
 
37
                line = line.strip()
 
38
                try:
 
39
                    page_url, page_name = line.split(' ', 1)
 
40
                    sisterpages[page_name.decode('utf-8')] = page_url
 
41
                except:
 
42
                    pass # ignore invalid lines
 
43
            try:
 
44
                lastmod = f.info()["Last-Modified"]
 
45
            except:
 
46
                lastmod = timefuncs.formathttpdate(time.time())
 
47
            f.close()
 
48
            data['lastmod'] = lastmod
 
49
            data['sisterpages'] = sisterpages
 
50
            cache.update(data)
 
51
            status.append(u"Site: %s Status: Updated. Pages: %d" % (sistername, len(sisterpages)))
 
52
        except IOError, (title, code, msg, headers): # code e.g. 304
 
53
            status.append(u"Site: %s Status: Not updated." % sistername)
 
54
        except TypeError: # catch bug in python 2.5: "EnvironmentError expected at most 3 arguments, got 4"
 
55
            status.append(u"Site: %s Status: Not updated." % sistername)
 
56
 
 
57
    request.emit_http_headers(["Content-Type: text/plain; charset=UTF-8"])
 
58
    request.write("\r\n".join(status).encode("utf-8"))