X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=lib%2Fmuff%2Fmuffvars.py;h=1abfe86acc87c02998c05aec136ab28bd35a483e;hp=9e6f9f1b3b0b7edc96abcb701e8888305938e8b0;hb=da136e612520ef6a3a19d99563e44b6518f91e7e;hpb=1ff00115321d800bec7313a3fdfc97a8b0b006fa diff --git a/lib/muff/muffvars.py b/lib/muff/muffvars.py index 9e6f9f1..1abfe86 100644 --- a/lib/muff/muffvars.py +++ b/lib/muff/muffvars.py @@ -6,6 +6,9 @@ # persistent variables are stored in ini-style files supported by ConfigParser import ConfigParser +# need to be able to create the variable save file's directory +import os + # hack to load all modules in the muff package import muff for module in muff.__all__: @@ -52,9 +55,19 @@ macros = { "$(red)": chr(27) + "[31m" } -# function to save persistent variables to file def save(): - file_descriptor = open(variable_file, "w") + """Function to save persistent variables to a file.""" + + # try to open the variable file + try: + file_descriptor = file(variable_file, "w") + + # failing that, make the directory in which it resides first + except IOError: + os.makedirs(os.sep.join(variable_file.split(os.sep)[:-1])) + file_descriptor = file(variable_file, "w") + + # now write the data and close out the file variable_data.write(file_descriptor) file_descriptor.flush() file_descriptor.close()