view MoinMoin/script/maint/ @ 670:687633456631

MoinMoin.script: move _util stuff to __init__
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 20 May 2006 23:40:21 +0200
parents d3a173c26e1c
children da5623bc6819
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - display unused or trash page directories in data/pages
    Then please review the output before running it!

    @copyright: 2005-2006 by MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.

import os

from MoinMoin.script import MoinScript

class PluginScript(MoinScript):
    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:
                current = open(os.path.join(p, 'current')).read().strip()
                curr = int(current)
                return 'current damaged'
            if current not in revs:
                return 'deleted'
            return 'no current'

        return 'ok'

    def mainloop(self):
        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)
                print "# %s: '%s'" % (status, pagedir)