Imported from archive.
[mudpy.git] / lib / muff / muffvars.py
1 """Global variable objects for the MUFF Engine"""
2
3 # Copyright (c) 2005 mudpy, Jeremy Stanley <fungi@yuggoth.org>, all rights reserved.
4 # Licensed per terms in the LICENSE file distributed with this software.
5
6 # persistent variables are stored in ini-style files supported by ConfigParser
7 import ConfigParser
8
9 # hack to load all modules in the muff package
10 import muff
11 for module in muff.__all__:
12         exec("import " + module)
13
14 # does the files:variable setting exist yet?
15 try:
16         if muffconf.get("files", "variable"): pass
17
18 # if not, reload the muffconf module
19 except AttributeError:
20         reload(muffconf)
21
22 # now we can safely load persistent variables from file
23 variable_file = muffconf.get("files", "variable")
24 variable_data = ConfigParser.SafeConfigParser()
25 variable_data.read(variable_file)
26
27 # if there is no userlist, create an empty one
28 try:
29         if userlist: pass
30 except NameError:
31         userlist = []
32
33 # if there is no listening socket, create an empty one
34 try:
35         if newsocket: pass
36 except NameError:
37         newsocket = None
38
39 # flag to raise when the world should be shut down
40 terminate_world = False
41
42 # flag to raise when all code modules, config and data should be reloaded
43 reload_modules = False
44
45 # a dict of replacement macros
46 macros = {
47         "$(eol)": "\r\n",
48         "$(bld)": chr(27) + "[1m",
49         "$(nrm)": chr(27) + "[0m",
50         "$(blk)": chr(27) + "[30m",
51         "$(grn)": chr(27) + "[32m",
52         "$(red)": chr(27) + "[31m"
53         }
54
55 # function to save persistent variables to file
56 def save():
57         file_descriptor = open(variable_file, "w")
58         variable_data.write(file_descriptor)
59         file_descriptor.flush()
60         file_descriptor.close()
61