diff --git a/variable_grabbler.py b/variable_grabbler.py index 6854940..f1aacbd 100644 --- a/variable_grabbler.py +++ b/variable_grabbler.py @@ -1,7 +1,7 @@ #!/usr/bin/python2 print """ -Variable Grabbler - version 4.0_pre2 +Variable Grabbler - version 4.0_pre4 ------------------------------------""" ################################################################ # Changes in this version: @@ -37,12 +37,15 @@ config_file.close() print "Done." -print "Working on file: "+sys.argv[1] -for variable in config_values: - print "> "+variable.upper()+" => ", +print "Reading file: "+sys.argv[1]+"..." file_in = open(sys.argv[1], "r") file_content = file_in.read() file_in.close() + +print "Replacing variables:" +for variable in config_values: + print "> "+variable.upper()+" => ", + if config_values[variable][0] == "file": print "Found array. Adding file instead: " + config_values[variable][1] file_replacement = open(config_values[variable][1], "r") @@ -78,10 +81,15 @@ 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) replacement = replacement.replace("\\?", "?") print repr(replacement) - print "DEBUG: " + str(argument_positions) - file_out = open(sys.argv[1], "w") - file_out.write(file_content.decode('utf-8').replace("%" + variable.upper() + "%", replacement).encode('utf-8')) - file_out.close() + # actually replace variables + 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") +file_out.write(file_content) +file_out.close() + print "Done."