BIND 10 trac1914, updated. a8f2c7a54ea5061e3b4d5ee48fb2e2fd2455c75d [1924] Generate the python version of constant defs
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Feb 4 15:04:58 UTC 2013
The branch, trac1914 has been updated
via a8f2c7a54ea5061e3b4d5ee48fb2e2fd2455c75d (commit)
from 8ea6b0f1c24282a98d7134d8f6e2eb0c181f9ffb (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a8f2c7a54ea5061e3b4d5ee48fb2e2fd2455c75d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Feb 4 16:59:36 2013 +0100
[1924] Generate the python version of constant defs
Generate it from the .cc file, so the are the same.
-----------------------------------------------------------------------
Summary of changes:
src/lib/python/isc/util/Makefile.am | 9 ++++-
src/lib/python/isc/util/pythonize_constants.py | 50 ++++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 src/lib/python/isc/util/pythonize_constants.py
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/util/Makefile.am b/src/lib/python/isc/util/Makefile.am
index 3eaaa12..d5d04bd 100644
--- a/src/lib/python/isc/util/Makefile.am
+++ b/src/lib/python/isc/util/Makefile.am
@@ -1,6 +1,13 @@
SUBDIRS = . cio tests
-python_PYTHON = __init__.py process.py socketserver_mixin.py file.py
+python_PYTHON = __init__.py process.py socketserver_mixin.py file.py \
+ common_defs.py
+BUILT_SOURCES = common_defs.py
+CLEANFILES = $(BUILT_SOURCES)
+EXTRA_DIST = pythonize_constants.py
+
+common_defs.py: $(top_srcdir)/src/lib/util/common_defs.cc pythonize_constants.py
+ $(PYTHON) $(srcdir)/pythonize_constants.py $(top_srcdir)/src/lib/util/common_defs.cc $@
pythondir = $(pyexecdir)/isc/util
diff --git a/src/lib/python/isc/util/pythonize_constants.py b/src/lib/python/isc/util/pythonize_constants.py
new file mode 100644
index 0000000..efda591
--- /dev/null
+++ b/src/lib/python/isc/util/pythonize_constants.py
@@ -0,0 +1,50 @@
+
+# Copyright (C) 2011 Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+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")
+
+[filename_in, filename_out] = sys.argv[1:3]
+
+# Ignore preprocessor, namespaces and the ends of namespaces.
+ignore = re.compile('^(#|namespace|})')
+comment = re.compile('^//(.*)')
+constant = re.compile('^[a-zA-Z].*?([a-zA-Z_0-9]+\\s*=.*);')
+
+with open(filename_in) as file_in, open(filename_out, "w") as file_out:
+ file_out.write("# This file is generated from " + filename_in + "\n" +
+ "# by the pythonize_constants.py script.\n" +
+ "# Do not edit, all changes will be lost.\n\n")
+ for line in file_in:
+ if ignore.match(line):
+ continue
+ # Mangle comments to be python-like
+ line = comment.sub('#\\1', line)
+ # Extract the constant.
+
+ # TODO: We may want to do something with the true vs. True and
+ # NULL vs. None and such. Left out for now, since none are in
+ # the input file currently.
+ line = constant.sub('\\1', line)
+
+ file_out.write(line)
More information about the bind10-changes
mailing list