42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
#!/usr/bin/python2
|
|
|
|
print """
|
|
Variable Grabbler - version 1.9
|
|
-------------------------------"""
|
|
|
|
# definitions
|
|
import os, json, fnmatch
|
|
|
|
dir = os.path.dirname(os.path.abspath(__file__))
|
|
file_name_pattern = "*.php"
|
|
|
|
print "Reading config file...",
|
|
config = open("variable_grabbler.cfg","r")
|
|
parsed = json.loads(config.read().decode(utf-8))
|
|
config.close()
|
|
print "Done."
|
|
|
|
print "Working on files:",
|
|
for x in parsed:
|
|
print "\n["+x+"]:",
|
|
for path, dirs, files in os.walk(dir):
|
|
printed_path = False
|
|
for file_name in fnmatch.filter(files, file_name_pattern):
|
|
file_path = os.path.join(path, file_name)
|
|
|
|
if not printed_path:
|
|
print "\n"+path+" >",
|
|
printed_path = True
|
|
print file_name,
|
|
|
|
file_in = open(file_path, "r")
|
|
file_content = file_in.read()
|
|
file_in.close()
|
|
|
|
file_content = file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8')
|
|
|
|
file_out = open(file_path, "w")
|
|
file_out.write(file_content)
|
|
file_out.close()
|
|
print "\nDone."
|