[gnome-doc-utils] [xml2po] Replace .xml2po.mo temp file by a system temp file - bug #593175



commit 4b1e70b5bb46685c5bd623ce2a0e5bd1dcc6b3fe
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Sep 14 22:21:21 2009 +0200

    [xml2po] Replace .xml2po.mo temp file by a system temp file - bug #593175

 xml2po/README.in           |    3 +--
 xml2po/xml2po.1.xml        |    2 --
 xml2po/xml2po/xml2po.py.in |   14 ++++++++++----
 3 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/xml2po/README.in b/xml2po/README.in
index 5fe92f0..bd3bcf3 100644
--- a/xml2po/README.in
+++ b/xml2po/README.in
@@ -150,6 +150,5 @@ not writeable, instead of showing an error, xml2po will replace every
 entity.
 
 Option "-p file.po" depends on program msgfmt being available and in
-the path, and also depends on a file .xml2po.mo being writeable in
-the current working directory.  If that fails, you'll see an error.
+the path.  If that fails, you'll see an error.
 
diff --git a/xml2po/xml2po.1.xml b/xml2po/xml2po.1.xml
index 777bb7b..39b80d9 100644
--- a/xml2po/xml2po.1.xml
+++ b/xml2po/xml2po.1.xml
@@ -146,8 +146,6 @@
 					<para>
  						Specify a PO FILE containing translation and output 
 						XML document with translations merged in.
-						Using this option will overwrite the temporary
-						file <filename>.xml2po.mo</filename>.
 					</para>
 				</listitem>
 			</varlistentry>
diff --git a/xml2po/xml2po/xml2po.py.in b/xml2po/xml2po/xml2po.py.in
index 5da1389..d4515b4 100644
--- a/xml2po/xml2po/xml2po.py.in
+++ b/xml2po/xml2po/xml2po.py.in
@@ -35,6 +35,7 @@ VERSION = "1.0.5"
 import sys
 import os
 import getopt
+import tempfile
 
 NULL_STRING = '/dev/null'
 if not os.path.exists('/dev/null'): NULL_STRING = 'NUL'
@@ -51,7 +52,6 @@ OPTIONS may be some of:
     -m    --mode=TYPE          Treat tags as type TYPE (default: docbook)
     -o    --output=FILE        Print resulting text (XML or POT) to FILE
     -p    --po-file=FILE       Specify PO file containing translation, and merge
-                                 Overwrites temporary file .xml2po.mo.
     -r    --reuse=FILE         Specify translated XML file with the same structure
     -t    --translation=FILE   Specify MO file containing translation, and merge
     -u    --update-translation=LANG.po   Updates a PO file using msgmerge program
@@ -97,7 +97,8 @@ def main(argv):
         'expand_all_entities' : False,
     }
     origxml = ''
-    mofile = ''
+    mofile = None
+    mofile_tmppath = None
 
     try: opts, remaining_args = getopt.getopt(argv, 'avhkem:t:o:p:u:r:l:',
                                ['automatic-tags','version', 'help', 'keep-entities', 'expand-all-entities', 'mode=', 'translation=',
@@ -130,12 +131,14 @@ def main(argv):
             operation = 'update'
             po_to_update = arg
         elif opt in ('-p', '--po-file'):
-            mofile = ".xml2po.mo"
+            mofile_handle, mofile_tmppath = tempfile.mkstemp()
+            os.close(mofile_handle)
             pofile = arg
             operation = 'merge'
             if 'translationlanguage' not in options:
                 options['translationlanguage'] = os.path.split(os.path.splitext(pofile)[0])[1]
-            os.system("msgfmt -o %s %s >%s" % (mofile, pofile, NULL_STRING)) and sys.exit(7)
+            os.system("msgfmt -o %s %s >%s" % (mofile_tmppath, pofile, NULL_STRING)) and sys.exit(7)
+            mofile = mofile_tmppath
         elif opt in ('-o', '--output'):
             output = arg
         elif opt in ('-v', '--version'):
@@ -180,6 +183,9 @@ def main(argv):
         # Standard POT producing
         xml2po_main.to_pot(filenames)
 
+    if mofile_tmppath:
+        os.remove(mofile_tmppath)
+
 # Main program start
 if __name__ == '__main__':
     main(sys.argv[1:])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]