master
BodgeMaster 2020-04-08 05:22:50 +02:00
parent 1f146b7b04
commit 219f0a4da5
1 changed files with 10 additions and 8 deletions

View File

@ -1,22 +1,23 @@
#!/usr/bin/python2
print """
Variable Grabbler - version 4.0_pre4
Variable Grabbler - version 4.0_pre6
------------------------------------"""
################################################################
# Changes in this version:
#===============================================================
# *"\?" in a variable will now be replaced with a simple ?
# before processing, remember to double escape that because
# json (=> \\?)
# json doesn't like \? (=> \\?)
# *commands are now not run over and over again if not needed
#
# *files are now not rewritten for each variable individually
# *some technical stuff
################################################################
# Exit codes:
#===============================================================
# 0 => normal exit
# 1 => argument error
# 1 => command line argument error
# 2 => error while processing
#
@ -49,7 +50,7 @@ for variable in config_values:
if config_values[variable][0] == "file":
print "Found array. Adding file instead: " + config_values[variable][1]
file_replacement = open(config_values[variable][1], "r")
replacement = file_replacement.read()
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", file_replacement.read()).encode('utf-8')
file_replacement.close()
elif config_values[variable][0] == "exec":
print "Found array. Executing command instead: " + config_values[variable][1]
@ -60,7 +61,7 @@ for variable in config_values:
print "Process exited normally. Replacing variable with the output from STDOUT..."
print_err("Subprocess exited normally.\nThe following error messages were produced:")
print_err(stderr)
replacement = stdout
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", stdout).encode('utf-8')
else:
print "Process exited abnormally. Exiting. No changes will be made."
print_err("Subprocess exited abnormally. Exiting.\nThe following output was produced:")
@ -81,11 +82,12 @@ for variable in config_values:
if replacement[i] == '?' and (i==0 or not replacement[i-1]=='\\'):
argument_positions = argument_positions + [ i ]
i = i+1
print "DEBUG: " + str(argument_positions)
#print "DEBUG: " + str(argument_positions)
replacement = replacement.replace("\\?", "?")
print repr(replacement)
# actually replace variables
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", replacement).encode('utf-8')
if argument_positions == []:
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", replacement).encode('utf-8')
print "Saving new file..."
file_out = open(sys.argv[1], "w")