~canonical-django/canonical-django/project-template

« back to all changes in this revision

Viewing changes to trunk/python-packages/django/bin/unique-messages.py

  • Committer: Matthew Nuzum
  • Date: 2008-11-13 05:46:03 UTC
  • Revision ID: matthew.nuzum@canonical.com-20081113054603-v0kvr6z6xyexvqt3
adding to version control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
def unique_messages():
 
7
    basedir = None
 
8
 
 
9
    if os.path.isdir(os.path.join('conf', 'locale')):
 
10
        basedir = os.path.abspath(os.path.join('conf', 'locale'))
 
11
    elif os.path.isdir('locale'):
 
12
        basedir = os.path.abspath('locale')
 
13
    else:
 
14
        print "this script should be run from the django svn tree or your project or app tree"
 
15
        sys.exit(1)
 
16
 
 
17
    for (dirpath, dirnames, filenames) in os.walk(basedir):
 
18
        for f in filenames:
 
19
            if f.endswith('.po'):
 
20
                sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
 
21
                pf = os.path.splitext(os.path.join(dirpath, f))[0]
 
22
                cmd = 'msguniq "%s.po"' % pf
 
23
                stdout = os.popen(cmd)
 
24
                msg = stdout.read()
 
25
                open('%s.po' % pf, 'w').write(msg)
 
26
 
 
27
if __name__ == "__main__":
 
28
    unique_messages()