forked from root/threadr.lostcave.ddnss.de
blob
parent
1f146b7b04
commit
219f0a4da5
|
@ -1,22 +1,23 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python2
|
||||||
|
|
||||||
print """
|
print """
|
||||||
Variable Grabbler - version 4.0_pre4
|
Variable Grabbler - version 4.0_pre6
|
||||||
------------------------------------"""
|
------------------------------------"""
|
||||||
################################################################
|
################################################################
|
||||||
# Changes in this version:
|
# Changes in this version:
|
||||||
#===============================================================
|
#===============================================================
|
||||||
# *"\?" in a variable will now be replaced with a simple ?
|
# *"\?" in a variable will now be replaced with a simple ?
|
||||||
# before processing, remember to double escape that because
|
# 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
|
# *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:
|
# Exit codes:
|
||||||
#===============================================================
|
#===============================================================
|
||||||
# 0 => normal exit
|
# 0 => normal exit
|
||||||
# 1 => argument error
|
# 1 => command line argument error
|
||||||
# 2 => error while processing
|
# 2 => error while processing
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ for variable in config_values:
|
||||||
if config_values[variable][0] == "file":
|
if config_values[variable][0] == "file":
|
||||||
print "Found array. Adding file instead: " + config_values[variable][1]
|
print "Found array. Adding file instead: " + config_values[variable][1]
|
||||||
file_replacement = open(config_values[variable][1], "r")
|
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()
|
file_replacement.close()
|
||||||
elif config_values[variable][0] == "exec":
|
elif config_values[variable][0] == "exec":
|
||||||
print "Found array. Executing command instead: " + config_values[variable][1]
|
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 "Process exited normally. Replacing variable with the output from STDOUT..."
|
||||||
print_err("Subprocess exited normally.\nThe following error messages were produced:")
|
print_err("Subprocess exited normally.\nThe following error messages were produced:")
|
||||||
print_err(stderr)
|
print_err(stderr)
|
||||||
replacement = stdout
|
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", stdout).encode('utf-8')
|
||||||
else:
|
else:
|
||||||
print "Process exited abnormally. Exiting. No changes will be made."
|
print "Process exited abnormally. Exiting. No changes will be made."
|
||||||
print_err("Subprocess exited abnormally. Exiting.\nThe following output was produced:")
|
print_err("Subprocess exited abnormally. Exiting.\nThe following output was produced:")
|
||||||
|
@ -81,10 +82,11 @@ for variable in config_values:
|
||||||
if replacement[i] == '?' and (i==0 or not replacement[i-1]=='\\'):
|
if replacement[i] == '?' and (i==0 or not replacement[i-1]=='\\'):
|
||||||
argument_positions = argument_positions + [ i ]
|
argument_positions = argument_positions + [ i ]
|
||||||
i = i+1
|
i = i+1
|
||||||
print "DEBUG: " + str(argument_positions)
|
#print "DEBUG: " + str(argument_positions)
|
||||||
replacement = replacement.replace("\\?", "?")
|
replacement = replacement.replace("\\?", "?")
|
||||||
print repr(replacement)
|
print repr(replacement)
|
||||||
# actually replace variables
|
# actually replace variables
|
||||||
|
if argument_positions == []:
|
||||||
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", replacement).encode('utf-8')
|
file_content = file_content.decode('utf-8').replace("%" + variable.upper() + "%", replacement).encode('utf-8')
|
||||||
|
|
||||||
print "Saving new file..."
|
print "Saving new file..."
|
||||||
|
|
Loading…
Reference in New Issue