102 lines
3.6 KiB
Python
102 lines
3.6 KiB
Python
|
|
#!/usr/bin/python
|
||
|
|
import re
|
||
|
|
infile = open('eyeconstants.h')
|
||
|
|
lines = infile.read().split("\n")
|
||
|
|
genconstants = False
|
||
|
|
|
||
|
|
# Generate the Java constants
|
||
|
|
def WriteClassHeader (f, c):
|
||
|
|
print >> f, ("package com.sequencelogic;")
|
||
|
|
print >> f, ("/* ** AUTO-GENERATED FILE - DO NOT EDIT ** */")
|
||
|
|
print >> f, ("/* This file was automatically generated from eyeconstants.h*/")
|
||
|
|
print >> f, ("public final class {0} {{".format (c));
|
||
|
|
print >> f, (" private {0}() {{".format (c));
|
||
|
|
print >> f, (" // restrict instantiation");
|
||
|
|
print >> f, (" }");
|
||
|
|
|
||
|
|
# Generate the C++ constants
|
||
|
|
def WriteNameSpace (f, c):
|
||
|
|
print >> f, ("/* ** AUTO-GENERATED FILE - DO NOT EDIT ** */")
|
||
|
|
print >> f, ("/* This file was automatically generated from eyeconstants.h*/")
|
||
|
|
print >> f, ("namespace sequencelogic {");
|
||
|
|
print >> f, (" namespace {0} {{".format (c));
|
||
|
|
|
||
|
|
if genconstants == True:
|
||
|
|
print ("package com.sequencelogic;")
|
||
|
|
print ("public final class EyeConstants {");
|
||
|
|
print ("private EyeConstants() {");
|
||
|
|
print (" // restrict instantiation");
|
||
|
|
print ("}");
|
||
|
|
|
||
|
|
javafile = ""
|
||
|
|
for line in lines:
|
||
|
|
if line.startswith ("//namespace"):
|
||
|
|
tokens = line.split()
|
||
|
|
javafile = "java/com/sequencelogic/" + tokens[1] + ".java"
|
||
|
|
print (javafile);
|
||
|
|
cppfile = tokens[1] + ".cpp"
|
||
|
|
java = open (javafile, "w")
|
||
|
|
cpp = open (cppfile, "w")
|
||
|
|
WriteNameSpace (cpp, tokens[1])
|
||
|
|
WriteClassHeader (java, tokens[1])
|
||
|
|
prefix = tokens[1].upper() + "_"
|
||
|
|
elif line.startswith ("//}"):
|
||
|
|
print >> java, ("}");
|
||
|
|
print >> cpp, (" }");
|
||
|
|
print >> cpp, ("}");
|
||
|
|
cpp.close()
|
||
|
|
cppfile = ""
|
||
|
|
java.close()
|
||
|
|
javafile = ""
|
||
|
|
elif line.startswith ("#define"):
|
||
|
|
tokens = line.split()
|
||
|
|
index = len (tokens) - 1
|
||
|
|
if index >= 2 :
|
||
|
|
var = tokens[1]
|
||
|
|
val = tokens[2]
|
||
|
|
comment = "";
|
||
|
|
if index >= 3 and tokens[3].startswith ("//"):
|
||
|
|
comment = "\n /**\n * " + line[line.index ("//") + 3:] + "\n */\n";
|
||
|
|
if val.startswith ("\""):
|
||
|
|
cpptype = "char* const"
|
||
|
|
type = "String";
|
||
|
|
elif "." in val:
|
||
|
|
type = "double";
|
||
|
|
elif val.isdigit():
|
||
|
|
type = "int";
|
||
|
|
|
||
|
|
if javafile == "":
|
||
|
|
if genconstants == True:
|
||
|
|
print ("{0} public static final {1} {2} = {3};".format (comment, type, var, val));
|
||
|
|
else:
|
||
|
|
var = var.replace (prefix, "")
|
||
|
|
#print >> cpp, ("{0} static const {1} {2} = {3};".format (comment, cpptype, var, val));
|
||
|
|
print >> java, ("{0} public static final {1} {2} = {3};".format (comment, type, var, val));
|
||
|
|
|
||
|
|
if genconstants == True:
|
||
|
|
print ("}");
|
||
|
|
|
||
|
|
# Generate the mongodb policy
|
||
|
|
mngo = open ("mongo-policy.txt", "w")
|
||
|
|
print >> mngo, ("db.van.update({_id:'urn:sl:000000:::'}, {$set: {policies: [");
|
||
|
|
for line in lines:
|
||
|
|
if line.startswith ("#define PN_"):
|
||
|
|
tokens = line.split()
|
||
|
|
if len (tokens) >= 6 and tokens[1].startswith ("PN_"):
|
||
|
|
policy = tokens[2]
|
||
|
|
ptype = tokens[4]
|
||
|
|
pdefault = tokens[5]
|
||
|
|
if ptype == "list":
|
||
|
|
plist = tokens[6]
|
||
|
|
prompt = tokens[7].replace ("@@", "")
|
||
|
|
if len (tokens) > 8:
|
||
|
|
prompt += " " + " ".join (tokens[8:])
|
||
|
|
else:
|
||
|
|
plist = "[]"
|
||
|
|
prompt = tokens[6].replace ("@@", "")
|
||
|
|
if len (tokens) > 7:
|
||
|
|
prompt += " " + " ".join (tokens[7:])
|
||
|
|
print >> mngo, ("{{policyName: {0}, type: '{1}', value:{2}, list:{3}, prompts:{{\"en_US\":{4}}}}},".format ( policy, ptype, pdefault, plist, prompt));
|
||
|
|
print >> mngo, ("]}}, {upsert:true})");
|
||
|
|
mngo.close()
|