[ooo-build-commit] .: bin/fixguard.py.in bin/.gitignore

Petr Mladek pmladek at kemper.freedesktop.org
Mon Oct 4 07:56:54 PDT 2010


 bin/.gitignore     |    3 +++
 bin/fixguard.py.in |   21 +++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

New commits:
commit 3e496227d77eb26c6b85342c222bd0640d53340c
Author: Petr Mladek <pmladek at suse.cz>
Date:   Mon Oct 4 16:52:49 2010 +0200

    fixguard.py improvements
    
    * handle also guards for .h, .hpp, .hrc files
    * print error when the input file does not exist
    * do not hardcode name of the temporary file
    * use shutil.move instead of os.rename; the original command
      did not move files between partitions

diff --git a/bin/.gitignore b/bin/.gitignore
index fb8a0fc..0f9cee4 100644
--- a/bin/.gitignore
+++ b/bin/.gitignore
@@ -1,3 +1,6 @@
+add_acor.py
+fixguard.py
 font-munge
+gob
 help-font-munge
 setup
diff --git a/bin/fixguard.py.in b/bin/fixguard.py.in
index bddd501..609bc4d 100755
--- a/bin/fixguard.py.in
+++ b/bin/fixguard.py.in
@@ -1,14 +1,27 @@
 #!@PYTHON@
 import sys
 import re
+import os
+import shutil
+import tempfile
 
-exp = '#ifndef.*_HXX.*\n(#include.*\n)#endif.*'
+exp = '#ifndef.*_(?:H|HXX|HRC|HPP)_*\s*\n(#include.*\n)#endif.*\n'
 
-filename = sys.argv[1] # warning no error checking
+filename = sys.argv[1]
+if not os.path.isfile(filename):
+    print "Error: File does not exist: " + filename
+    sys.exit(1)
 
 data = open(filename).read()
 
-o = open("/tmp/fixed","w")
+temp_dir = tempfile.mkdtemp()
+temp_file = temp_dir + "/fixed"
+
+o = open(temp_file,"w")
 o.write( re.sub(exp,"\\1",data) )
 o.close()
-os.rename("/tmp/fixed", filename)
+
+os.chmod(temp_file, 0644)
+shutil.move(temp_file, filename)
+
+os.removedirs(temp_dir)


More information about the ooo-build-commit mailing list