Esempio n. 1
0
def getPlugins():
    """
	This function is used to get a list of the plugins registered for use with
	PyRC.
	
	@rtype: tuple
	@return: A tuple containing the names of all plugins registered for use with
	    PyRC. Its elements have the following form::
	     (<module_name:unicode>, <load:bool>)
	"""
    try:
        _xml_handler.lock()
        plugins = []
        for i in _xml_handler.getNodes("/settings/plugins/plugin"):
            value = parsers.xml_getAttributeValue(i, "load")
            if value:
                value = C_FUNCS.evaluateTruth(value)
            else:
                value = True

            plugins.append((parsers.xml_getNodeValue(i), value))

        return tuple(plugins)
    finally:
        _xml_handler.unlock()
Esempio n. 2
0
def getInterface():
    """
	This function is used to get the interface value from the settings data.
	
	@rtype: unicode|None
	@return: The interface value, or None if no interface is specified.
	"""
    try:
        _xml_handler.lock()
        node = _xml_handler.getNode("/settings/interface")
        if not node:
            return
        return parsers.xml_getNodeValue(node)
    finally:
        _xml_handler.unlock()
Esempio n. 3
0
def getFormat(format_path):
    """
	This function is used to get a format value from the settings data.
	
	@type option_path: basestring
	@param option_path: The path of the format to be retrieved, dot-separated.
	
	@rtype: unicode|None
	@return: The requested value, or None if the value could not be found.
	"""
    try:
        _xml_handler.lock()
        return parsers.xml_getNodeValue(_xml_handler.getNode("/settings/formats/" + format_path.replace(".", "/")))
    finally:
        _xml_handler.unlock()
Esempio n. 4
0
def _getProfileDetailsFromNode(node):
	"""
	This function is used to process a <profile/> node from the XML tree and
	return the details it contains.
	
	@type node: Node|None
	@param node: The node retrieved from the XML tree. This may be None.
	
	@rtype: tuple|None
	@return: The information stored in the <profile/> node, represented as a
	    tuple, or None if the node does not exist. The tuple's
	    structure follows::
		 (<nicknames:tuple>, <ident:unicode>, <real_name:unicode>)
	"""
	if node:
		nicknames = []
		nickname_node = node.xpath("nicknames")[0]
		for i in nickname_node.xpath("nickname"):
			nicknames.append(parsers.xml_getNodeValue(i))
			
		return (nicknames, parsers.xml_getSubNodeValue(node, "ident"), parsers.xml_getSubNodeValue(node, "realname"))
	return None
	
Esempio n. 5
0
def _getNetworkDetailsFromNode(node):
	"""
	This function is used to process a <network/> node from the XML tree and
	return the details it contains.
	
	@type node: Node|None
	@param node: The node retrieved from the XML tree. This may be None.
	
	@rtype: dict|None
	@return: The information stored in the <network/> node, represented as a
	    dictionary, or None if the node does not exist. The dictionary's
	    structure follows::
		 {
		  'id': <network_id:unicode>,
		  'name': <user-specified_network_name:unicode|None>,
		  'description': <user-specified_network_description:unicode|None>,
		  'autoconnect': <auto_connect:bool>,
		  'workerthreads': <worker_threads:int>,
		  'proxy': <proxy_identifier:unicode|None>,
		  'addresses': <(randomize_addresses:bool, addresses_data:list)>,
		  'profiles': <(use_all:bool, profile_data:tuple)>,
		  'channels': <channel_names:tuple>
		 }
	"""
	if node:
		#Get network data.
		id = parsers.xml_getAttributeValue(node, 'id')
		autoconnect = C_FUNCS.evaluateTruth(parsers.xml_getAttributeValue(node, 'autoconnect'))
		workerthreads = parsers.xml_getAttributeValue(node, 'workerthreads')
		if workerthreads:
			workerthreads = int(workerthreads)
		else:
			workerthreads = GLOBAL.USR_SERVER_THREADS	
		proxy = parsers.xml_getAttributeValue(node, 'proxy')
		
		name = parsers.xml_getSubNodeValue(node, "name")
		description = parsers.xml_getSubNodeValue(node, "description")
		
		#Get address data.
		address_node = node.xpath("addresses")[0]
		addresses_random = parsers.xml_getAttributeValue(address_node, 'randomorder')
		if not addresses_random or C_FUNCS.evaluateTruth(addresses_random):
			addresses_random = True
		else:
			addresses_random = False
			
		addresses = []
		for i in address_node.xpath("address"):
			addresses.append((
			 parsers.xml_getSubNodeValue(i, "url"),
			 int(parsers.xml_getSubNodeValue(i, "port")),
			 C_FUNCS.evaluateTruth(parsers.xml_getAttributeValue(i, 'secure')),
			 parsers.xml_getAttributeValue(i, 'proxy')
			))
			
		#Get profile data.
		profiles_use_all = True
		profiles = []
		profile_nodes = node.xpath("profiles")
		if profile_nodes:
			profile_node = profile_nodes[0]
			profiles_use_all = parsers.xml_getAttributeValue(profile_node, 'useall')
			if not profiles_use_all or C_FUNCS.evaluateTruth(profiles_use_all):
				profiles_use_all = True
			else:
				profiles_use_all = False
				
			for i in profile_node.xpath("profile"):
				profiles.append(parsers.xml_getNodeValue(i))
				
		#Get channel data.
		channels = []
		channel_nodes = node.xpath("channels")
		if channel_nodes:
			channel_node = channel_nodes[0]
			for i in channel_node.xpath("channel"):
				channels.append(parsers.xml_getNodeValue(i))
				
		return {
		 'id': id,
		 'name': name,
		 'description': description,
		 'autoconnect': autoconnect,
		 'workerthreads': workerthreads,
		 'proxy': proxy,
		 'addresses': (addresses_random, addresses),
		 'profiles': (profiles_use_all, tuple(profiles)),
		 'channels': tuple(channels)
		}
	return None