2020-02-23 21:40:16 +01:00
|
|
|
#!/usr/bin/python2
|
|
|
|
|
|
|
|
print """
|
2020-02-24 00:56:44 +01:00
|
|
|
Variable Grabbler - version 2.0
|
2020-02-23 21:40:16 +01:00
|
|
|
-------------------------------"""
|
|
|
|
|
|
|
|
# definitions
|
2020-02-24 00:56:44 +01:00
|
|
|
import os, json, sys
|
2020-02-23 21:40:16 +01:00
|
|
|
|
2020-02-24 00:56:44 +01:00
|
|
|
if not len(sys.argv)==3:
|
|
|
|
print >> sys.stderr, "Error: Exactly two arguments required: \"python variable_grabbler.py <file to be rewritten> <config file>\""
|
|
|
|
sys.exit(1)
|
2020-02-23 21:40:16 +01:00
|
|
|
|
2020-02-24 00:04:25 +01:00
|
|
|
print "Reading config file...",
|
2020-02-24 00:56:44 +01:00
|
|
|
config = open(sys.argv[2],"r")
|
2020-02-24 00:26:22 +01:00
|
|
|
parsed = json.loads(config.read().decode("utf-8"))
|
2020-02-23 23:42:13 +01:00
|
|
|
config.close()
|
2020-02-24 00:04:25 +01:00
|
|
|
print "Done."
|
2020-02-23 21:40:16 +01:00
|
|
|
|
2020-02-24 00:56:44 +01:00
|
|
|
print "Working on file: "+sys.argv[1]
|
2020-02-23 23:06:34 +01:00
|
|
|
for x in parsed:
|
2020-02-24 00:56:44 +01:00
|
|
|
print x,
|
|
|
|
file_in = open(sys.argv[1], "r")
|
|
|
|
file_content = file_in.read()
|
|
|
|
file_in.close()
|
|
|
|
file_out = open(file_path, "w")
|
|
|
|
file_out.write(file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8'))
|
|
|
|
file_out.close()
|
2020-02-24 00:14:31 +01:00
|
|
|
print "\nDone."
|