Back to index

moin  1.9.0~rc2
Functions
MoinMoin.action.pollsistersites Namespace Reference

Functions

def execute

Function Documentation

def MoinMoin.action.pollsistersites.execute (   pagename,
  request 
)

Definition at line 18 of file pollsistersites.py.

00018 
00019 def execute(pagename, request):
00020     status = []
00021     for sistername, sisterurl in request.cfg.sistersites:
00022         arena = 'sisters'
00023         key = sistername
00024         cache = caching.CacheEntry(request, arena, key, scope='farm', use_pickle=True)
00025         if cache.exists():
00026             data = cache.content()
00027         else:
00028             data = {'lastmod': ''}
00029         uo = urllib.URLopener()
00030         uo.version = 'MoinMoin SisterPage list fetcher 1.0'
00031         lastmod = data['lastmod']
00032         if lastmod:
00033             uo.addheader('If-Modified-Since', lastmod)
00034         try:
00035             sisterpages = {}
00036             f = uo.open(sisterurl)
00037             for line in f:
00038                 line = line.strip()
00039                 try:
00040                     page_url, page_name = line.split(' ', 1)
00041                     sisterpages[page_name.decode('utf-8')] = page_url
00042                 except:
00043                     pass # ignore invalid lines
00044             try:
00045                 lastmod = f.info()["Last-Modified"]
00046             except:
00047                 lastmod = timefuncs.formathttpdate(time.time())
00048             f.close()
00049             data['lastmod'] = lastmod
00050             data['sisterpages'] = sisterpages
00051             cache.update(data)
00052             status.append(u"Site: %s Status: Updated. Pages: %d" % (sistername, len(sisterpages)))
00053         except IOError, (title, code, msg, headers): # code e.g. 304
00054             status.append(u"Site: %s Status: Not updated." % sistername)
00055         except TypeError: # catch bug in python 2.5: "EnvironmentError expected at most 3 arguments, got 4"
00056             status.append(u"Site: %s Status: Not updated." % sistername)
00057 
00058     request.mimetype = 'text/plain'
00059     request.write("\r\n".join(status).encode("utf-8"))