Don't write actual values, everything is a variable
@@ -7,35 +7,25 @@ Usage:
"""
from sys import argv
from os.path import join, dirname
-from os import environ
if __name__ == "__main__":
var_file = argv[1]
# Get a list of variables that are set, and their current values
- variables = {}
+ variables = []
with open(var_file) as ifile:
for line in ifile:
exp, _ = line.split("=")
- var = exp.split()[1]
- variables[var] = environ.get(var)
+ variables.append(exp.split()[1])
# Write a script that stores those values when sourced
backup_file = join(dirname(var_file), "backup_conda.sh")
with open(backup_file, "w") as ofile:
- for var, val in variables.items():
- ofile.write("export " + var + "_CONDA=")
- if val is None:
- ofile.write('""')
- else:
- ofile.write(val)
- ofile.write("\n")
+ for var in variables:
+ ofile.write("export " + var + "_CONDA=$" + var + "\n")
# Write a script that restores those values
restore_file = join(dirname(var_file), "restore_conda.sh")
with open(restore_file, "w") as ofile:
- for var, val in variables.items():
+ for var in variables:
ofile.write("export " + var + "=$" + var + "_CONDA\n")
- print(backup_file)
- print(restore_file)
- pass
