threadr.lostcave.ddnss.de/variable_grabbler.py

42 lines
1.0 KiB
Python
Raw Normal View History

2020-02-23 21:40:16 +01:00
#!/usr/bin/python2
print """
2020-02-24 00:16:25 +01:00
Variable Grabbler - version 1.9
2020-02-23 21:40:16 +01:00
-------------------------------"""
# definitions
import os, json, fnmatch
2020-02-23 21:40:16 +01:00
dir = os.path.dirname(os.path.abspath(__file__))
2020-02-23 23:45:08 +01:00
file_name_pattern = "*.php"
2020-02-23 21:40:16 +01:00
2020-02-24 00:04:25 +01:00
print "Reading config file...",
config = open("variable_grabbler.cfg","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:16:25 +01:00
print "Working on files:",
for x in parsed:
2020-02-24 00:16:25 +01:00
print "\n["+x+"]:",
for path, dirs, files in os.walk(dir):
2020-02-24 00:10:25 +01:00
printed_path = False
2020-02-24 00:04:25 +01:00
for file_name in fnmatch.filter(files, file_name_pattern):
file_path = os.path.join(path, file_name)
2020-02-23 23:42:13 +01:00
2020-02-24 00:10:25 +01:00
if not printed_path:
2020-02-24 00:14:31 +01:00
print "\n"+path+" >",
2020-02-24 00:10:25 +01:00
printed_path = True
2020-02-24 00:04:25 +01:00
print file_name,
2020-02-23 23:42:13 +01:00
2020-02-24 00:04:25 +01:00
file_in = open(file_path, "r")
file_content = file_in.read()
file_in.close()
2020-02-24 00:04:25 +01:00
file_content = file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8')
2020-02-24 00:04:25 +01:00
file_out = open(file_path, "w")
file_out.write(file_content)
file_out.close()
2020-02-24 00:14:31 +01:00
print "\nDone."