~ubuntu-branches/ubuntu/intrepid/moin/intrepid-updates

« back to all changes in this revision

Viewing changes to MoinMoin/script/maint/cleanpage.py

  • Committer: Bazaar Package Importer
  • Author(s): Sivan Greenberg
  • Date: 2006-07-09 19:28:02 UTC
  • Revision ID: james.westby@ubuntu.com-20060709192802-oaeuvt4v3e9300uj
Tags: 1.5.3-1ubuntu1
* Merge new debian version.
* Reapply Ubuntu changes:
    + debian/rules:
      - Comment out usage of control.ubuntu.in (doesn't fit!).
    + debian/control.in:
      - Dropped python2.3 binary package.
    + debian/control:
      - Dropped python2.3 binary, again.
      - Dropped python2.3-dev from Build-Depends-Indep.
    + debian/patches/001-attachment-xss-fix.patch:
      - Dropped this patch. It's now in upstream's distribution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - display unused or trash page directories in data/pages
 
4
    
 
5
    Then please review the output before running it!
 
6
 
 
7
    @copyright: 2005-2006 by MoinMoin:ThomasWaldmann
 
8
    @license: GNU GPL, see COPYING for details.
 
9
"""
 
10
 
 
11
import os
 
12
 
 
13
from MoinMoin.script._util import MoinScript
 
14
 
 
15
class PluginScript(MoinScript):
 
16
    def __init__(self, argv, def_values):
 
17
        MoinScript.__init__(self, argv, def_values)
 
18
    
 
19
    def qualify(self, p):
 
20
        """ look at page directory p and return its state """
 
21
        dir = os.listdir(p)
 
22
        if not dir:
 
23
            return 'empty'
 
24
 
 
25
        # check if we have something of potential value
 
26
        revs = []
 
27
        if 'revisions' in dir:
 
28
            revs = os.listdir(os.path.join(p, 'revisions'))
 
29
        atts = []
 
30
        if 'attachments' in dir:
 
31
            atts = os.listdir(os.path.join(p, 'attachments'))
 
32
 
 
33
        if not revs and not atts:
 
34
            return 'trash'
 
35
        
 
36
        if 'current-locked' in dir:
 
37
            return 'current-locked'
 
38
        elif 'current' in dir:
 
39
            try:
 
40
                current = open(os.path.join(p, 'current')).read().strip()
 
41
                curr = int(current)
 
42
            except:
 
43
                return 'current damaged'
 
44
            if current not in revs:
 
45
                return 'deleted'
 
46
        else:
 
47
            return 'no current'
 
48
 
 
49
        return 'ok'
 
50
 
 
51
    def mainloop(self):
 
52
        self.init_request()
 
53
        base = self.request.cfg.data_dir
 
54
        pagesdir = os.path.join(base, 'pages')
 
55
        for p in os.listdir(pagesdir):
 
56
            pagedir = os.path.join(pagesdir, p)
 
57
            status = self.qualify(pagedir)
 
58
            if status in ['trash', 'empty', ]:
 
59
                print "mv '%s' trash # %s" % (pagedir,status)
 
60
            elif status in ['deleted', ]:
 
61
                print "mv '%s' deleted # %s" % (pagedir,status)
 
62
            else:
 
63
                print "# %s: '%s'" % (status, pagedir)
 
64