Skip to content

Commit

Permalink
Only re-write on diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnealtowns committed Aug 21, 2017
1 parent ad064c4 commit cb9b9e5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tools/uclihandlers2.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import sys
import re
import pprint
import infra
import wod

class UcliGenerator(object):
def __init__(self):
Expand Down Expand Up @@ -168,7 +170,7 @@ def __emit_inits(self, key, value, parent):
name = key
else:
name = "%s__%s" % (parent, key)
s += ' if(%s__node__ == NULL) %s__node__ = ucli_node_create("%s", NULL, NULL);\n' % (name, name, key)
s += ' if(%s__node__ == NULL) %s__node__ = ucli_node_create("%s", NULL, NULL);\n' % (name, name, key.replace("_ucli", ""))
for(k, v) in value.iteritems():
s += self.__emit_inits(k, v, name)

Expand Down Expand Up @@ -209,8 +211,8 @@ def generate_str(self):
return s


def update(self, fname):
source = open(fname).read()
def update(self, src, stdout=False):
source = open(src).read()
start = "/* <auto.ucli.handlers.start> */"
end = "/* <auto.ucli.handlers.end> */"

Expand All @@ -233,9 +235,17 @@ def update(self, fname):
expr = rstart + ".*" + rend
source = re.sub(expr, s, source, flags=re.DOTALL)

with open(fname, "w") as f:
f.write(source)

u = UcliGenerator()
u.add_file(sys.argv[1])
u.update(sys.argv[1])
if stdout:
print source
else:
wod.write_on_diff(src, source, msg=False)

if __name__ == '__main__':
import argparse
ap = argparse.ArgumentParser("uclihandlers2")
ap.add_argument("source", help="uCli Source file.")
ap.add_argument("--stdout", help="Send output to stdout instead of updating the source file.", action='store_true')
ops = ap.parse_args()
u = UcliGenerator()
u.add_file(ops.source)
u.update(ops.source, ops.stdout)

0 comments on commit cb9b9e5

Please sign in to comment.