summaryrefslogtreecommitdiffstats
path: root/src/lib/dns/gen-rdatacode.py.in
diff options
context:
space:
mode:
authorJINMEI Tatuya <jinmei@isc.org>2013-01-26 05:03:40 +0100
committerJINMEI Tatuya <jinmei@isc.org>2013-01-26 05:03:40 +0100
commit62bb1c4ddcb01d285edfdb04016d710597c708e7 (patch)
treed3ae340e5575a127c8dc6f3f79ca8fa456500afd /src/lib/dns/gen-rdatacode.py.in
parent[master]Merge branch 'master' of ssh://git.bind10.isc.org/var/bind10/git/bind10 (diff)
downloadkea-62bb1c4ddcb01d285edfdb04016d710597c708e7.tar.xz
kea-62bb1c4ddcb01d285edfdb04016d710597c708e7.zip
[1866] update gen_rdatacode to autogenerate C++ code for some python wrapper.
specifically, it generates code to create RRType and RRClass constants.
Diffstat (limited to 'src/lib/dns/gen-rdatacode.py.in')
-rwxr-xr-xsrc/lib/dns/gen-rdatacode.py.in44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/lib/dns/gen-rdatacode.py.in b/src/lib/dns/gen-rdatacode.py.in
index fc63d73a06..c3d3a654e6 100755
--- a/src/lib/dns/gen-rdatacode.py.in
+++ b/src/lib/dns/gen-rdatacode.py.in
@@ -255,16 +255,22 @@ class MasterLoaderCallbacks;
def generate_typeclasscode(fileprefix, basemtime, code2txt, type_or_class):
placeholder = '@srcdir@/' + fileprefix + '-placeholder.h'
outputfile = '@builddir@/' + fileprefix + '.h'
+ py_outputfile = '@builddir@/python/' + fileprefix + '_constants_inc.cc'
upper_key = type_or_class.upper() # TYPE or CLASS
lower_key = 'rr' + type_or_class.lower() # rrtype or rrclass
cap_key = type_or_class # Type or Class
- if not need_generate(outputfile, basemtime) and getmtime(outputfile) > getmtime(placeholder):
+ # We only decide whether to generate files for libdns++ files; Python
+ # files are generated if and only if libdns++ files are generated.
+ # In practice it should be sufficient.
+ if (not need_generate(outputfile, basemtime) and
+ getmtime(outputfile) > getmtime(placeholder)):
print('skip generating ' + outputfile)
return
declarationtxt = ''
deftxt = ''
+ pydef_txt = ''
for code in code2txt.keys():
codetxt = code2txt[code].upper()
declarationtxt += ' ' * 4 + 'static const RR' + cap_key + '& ' + codetxt + '();\n'
@@ -274,17 +280,31 @@ RR''' + cap_key + '''::''' + codetxt + '''() {
return (''' + lower_key + ''');
}\n
'''
- header_temp = open(placeholder, 'r')
- header_out = open(outputfile, 'w')
- header_out.write(heading_txt)
- for line in header_temp.readlines():
- header_out.write(line)
- if re.match('\s+// BEGIN_WELL_KNOWN_' + upper_key + '_DECLARATIONS$', line):
- header_out.write(declarationtxt)
- if re.match('// BEGIN_WELL_KNOWN_' + upper_key + '_DEFINITIONS$', line):
- header_out.write('\n' + deftxt)
- header_out.close()
- header_temp.close()
+ pydef_txt += '''\
+ installClassVariable(''' + lower_key + '''_type, "''' + codetxt + '''",
+ createRR''' + cap_key + '''Object(RR''' + \
+ cap_key + '''::''' + codetxt + '''()));
+'''
+
+ # Dump source code for libdns++
+ with open(placeholder, 'r') as header_temp:
+ with open(outputfile, 'w') as header_out:
+ header_out.write(heading_txt)
+ for line in header_temp.readlines():
+ header_out.write(line)
+ if re.match('\s+// BEGIN_WELL_KNOWN_' + upper_key +
+ '_DECLARATIONS$', line):
+ header_out.write(declarationtxt)
+ if re.match('// BEGIN_WELL_KNOWN_' + upper_key +
+ '_DEFINITIONS$', line):
+ header_out.write('\n' + deftxt)
+
+ # Dump source code snippet for isc.dns Python module
+ with open(py_outputfile, 'w') as py_out:
+ py_out.write(" // auto-generated by ../gen-rdatacode.py."
+ " Don't edit this file.\n")
+ py_out.write("\n")
+ py_out.write(pydef_txt)
def generate_rrparam(fileprefix, basemtime):
placeholder = '@srcdir@/' + fileprefix + '-placeholder.cc'