config.py

来自「Unix下的MUD客户端程序」· Python 代码 · 共 58 行

PY
58
字号
import osimport reprimary_config_file_path = os.environ["HOME"] + "/.mcl/config.python"secondary_config_file_path = os.environ["HOME"] + "/.mcl/config"AutoLoad = {}AutoSave = []loading = 0def load_configuration():  global loading  try:    config_file = open(primary_config_file_path, "r")  except IOError:    try:      config_file = open(secondary_config_file_path, "r")    except IOError:      return  config_re_regex = re.compile(r"(\w+)\s*(.*)")    loading = 1  while 1:    curr_line = config_file.readline()        if curr_line == "":      break    if curr_line[0] == "#" or curr_line[0] == "\n":      continue         config_re_match = config_re_regex.search(curr_line)    if config_re_match:      if AutoLoad.has_key(config_re_match.group(1)):        AutoLoad[config_re_match.group(1)](config_re_match.group(2))    else:      print "Unsupported keyword found in config file"    config_file.close()  loading = 0def load_add(name, function):  global AutoLoad  AutoLoad[name] = functiondef save_add(function):  global AutoSave  AutoSave.append(function)  def save_configuration():  try:    config_file = open(primary_config_file_path, "w")  except IOError:    return  config_file.write("# mcl module config file generated by mcl\n")  for save_func in AutoSave:    save_func(config_file)  config_file.close()  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?