diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-05-27 21:58:22 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-05-27 21:58:22 +0000 |
commit | bf9cf5ec1e161bf745cd9c852b4d0261acc209d3 (patch) | |
tree | bfd4796f8e41177a5c8bc5a3f0427c56fce14cfa /lldb/scripts/Python/edit-swig-python-wrapper-file.py | |
parent | 041ec4aadaa87d1c7ce5f146e6b5b666143a74c9 (diff) | |
download | bcm5719-llvm-bf9cf5ec1e161bf745cd9c852b4d0261acc209d3.tar.gz bcm5719-llvm-bf9cf5ec1e161bf745cd9c852b4d0261acc209d3.zip |
Use the with statement to simplify the build script.
llvm-svn: 132221
Diffstat (limited to 'lldb/scripts/Python/edit-swig-python-wrapper-file.py')
-rw-r--r-- | lldb/scripts/Python/edit-swig-python-wrapper-file.py | 62 |
1 files changed, 20 insertions, 42 deletions
diff --git a/lldb/scripts/Python/edit-swig-python-wrapper-file.py b/lldb/scripts/Python/edit-swig-python-wrapper-file.py index 4a71da1dff4..e0efb49f1a7 100644 --- a/lldb/scripts/Python/edit-swig-python-wrapper-file.py +++ b/lldb/scripts/Python/edit-swig-python-wrapper-file.py @@ -20,52 +20,30 @@ # That's what this python script does. # - import os +include_python = '#include <Python.h>' +include_python_ifdef = '''#if defined (__APPLE__) +#include <Python/Python.h> +#else +#include <Python.h> +#endif +''' + input_dir_name = os.environ["SRCROOT"] full_input_name = input_dir_name + "/source/LLDBWrapPython.cpp" full_output_name = full_input_name + ".edited" -try: - f_in = open (full_input_name, 'r') -except IOError: - print "Error: Unable to open file for reading: " + full_input_name -else: - try: - f_out = open (full_output_name, 'w') - except IOError: - print "Error: Unable to open file for writing: " + full_output_name - else: - include_line_found = False +with open(full_input_name, 'r') as f_in: + with open(full_output_name, 'w') as f_out: + include_python_found = False + for line in f_in: + if not include_python_found: + if line.startswith(include_python): + # Write out the modified lines. + f_out.write(include_python_ifdef) + include_python_found = True + continue - try: - line = f_in.readline() - except IOError: - print "Error occurred while reading file." - else: - while line: - # - # - if not include_line_found: - if (line.find ("#include <Python.h>") == 0): - f_out.write ("#if defined (__APPLE__)\n"); - f_out.write ("#include <Python/Python.h>\n"); - f_out.write ("#else\n"); - f_out.write (line); - f_out.write ("#endif\n"); - include_line_found = True - else: - f_out.write (line) - else: - f_out.write (line) - try: - line = f_in.readline() - except IOError: - print "Error occurred while reading file." - - try: - f_in.close() - f_out.close() - except: - print "Error occurred while closing files" + # Otherwise, copy the line verbatim to the output file. + f_out.write(line) |