Browse Source

[1924] Comments and cleanups in the generator scripts

Michal 'vorner' Vaner 12 years ago
parent
commit
57c90f7a92
2 changed files with 28 additions and 10 deletions
  1. 14 5
      src/lib/python/isc/util/pythonize_constants.py
  2. 14 5
      src/lib/util/const2hdr.py

+ 14 - 5
src/lib/python/isc/util/pythonize_constants.py

@@ -13,15 +13,24 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+'''
+This script takes a C++ file with constants and converts it to a python
+module. However, the syntax it parses is very limited (it doesn't understand
+C++ at all, it just looks for lines containing the equal sign and strips
+what it thinks might be type).
+
+The purpose is to keep the same values of constants in C++ and python. This
+saves the work of keeping the constants in sync manually and is less error
+prone.
+'''
+
 import sys
 import re
 
-def die(message):
-    sys.stderr.write(message + "\n")
-    sys.exit(1)
-
 if len(sys.argv) != 3:
-    die("Usage: python3 ./pythonize_constants.py input.cpp output.py")
+    sys.stderr.write("Usage: python3 ./pythonize_constants.py input.cpp output.py\n")
+    sys.exit(1)
+    die(
 
 [filename_in, filename_out] = sys.argv[1:3]
 

+ 14 - 5
src/lib/util/const2hdr.py

@@ -13,15 +13,24 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+'''
+The script takes a C++ file with constant definitions and creates a
+header file for the constants. It, however, does not understand C++
+syntax, it only does some heuristics to guess what looks like
+a constant and strips the values.
+
+The purpose is just to save some work with keeping both the source and
+header. The source syntax must be limited already, because it's used to
+generate the python module (by the
+lib/python/isc/util/pythonize_constants.py script).
+'''
+
 import sys
 import re
 
-def die(message):
-    sys.stderr.write(message + "\n")
-    sys.exit(1)
-
 if len(sys.argv) != 3:
-    die("Usage: python3 ./const2hdr.py input.cpp output.h")
+    sys.stderr.write("Usage: python3 ./const2hdr.py input.cc output.h\n")
+    sys.exit(1)
 
 [filename_in, filename_out] = sys.argv[1:3]