Commits

Barry Warsaw  committed 6f42c1d

Added -o/--output-file option as per GNU msgfmt to specify the output
file instead of using inputfilename.mo

  • Participants
  • Parent commits 2c290d4
  • Branches legacy-trunk

Comments (0)

Files changed (1)

File Tools/i18n/msgfmt.py

 Usage: msgfmt.py [OPTIONS] filename.po
 
 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
     --help
         Print this message and exit.
     -V
     --version
         Display version information and exit.
-
 """
 
 import sys
+import os
 import getopt
 import struct
 import array
 
-__version__ = "1.0"
+__version__ = "1.1"
 
 MESSAGES = {}
 
 
 
 
-def make(filename):
+def make(filename, outfile):
     ID = 1
     STR = 2
 
-    # Compute .mo name from .po name
+    # Compute .mo name from .po name and arguments
     if filename.endswith('.po'):
         infile = filename
-        outfile = filename[:-2] + 'mo'
     else:
         infile = filename + '.po'
-        outfile = filename + '.mo'
+    if outfile is None:
+        outfile = os.path.splitext(infile)[0] + '.mo'
+
     try:
         lines = open(infile).readlines()
     except IOError, msg:
     # Compute output
     output = generate()
 
-    # Save output
     try:
         open(outfile,"wb").write(output)
     except IOError,msg:
 
 def main():
     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:
         usage(1, msg)
 
+    outfile = None
     # parse options
     for opt, arg in opts:
         if opt in ('-h', '--help'):
         elif opt in ('-V', '--version'):
             print >> sys.stderr, "msgfmt.py", __version__
             sys.exit(0)
+        elif opt in ('-o', '--output-file'):
+            outfile = arg
     # do it
     if not args:
         print >> sys.stderr, 'No input file given'
         return
 
     for filename in args:
-        make(filename)
+        make(filename, outfile)
 
 
 if __name__ == '__main__':