Kaydet (Commit) 78d7dc49 authored tarafından Barry Warsaw's avatar Barry Warsaw

Added -o/--output-file option as per GNU msgfmt to specify the output

file instead of using inputfilename.mo
üst 043d5e55
...@@ -11,6 +11,11 @@ GNU msgfmt program, however, it is a simpler implementation. ...@@ -11,6 +11,11 @@ GNU msgfmt program, however, it is a simpler implementation.
Usage: msgfmt.py [OPTIONS] filename.po Usage: msgfmt.py [OPTIONS] filename.po
Options: Options:
-o file
--output-file=file
Specify the output file to write to. If omitted, output will go to a
file named filename.mo (based off the input file name).
-h -h
--help --help
Print this message and exit. Print this message and exit.
...@@ -18,15 +23,15 @@ Options: ...@@ -18,15 +23,15 @@ Options:
-V -V
--version --version
Display version information and exit. Display version information and exit.
""" """
import sys import sys
import os
import getopt import getopt
import struct import struct
import array import array
__version__ = "1.0" __version__ = "1.1"
MESSAGES = {} MESSAGES = {}
...@@ -91,17 +96,18 @@ def generate(): ...@@ -91,17 +96,18 @@ def generate():
def make(filename): def make(filename, outfile):
ID = 1 ID = 1
STR = 2 STR = 2
# Compute .mo name from .po name # Compute .mo name from .po name and arguments
if filename.endswith('.po'): if filename.endswith('.po'):
infile = filename infile = filename
outfile = filename[:-2] + 'mo'
else: else:
infile = filename + '.po' infile = filename + '.po'
outfile = filename + '.mo' if outfile is None:
outfile = os.path.splitext(infile)[0] + '.mo'
try: try:
lines = open(infile).readlines() lines = open(infile).readlines()
except IOError, msg: except IOError, msg:
...@@ -159,7 +165,6 @@ def make(filename): ...@@ -159,7 +165,6 @@ def make(filename):
# Compute output # Compute output
output = generate() output = generate()
# Save output
try: try:
open(outfile,"wb").write(output) open(outfile,"wb").write(output)
except IOError,msg: except IOError,msg:
...@@ -169,10 +174,12 @@ def make(filename): ...@@ -169,10 +174,12 @@ def make(filename):
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'hV', ['help','version']) opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
['help', 'version', 'output-file='])
except getopt.error, msg: except getopt.error, msg:
usage(1, msg) usage(1, msg)
outfile = None
# parse options # parse options
for opt, arg in opts: for opt, arg in opts:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
...@@ -180,6 +187,8 @@ def main(): ...@@ -180,6 +187,8 @@ def main():
elif opt in ('-V', '--version'): elif opt in ('-V', '--version'):
print >> sys.stderr, "msgfmt.py", __version__ print >> sys.stderr, "msgfmt.py", __version__
sys.exit(0) sys.exit(0)
elif opt in ('-o', '--output-file'):
outfile = arg
# do it # do it
if not args: if not args:
print >> sys.stderr, 'No input file given' print >> sys.stderr, 'No input file given'
...@@ -187,7 +196,7 @@ def main(): ...@@ -187,7 +196,7 @@ def main():
return return
for filename in args: for filename in args:
make(filename) make(filename, outfile)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment