Skip to content

Instantly share code, notes, and snippets.

@DannyWeitekamp
Last active January 15, 2019 02:27
Show Gist options
  • Select an option

  • Save DannyWeitekamp/2d60a5d207162c5d8d6b7e5b97fb56bc to your computer and use it in GitHub Desktop.

Select an option

Save DannyWeitekamp/2d60a5d207162c5d8d6b7e5b97fb56bc to your computer and use it in GitHub Desktop.
Turns BRDs built for java CTAT to BRDs for html
import sys, glob, os, re
print(len(sys.argv))
if(len(sys.argv) < 3):
print("Proper Usage:")
print("%s <input.brd or folder w/ .brds> <output file or folder>" % sys.argv[0])
exit()
inp = os.path.abspath(sys.argv[1]);
out = os.path.abspath(sys.argv[2]);
if(os.path.isfile(inp)):
toprocess = [inp]
elif(os.path.isdir(inp)):
assert os.path.isdir(out), "output %r is not valid directory" % out
toprocess = glob.glob(inp + os.sep + "*.brd")
assert len(toprocess) > 0, "no .brd files found in directory %r" % inp
out_is_dir = os.path.isdir(out)
out_template = out + os.sep + "%s" if out_is_dir else out
for x in toprocess:
print(x)
# out_template = out + "%s"
# elif(os.path.isfile(out)):
# out_template = out + "%s"
# Does bob.txt exist? Is it a file, or a directory?
# wholeTag = re.compile(r"<value>.*_C\d+R\d+</value>")
inner = re.compile(r"_C\d+R\d+")
for x in toprocess:
with open(x, "rt") as fin:
y = out_template % fin.name.split(os.sep)[-1] if out_is_dir else out_template
with open(y, "wt") as fout:
for line in fin:
if(inner.search(line)):
# val = next(inner.finditer(line)).group(0)
# val = val[1:]
val = inner.search(line).group(0)
# name, rest = val.split("_")
C,R = re.findall(r'\d+',val)
repl = "." + "R%sC%s" % (int(R)-1,int(C)-1)
line = re.sub(inner, repl, line)
# print(line)
line = line.replace('UpdateTable', "UpdateTextArea")
fout.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment