예제 #1
0
	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
예제 #2
0
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
예제 #3
0
    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)
예제 #4
0
    def Load(self, node, x):
        try:
            data = Eval(x)

        except:
            data = {}

        self.LoadDict(node, data)
예제 #5
0
 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)
예제 #6
0
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")
예제 #7
0
 def getOptVal(self, section, option):
     try:
         return Eval(parm.sub(r'"\1"', self.get(section, option)))
     except Exception:
         return None
예제 #8
0
 def get_safe(self, section, option, **kwargs):
     try:
         return Eval(self.get(section, option, **kwargs))
     except:
         return kwargs.pop('fallback', None)