Back to index

moin  1.9.0~rc2
cleancache.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - cleancache script
00004 
00005 @copyright: 2005-2007 MoinMoin:ThomasWaldmann,
00006             2007-2008 MoinMoin:ReimarBauer
00007 @license: GNU GPL, see COPYING for details.
00008 """
00009 
00010 from MoinMoin import caching, user
00011 from MoinMoin.Page import Page
00012 from MoinMoin.script import MoinScript
00013 
00014 class PluginScript(MoinScript):
00015     """\
00016 Purpose:
00017 ========
00018 This script allows you to globally delete all the cache files in data/pages/PageName/cache/
00019 and /data/cache directories
00020 
00021 You will usually do this after changing MoinMoin code, by either upgrading
00022 version, installing or removing macros or changing the regex expression for dicts or groups.
00023 This often makes the text_html file invalid, so you have to remove it (the wiki will recreate it automatically).
00024 
00025 text_html is the name of the cache file used for compiled pages formatted by the wiki text to html formatter.
00026 
00027 Detailed Instructions:
00028 ======================
00029 General syntax: moin [options] maint cleancache
00030 
00031 [options] usually should be:
00032     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
00033 """
00034 
00035     def __init__(self, argv, def_values):
00036         MoinScript.__init__(self, argv, def_values)
00037 
00038     def mainloop(self):
00039         self.init_request()
00040         request = self.request
00041 
00042         # clean page scope cache entries
00043         keys = ['text_html', 'pagelinks', 'hitcounts', ]
00044         pages = request.rootpage.getPageList(user='')
00045         for pagename in pages:
00046             arena = Page(request, pagename)
00047             for key in keys:
00048                 caching.CacheEntry(request, arena, key, scope='item').remove()
00049 
00050         # clean wiki scope cache entries
00051         arena_key_list = [
00052             ('charts', 'hitcounts'),
00053             ('charts', 'pagehits'),
00054             ('charts', 'useragents'),
00055             ('user', 'name2id'),
00056         ]
00057         for arena, key in arena_key_list:
00058             caching.CacheEntry(request, arena, key, scope='wiki').remove()
00059 
00060         # clean dict and groups related cache
00061         arena_scope_list =  [('pagedicts', 'wiki'),
00062                              ('pagegroups', 'wiki'),
00063         ]
00064         for arena, scope in arena_scope_list:
00065             for key in caching.get_cache_list(request, arena, scope):
00066                 caching.CacheEntry(request, arena, key, scope=scope).remove()
00067 
00068         # clean drafts of users
00069         uids = user.getUserList(request)
00070         for key in uids:
00071             caching.CacheEntry(request, 'drafts', key, scope='wiki').remove()
00072