# 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__:
"$(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()