Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed unique-messages.py, compile-messages.py and make-messages.py …

…to use 'if name == main' so they can be imported and won't mess up utilities such as pychecker

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2056 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ce40c4a9e2b32e8c9233e788f594ebf03cc9a7f0 1 parent 2e0fc1f
Adrian Holovaty authored
33  django/bin/compile-messages.py
@@ -4,21 +4,24 @@
4 4
 import sys
5 5
 import getopt
6 6
 
7  
-basedir = None
  7
+def compile_messages():
  8
+    basedir = None
8 9
 
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)
  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)
16 17
 
17  
-for (dirpath, dirnames, filenames) in os.walk(basedir):
18  
-    for file in filenames:
19  
-        if file.endswith('.po'):
20  
-            sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
21  
-            pf = os.path.splitext(os.path.join(dirpath, file))[0]
22  
-            cmd = 'msgfmt -o "%s.mo" "%s.po"' % (pf, pf)
23  
-            os.system(cmd)
  18
+    for (dirpath, dirnames, filenames) in os.walk(basedir):
  19
+        for file in filenames:
  20
+            if file.endswith('.po'):
  21
+                sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
  22
+                pf = os.path.splitext(os.path.join(dirpath, file))[0]
  23
+                cmd = 'msgfmt -o "%s.mo" "%s.po"' % (pf, pf)
  24
+                os.system(cmd)
24 25
 
  26
+if __name__ == "__main__":
  27
+    compile_messages()
238  django/bin/make-messages.py
... ...
@@ -1,139 +1,141 @@
1 1
 #!/usr/bin/python
2 2
 
  3
+from django.utils.translation import templateize
3 4
 import re
4 5
 import os
5 6
 import sys
6 7
 import getopt
7 8
 
8  
-from django.utils.translation import templateize
9  
-
10 9
 pythonize_re = re.compile(r'\n\s*//')
11 10
 
