view MoinMoin/scripts/pagescleaner.py @ 35:f0af060fb82b

making people choose the right approach to page_front_page imported from: moin--main--1.5--patch-36
author Thomas Waldmann <tw@waldmann-edv.de>
date Sun, 25 Sep 2005 14:45:38 +0000
parents 77665d8e2254
children be33ecd58d4e
line wrap: on
line source
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - display unused or trash page directories in data/pages
    
    Usage:
    First change the base path to match your needs.
    Then do ./pagescleaner.py >cleanthem.sh
    Then please review cleanthem.sh and run it, if it is OK.

    @copyright: 2005 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
    @license: GNU GPL, see COPYING for details.
"""

import os

base = "."
pagebasedir = base + "/data/pages"

def qualify(p):
    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()
            curr = int(current)
        except:
            return 'current damaged'
        if current not in revs:
            return 'deleted'
    else:
        return 'no current'

    return 'ok'

for p in os.listdir(pagebasedir):
    pagedir = os.path.join(pagebasedir, p)
    status = 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)

# EOF