1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - display unused or trash page directories in data/pages
@copyright: 2005-2006 MoinMoin:ThomasWaldmann
@license: GNU GPL, see COPYING for details.
"""
import os
from MoinMoin.script import MoinScript
class PluginScript(MoinScript):
"""\
Purpose:
========
This tool outputs a shell script which upon execution will remove unused or
trashed pages from the wiki.
Detailed Instructions:
======================
General syntax: moin [options] maint cleanpage [cleanpage-options]
[options] usually should be:
--config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/
[cleanpage-options] see below:
0. Verify the outputted shell script before running it.
1. This script takes no command line arguments.
"""
def __init__(self, argv, def_values):
MoinScript.__init__(self, argv, def_values)
def qualify(self, p):
""" look at page directory p and return its state """
dir = os.listdir(p)
if not dir:
return 'empty'
# check if we have something of potential value
revs = []
if 'revisions' in dir:
revs = os.listdir(os.path.join(p, 'revisions'))
atts = []
if 'attachments' in dir:
atts = os.listdir(os.path.join(p, 'attachments'))
if not revs and not atts:
return 'trash'
if 'current-locked' in dir:
return 'current-locked'
elif 'current' in dir:
try:
current = open(os.path.join(p, 'current')).read().strip()
int(current)
except:
return 'current damaged'
if current not in revs:
return 'deleted'
else:
return 'no current'
return 'ok'
def mainloop(self):
self.init_request()
base = self.request.cfg.data_dir
pagesdir = os.path.join(base, 'pages')
for p in os.listdir(pagesdir):
pagedir = os.path.join(pagesdir, p)
status = self.qualify(pagedir)
if status in ['trash', 'empty', ]:
print "mv '%s' trash # %s" % (pagedir, status)
elif status in ['deleted', ]:
print "mv '%s' deleted # %s" % (pagedir, status)
else:
print "# %s: '%s'" % (status, pagedir)
|