i sure there must more intelligent way achieve this. need change app id in javascript before minifying closure.
one "quick" solution came with, using old sed. while works on command line, fails when run within python file. doesn't fail error. outfile file exact copy of source. if hasn't found text.
choice = raw_input("type 1 (staging) or 2 (production)?") if choice == '1': cmd = r"sed 's%var appid = '1234';%var appid = '5678';%' {0}f11.js > {0}f11_final.js".format(path) os.system(cmd) any idea missing? thanks
update:
i changed source this:
var appid = '1'; to this:
var appid = 1; and ran successfully:
cmd = "sed -i 's%var appid = 1;%var appid = 2;%' {0}f11.js".format(path) it has escaping single quotes. idea do? tried \' fails.
solution:
i ended doing in python suggested. not easy though, if haven't done before. share code:
with open("{0}f11.js".format(path), "r") sources: lines = sources.readlines() open("{0}f11-final.js".format(path), "w") sources: line in lines: sources.write(re.sub("var appid = '1';", "var appid = '2';", line))
you can use library re of python. in particular function sub similar sed.
Comments
Post a Comment