~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/bin/compile-messages.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
3
 
import optparse
4
 
import os
5
 
import sys
6
 
 
7
 
def compile_messages(locale=None):
8
 
    basedir = None
9
 
 
10
 
    if os.path.isdir(os.path.join('conf', 'locale')):
11
 
        basedir = os.path.abspath(os.path.join('conf', 'locale'))
12
 
    elif os.path.isdir('locale'):
13
 
        basedir = os.path.abspath('locale')
14
 
    else:
15
 
        print "This script should be run from the Django SVN tree or your project or app tree."
16
 
        sys.exit(1)
17
 
 
18
 
    if locale is not None:
19
 
        basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
20
 
 
21
 
    for dirpath, dirnames, filenames in os.walk(basedir):
22
 
        for f in filenames:
23
 
            if f.endswith('.po'):
24
 
                sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
25
 
                pf = os.path.splitext(os.path.join(dirpath, f))[0]
26
 
                # Store the names of the .mo and .po files in an environment
27
 
                # variable, rather than doing a string replacement into the
28
 
                # command, so that we can take advantage of shell quoting, to
29
 
                # quote any malicious characters/escaping.
30
 
                # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
31
 
                os.environ['djangocompilemo'] = pf + '.mo'
32
 
                os.environ['djangocompilepo'] = pf + '.po'
33
 
                if sys.platform == 'win32': # Different shell-variable syntax
34
 
                    cmd = 'msgfmt -o "%djangocompilemo%" "%djangocompilepo%"'
35
 
                else:
36
 
                    cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"'
37
 
                os.system(cmd)
38
 
 
39
 
def main():
40
 
    parser = optparse.OptionParser()
41
 
    parser.add_option('-l', '--locale', dest='locale',
42
 
            help="The locale to process. Default is to process all.")
43
 
    options, args = parser.parse_args()
44
 
    if len(args):
45
 
        parser.error("This program takes no arguments")
46
 
    compile_messages(options.locale)
47
 
 
48
3
if __name__ == "__main__":
49
 
    main()
 
4
    import sys
 
5
    name = sys.argv[0]
 
6
    args = ' '.join(sys.argv[1:])
 
7
    print >> sys.stderr, "%s has been moved into django-admin.py" % name
 
8
    print >> sys.stderr, 'Please run "django-admin.py compilemessages %s" instead.'% args
 
9
    print >> sys.stderr
 
10
    sys.exit(1)
 
11