1 """Global variable objects for the MUFF Engine"""
3 # Copyright (c) 2005 MUDpy, The Fungi <fungi@yuggoth.org>, all rights reserved.
4 # Licensed per terms in the LICENSE file distributed with this software.
6 # persistent variables are stored in ini-style files supported by ConfigParser
9 # need to be able to create the variable save file's directory
12 # hack to load all modules in the muff package
14 for module in muff.__all__:
15 exec("import " + module)
17 # does the files:variable setting exist yet?
19 if muffconf.get("files", "variable"): pass
21 # if not, reload the muffconf module
22 except AttributeError:
25 # now we can safely load persistent variables from file
26 variable_file = muffconf.get("files", "variable")
27 variable_data = ConfigParser.SafeConfigParser()
28 variable_data.read(variable_file)
30 # if there is no userlist, create an empty one
36 # if there is no listening socket, create an empty one
42 # flag to raise when the world should be shut down
43 terminate_world = False
45 # flag to raise when all code modules, config and data should be reloaded
46 reload_modules = False
48 # a dict of replacement macros
51 "$(bld)": chr(27) + "[1m",
52 "$(nrm)": chr(27) + "[0m",
53 "$(blk)": chr(27) + "[30m",
54 "$(grn)": chr(27) + "[32m",
55 "$(red)": chr(27) + "[31m"
59 """Function to save persistent variables to a file."""
61 # try to open the variable file
63 file_descriptor = file(variable_file, "w")
65 # failing that, make the directory in which it resides first
67 os.makedirs(os.sep.join(variable_file.split(os.sep)[:-1]))
68 file_descriptor = file(variable_file, "w")
70 # now write the data and close out the file
71 variable_data.write(file_descriptor)
72 file_descriptor.flush()
73 file_descriptor.close()