Files
ResInsight/ThirdParty/Ert/cmake/cmake_pyc_tree

36 lines
1006 B
Python

#!/usr/bin/env python
import py_compile
import os
import sys
import os.path
# Small 'python compiler' used in the build system for ert. The
# commandline argument should be the top level name of directory
# containing python source code. The 'compiler' will walk through the
# tree and in-place compile all the python files.
root_path = sys.argv[1]
for (root , dir_list , file_list) in os.walk( root_path ):
for file in file_list:
full_path = os.path.join( root , file )
(tmp , ext) = os.path.splitext( full_path )
if ext == ".py":
py_file = full_path
pyc_file = full_path + "c"
if os.path.exists( pyc_file ):
os.unlink( pyc_file )
try:
print "Compiling: %s" % py_file
py_compile.compile( py_file , doraise = True )
except Exception,error:
sys.exit("py_compile(%s) failed:%s" % (py_file , error))
sys.exit(0)