view MoinMoin/action/ @ 4109:e88baf535b48

fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2. cfg.backup_exclude is now just a function of filename, telling whether the file should be excluded. By default, no file is excluded.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 19 Sep 2008 21:41:40 +0200
parents 01f05e74aa9c
children 85884c67228d
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - "pollsistersites" action

    This action fetches lists of page urls and page names from sister sites,
    so we can implement SisterWiki functionality.

    @copyright: 2007 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.

import time, urllib

from MoinMoin import caching
from MoinMoin.util import timefuncs

def execute(pagename, request):
    status = []
    for sistername, sisterurl in request.cfg.sistersites:
        arena = 'sisters'
        key = sistername
        cache = caching.CacheEntry(request, arena, key, scope='farm', use_pickle=True)
        if cache.exists():
            data = cache.content()
            data = {'lastmod': ''}
        uo = urllib.URLopener()
        uo.version = 'MoinMoin SisterPage list fetcher 1.0'
        lastmod = data['lastmod']
        if lastmod:
            uo.addheader('If-Modified-Since', lastmod)
            sisterpages = {}
            f =
            for line in f:
                line = line.strip()
                    page_url, page_name = line.split(' ', 1)
                    sisterpages[page_name.decode('utf-8')] = page_url
                    pass # ignore invalid lines
                lastmod =["Last-Modified"]
                lastmod = timefuncs.formathttpdate(time.time())
            data['lastmod'] = lastmod
            data['sisterpages'] = sisterpages
            status.append(u"Site: %s Status: Updated. Pages: %d" % (sistername, len(sisterpages)))
        except IOError, (title, code, msg, headers): # code e.g. 304
            status.append(u"Site: %s Status: Not updated." % sistername)
        except TypeError: # catch bug in python 2.5: "EnvironmentError expected at most 3 arguments, got 4"
            status.append(u"Site: %s Status: Not updated." % sistername)

    request.emit_http_headers(["Content-Type: text/plain; charset=UTF-8"])