~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/i18n/tools/mk_POTFILES.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
from sys import argv
 
5
 
 
6
# Define the starting directory.
 
7
 
 
8
startdir = ""
 
9
 
 
10
if len(argv) == 2:
 
11
    startdir = os.path.join(argv[1])
 
12
else:
 
13
    startdir = os.path.join("..") # MoinMoin
 
14
 
 
15
# Define a blacklist.
 
16
 
 
17
blacklist = ["_tests", os.path.join("script", "old"), "support", "filter/EXIF.py"]
 
18
 
 
19
# Define an output file for the filenames.
 
20
 
 
21
outname_in = "POTFILES.in"
 
22
outname_final = "POTFILES"
 
23
 
 
24
# Functions.
 
25
 
 
26
def get_files((files, prefix, blacklist), d, names):
 
27
 
 
28
    """
 
29
    Store pathnames in 'files', removing 'prefix', excluding those mentioned
 
30
    in the 'blacklist', building such pathnames from the directory 'd' and
 
31
    the given 'names'.
 
32
    """
 
33
 
 
34
    for name in names:
 
35
        if name.endswith(".py"):
 
36
            path = os.path.join(d, name)
 
37
 
 
38
            # Strip the prefix.
 
39
            if path.startswith(prefix):
 
40
                path = path[len(prefix):]
 
41
 
 
42
            # Test for exact blacklist matches.
 
43
            if path in blacklist:
 
44
                continue
 
45
 
 
46
            # Test for directory blacklist matches.
 
47
            found = 0
 
48
            for blackitem in blacklist:
 
49
                if path.startswith(blackitem):
 
50
                    found = 1
 
51
                    break
 
52
 
 
53
            if not found:
 
54
                files.append(path)
 
55
 
 
56
def find_files(startdir, blacklist):
 
57
    "Find files under 'startdir' excluding those in the 'blacklist'."
 
58
 
 
59
    # Calculate the prefix from the start directory.
 
60
    prefix = os.path.join(startdir, "")
 
61
 
 
62
    # Start with an empty list of files.
 
63
 
 
64
    files = []
 
65
    os.path.walk(startdir, get_files, (files, prefix, blacklist))
 
66
    return files
 
67
 
 
68
if __name__ == "__main__":
 
69
 
 
70
    # Find those files using the module defaults.
 
71
    files = find_files(startdir, blacklist)
 
72
 
 
73
    # Write the names out.
 
74
    outfile = open(outname_in, "w")
 
75
    try:
 
76
        for file in files:
 
77
            outfile.write(file + "\n")
 
78
    finally:
 
79
        outfile.close()
 
80
 
 
81
    # Write the processed list out, ready for other purposes.
 
82
    outfile = open(outname_final, "w")
 
83
    outfile.write("POTFILES = \\\n")
 
84
    try:
 
85
        for file in files[:-1]:
 
86
            outfile.write("\t" + os.path.join(startdir, file) + " \\\n")
 
87
        if files[-1]:
 
88
            file = files[-1]
 
89
            outfile.write("\t" + os.path.join(startdir, file) + "\n")
 
90
    finally:
 
91
        outfile.close()
 
92
 
 
93
# vim: tabstop=4 expandtab shiftwidth=4