Ticket #6073: compile-messages.py.diff
File compile-messages.py.diff, 2.6 KB (added by , 17 years ago) |
---|
-
django/bin/compile-messages.py
34 34 if f.endswith('.po'): 35 35 sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) 36 36 pf = os.path.splitext(os.path.join(dirpath, f))[0] 37 # msgfmt does not support files with byte order marks, so 38 # we have to make a tmp file without marks for compiling. 39 pofile = pf + '.po' 40 tmpfile = None 41 po = file(pofile) 42 s = po.read(4) 43 if s[:3] == '\xef\xbb\xbf': # UTF-8 44 remove = 3 45 elif s[:2] == '\xfe\xff': # UTF-16 Big Endian 46 remove = 2 47 elif s[:2] == '\xff\xfe': # UTF-16 Little Endian 48 remove = 2 49 elif s[:4] == '\x00\x00\xfe\xff': # UTF-32 Big Endian 50 remove = 4 51 elif s[:4] == '\xff\xfe\x00\x00': # UTF-32 Little Endian 52 remove = 4 53 else: 54 remove = 0 55 if remove > 0: 56 po.seek(remove) 57 tmpfile = pofile + '.tmp' 58 tmp = file(tmpfile, 'w+b') 59 tmp.write(po.read()) 60 tmp.close() 61 pofile = tmpfile 62 po.close() 37 63 # Store the names of the .mo and .po files in an environment 38 64 # variable, rather than doing a string replacement into the 39 65 # command, so that we can take advantage of shell quoting, to 40 66 # quote any malicious characters/escaping. 41 67 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html 42 68 os.environ['djangocompilemo'] = pf + '.mo' 43 os.environ['djangocompilepo'] = p f + '.po'69 os.environ['djangocompilepo'] = pofile 44 70 if sys.platform == 'win32': # Different shell-variable syntax 45 71 cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"' 46 72 else: 47 73 cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"' 48 74 os.system(cmd) 49 75 76 if tmpfile: 77 # Remove the tmp file we created. 78 os.remove(tmpfile) 79 50 80 def main(): 51 81 parser = optparse.OptionParser() 52 82 parser.add_option('-l', '--locale', dest='locale',