12  
-localedir = None
13  
-
14  
-if os.path.isdir(os.path.join('conf', 'locale')):
15  
-    localedir = os.path.abspath(os.path.join('conf', 'locale'))
16  
-elif os.path.isdir('locale'):
17  
-    localedir = os.path.abspath('locale')
18  
-else:
19  
-    print "This script should be run from the django svn tree or your project or app tree."
20  
-    print "If you did indeed run it from the svn checkout or your project or application,"
21  
-    print "maybe you are just missing the conf/locale (in the django tree) or locale (for project"
22  
-    print "and application) directory?"
23  
-    print "make-messages.py doesn't create it automatically, you have to create it by hand if"
24  
-    print "you want to enable i18n for your project or application."
25  
-    sys.exit(1)
26  
-
27  
-(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
28  
-
29  
-lang = None
30  
-domain = 'django'
31  
-verbose = False
32  
-all = False
33  
-
34  
-for o, v in opts:
35  
-    if o == '-l':
36  
-        lang = v
37  
-    elif o == '-d':
38  
-        domain = v
39  
-    elif o == '-v':
40  
-        verbose = True
41  
-    elif o == '-a':
42  
-        all = True
43  
-
44  
-if domain not in ('django', 'djangojs'):
45  
-    print "currently make-messages.py only supports domains 'django' and 'djangojs'"
46  
-    sys.exit(1)
47  
-if (lang is None and not all) or domain is None:
48  
-    print "usage: make-messages.py -l <language>"
49  
-    print "   or: make-messages.py -a"
50  
-    sys.exit(1)
51  
-
52  
-languages = []
53  
-
54  
-if lang is not None:
55  
-    languages.append(lang)
56  
-elif all:
57  
-    languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
58  
-
59  
-for lang in languages:
60  
-
61  
-    print "processing language", lang
62  
-    basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
63  
-    if not os.path.isdir(basedir):
64  
-        os.makedirs(basedir)
65  
-
66  
-    pofile = os.path.join(basedir, '%s.po' % domain)
67  
-    potfile = os.path.join(basedir, '%s.pot' % domain)
68  
-
69  
-    if os.path.exists(potfile):
70  
-        os.unlink(potfile)
71  
-
72  
-    for (dirpath, dirnames, filenames) in os.walk("."):
73  
-        for file in filenames:
74  
-            if domain == 'djangojs' and file.endswith('.js'):
75  
-                if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
76  
-                src = open(os.path.join(dirpath, file), "rb").read()
77  
-                src = pythonize_re.sub('\n#', src)
78  
-                open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
79  
-                thefile = '%s.py' % file
80  
-                cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
81  
-                    os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
82  
-                (stdin, stdout, stderr) = os.popen3(cmd, 'b')
83  
-                msgs = stdout.read()
84  
-                errors = stderr.read()
85  
-                if errors: 
86  
-                    print "errors happened while running xgettext on %s" % file
87  
-                    print errors
88  
-                    sys.exit(8)
89  
-                old = '#: '+os.path.join(dirpath, thefile)[2:]
90  
-                new = '#: '+os.path.join(dirpath, file)[2:]
91  
-                msgs = msgs.replace(old, new)
92  
-                if msgs:
93  
-                    open(potfile, 'ab').write(msgs)
94  
-                os.unlink(os.path.join(dirpath, thefile))
95  
-            elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
96  
-                thefile = file
97  
-                if file.endswith('.html'):
  11
+def make_messages():
  12
+    localedir = None
  13
+
  14
+    if os.path.isdir(os.path.join('conf', 'locale')):
  15
+        localedir = os.path.abspath(os.path.join('conf', 'locale'))
  16
+    elif os.path.isdir('locale'):
  17
+        localedir = os.path.abspath('locale')
  18
+    else:
  19
+        print "This script should be run from the django svn tree or your project or app tree."
  20
+        print "If you did indeed run it from the svn checkout or your project or application,"
  21
+        print "maybe you are just missing the conf/locale (in the django tree) or locale (for project"
  22
+        print "and application) directory?"
  23
+        print "make-messages.py doesn't create it automatically, you have to create it by hand if"
  24
+        print "you want to enable i18n for your project or application."
  25
+        sys.exit(1)
  26
+
  27
+    (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
  28
+
  29
+    lang = None
  30
+    domain = 'django'
  31
+    verbose = False
  32
+    all = False
  33
+
  34
+    for o, v in opts:
  35
+        if o == '-l':
  36
+            lang = v
  37
+        elif o == '-d':
  38
+            domain = v
  39
+        elif o == '-v':
  40
+            verbose = True
  41
+        elif o == '-a':
  42
+            all = True
  43
+
  44
+    if domain not in ('django', 'djangojs'):
  45
+        print "currently make-messages.py only supports domains 'django' and 'djangojs'"
  46
+        sys.exit(1)
  47
+    if (lang is None and not all) or domain is None:
  48
+        print "usage: make-messages.py -l <language>"
  49
+        print "   or: make-messages.py -a"
  50
+        sys.exit(1)
  51
+
  52
+    languages = []
  53
+
  54
+    if lang is not None:
  55
+        languages.append(lang)
  56
+    elif all:
  57
+        languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
  58
+
  59
+    for lang in languages:
  60
+
  61
+        print "processing language", lang
  62
+        basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
  63
+        if not os.path.isdir(basedir):
  64
+            os.makedirs(basedir)
  65
+
  66
+        pofile = os.path.join(basedir, '%s.po' % domain)
  67
+        potfile = os.path.join(basedir, '%s.pot' % domain)
  68
+
  69
+        if os.path.exists(potfile):
  70
+            os.unlink(potfile)
  71
+
  72
+        for (dirpath, dirnames, filenames) in os.walk("."):
  73
+            for file in filenames:
  74
+                if domain == 'djangojs' and file.endswith('.js'):
  75
+                    if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
98 76
                     src = open(os.path.join(dirpath, file), "rb").read()
99  
-                    open(os.path.join(dirpath, '%s.py' % file), "wb").write(templateize(src))
  77
+                    src = pythonize_re.sub('\n#', src)
  78
+                    open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
100 79
                     thefile = '%s.py' % file
101  
-                if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
102  
-                cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
103  
-                    os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
104  
-                (stdin, stdout, stderr) = os.popen3(cmd, 'b')
105  
-                msgs = stdout.read()
106  
-                errors = stderr.read()
107  
-                if errors: 
108  
-                    print "errors happened while running xgettext on %s" % file
109  
-                    print errors
110  
-                    sys.exit(8)
111  
-                if thefile != file:
  80
+                    cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
  81
+                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
  82
+                    (stdin, stdout, stderr) = os.popen3(cmd, 'b')
  83
+                    msgs = stdout.read()
  84
+                    errors = stderr.read()
  85
+                    if errors:
  86
+                        print "errors happened while running xgettext on %s" % file
  87
+                        print errors
  88
+                        sys.exit(8)
112 89
                     old = '#: '+os.path.join(dirpath, thefile)[2:]
113 90
                     new = '#: '+os.path.join(dirpath, file)[2:]
114 91
                     msgs = msgs.replace(old, new)
115  
-                if msgs:
116  
-                    open(potfile, 'ab').write(msgs)
117  
-                if thefile != file:
  92
+                    if msgs:
  93
+                        open(potfile, 'ab').write(msgs)
118 94
                     os.unlink(os.path.join(dirpath, thefile))
119  
-
120  
-    if os.path.exists(potfile):
121  
-        (stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b')
122  
-        msgs = stdout.read()
123  
-        errors = stderr.read()
124  
-        if errors:
125  
-            print "errors happened while running msguniq"
126  
-            print errors
127  
-            sys.exit(8)
128  
-        open(potfile, 'w').write(msgs)
129  
-        if os.path.exists(pofile):
130  
-            (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
  95
+                elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
  96
+                    thefile = file
  97
+                    if file.endswith('.html'):
  98
+                        src = open(os.path.join(dirpath, file), "rb").read()
  99
+                        open(os.path.join(dirpath, '%s.py' % file), "wb").write(templateize(src))
  100
+                        thefile = '%s.py' % file
  101
+                    if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
  102
+                    cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
  103
+                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
  104
+                    (stdin, stdout, stderr) = os.popen3(cmd, 'b')
  105
+                    msgs = stdout.read()
  106
+                    errors = stderr.read()
  107
+                    if errors:
  108
+                        print "errors happened while running xgettext on %s" % file
  109
+                        print errors
  110
+                        sys.exit(8)
  111
+                    if thefile != file:
  112
+                        old = '#: '+os.path.join(dirpath, thefile)[2:]
  113
+                        new = '#: '+os.path.join(dirpath, file)[2:]
  114
+                        msgs = msgs.replace(old, new)
  115
+                    if msgs:
  116
+                        open(potfile, 'ab').write(msgs)
  117
+                    if thefile != file:
  118
+                        os.unlink(os.path.join(dirpath, thefile))
  119
+
  120
+        if os.path.exists(potfile):
  121
+            (stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b')
131 122
             msgs = stdout.read()
132 123
             errors = stderr.read()
133 124
             if errors:
134  
-                print "errors happened while running msgmerge"
  125
+                print "errors happened while running msguniq"
135 126
                 print errors
136 127
                 sys.exit(8)
137  
-        open(pofile, 'wb').write(msgs)
138  
-        os.unlink(potfile)
  128
+            open(potfile, 'w').write(msgs)
  129
+            if os.path.exists(pofile):
  130
+                (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
  131
+                msgs = stdout.read()
  132
+                errors = stderr.read()
  133
+                if errors:
  134
+                    print "errors happened while running msgmerge"
  135
+                    print errors
  136
+                    sys.exit(8)
  137
+            open(pofile, 'wb').write(msgs)
  138
+            os.unlink(potfile)
139 139
 
  140
+if __name__ == "__main__":
  141
+    make_messages()
37  django/bin/unique-messages.py
@@ -4,23 +4,26 @@
4 4
 import sys
5 5
 import getopt
6 6
 
7  
-basedir = None
  7
+def unique_messages():
  8
+    basedir = None
8 9
 
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)
  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)
16 17
 
17  
-for (dirpath, dirnames, filenames) in os.walk(basedir):
18  
-    for file in filenames:
19  
-        if file.endswith('.po'):
20  
-            sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
21  
-            pf = os.path.splitext(os.path.join(dirpath, file))[0]
22  
-            cmd = 'msguniq "%s.po"' % pf
23  
-            stdout = os.popen(cmd)
24  
-            msg = stdout.read()
25  
-            open('%s.po' % pf, 'w').write(msg)
  18
+    for (dirpath, dirnames, filenames) in os.walk(basedir):
  19
+        for file in filenames:
  20
+            if file.endswith('.po'):
  21
+                sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
  22
+                pf = os.path.splitext(os.path.join(dirpath, file))[0]
  23
+                cmd = 'msguniq "%s.po"' % pf
  24
+                stdout = os.popen(cmd)
  25
+                msg = stdout.read()
  26
+                open('%s.po' % pf, 'w').write(msg)
26 27
 
  28
+if __name__ == "__main__":
  29
+    unique_messages()

0 notes on commit ce40c4a

Please sign in to comment.
Something went wrong with that request. Please try again.