def LoadSection(self, node, lines, indent=0): while lines: line = lines[0] strip = line.lstrip() newIndent = len(line) - len(strip) split = strip.split(':') key = split[0] if newIndent < indent: return del lines[0] if line.endswith(":"): node[key] = Node() self.LoadSection(node[key], lines, indent + 1) else: try: value = Eval(":".join(split[1:])) except: value = ":".join(split[1:]) node[key] = value
def OnCommandProperty(sender, args): if not sender.hasPermission("ore.config"): sender.sendMessage("No permission!") return True if len(args) == 0: sender.sendMessage(str(CONFIG).replace('\t',' ')) elif len(args) == 1: sender.sendMessage(args[0] + " = " + str(CONFIG[args[0]])) elif len(args) >= 2: if args[1] == 'None': CONFIG[args[0]] = None else: try: value = Eval(' '.join(args[1:])) except: traceback.print_exc() sender.sendMessage('Usage: /property [name] [value]') else: CONFIG[args[0]] = value return True
def get_config_options(self,section_names=None): """ Get all the options of the specified sections. The dict is returned as a nested namespace for its implementation, please see `utils.py` This function also parses the values and converts them to their expected types. This will work on most of the types, but can throw an error if the string is malformed. Args: section_names (list): A list of strings that includes all the sections that need to be included default = None NOTE: If the section_names is None, all the options found in the config file will be used. Returns: namespace : containing all the options and their values """ section_options = dict() if section_names is None: sections = self.parser.sections() else: sections = section_names for section in sections: options = dict(self.parser.items(section)) for k,v in options.items(): options[k] = Eval(v) section_options[section] = options return wrap_namespace(section_options)
def Load(self, node, x): try: data = Eval(x) except: data = {} self.LoadDict(node, data)
def get_safe(self, section, option, **kwargs): try: option = self.get(section, option, **kwargs) return Eval(option) except (SyntaxError, ValueError) as e: try: return self[section][str(option)] except (KeyError, AttributeError) as e: pass return kwargs.pop('fallback', None)
def OnEnable(conf=None): global help, keys Config = conf.node.properties Config.Ensure("HelpPath", "") Config.Ensure("MainPath", "") filename = Config.HelpPath.replace("[path]", Config.MainPath) try: help = Eval(open(filename).read()) keys = help.keys() keys.sort() except: Info("[!]Could not find help file")
def getOptVal(self, section, option): try: return Eval(parm.sub(r'"\1"', self.get(section, option))) except Exception: return None
def get_safe(self, section, option, **kwargs): try: return Eval(self.get(section, option, **kwargs)) except: return kwargs.pop('fallback', None)