Exemple #1
0
def _getIdleTime(server):
	"""
	This function calculates the total time spent idle on a server.
	
	@type server: pyrc_irc_abstract.irc_server.Server
	@param server: The pyrc_irc_abstract.irc_server.Server object for which idle time
	    is being calculated.
	
	@rtype: unicode
	@return: A string in the form '[[x hour(s), ][x minute(s), ]and ]x second(s)'
	"""
	idle_time = server.getIdleTime()
	hours = int(idle_time / 3600)
	idle_time = idle_time % 3600
	minutes = int(idle_time / 60)
	idle_time = idle_time % 60
	seconds = int(round(idle_time, 1))
	
	timestamp = ""
	if hours:
		timestamp = "%i %s, " % (hours, C_FUNCS.pluralizeQuantity(hours, 'hour'))
		
	if minutes:
		timestamp = "%s %i %s, " % (timestamp, minutes, C_FUNCS.pluralizeQuantity(minutes, 'minute'))
		
	if timestamp:
		timestamp = "%s and " % timestamp
		
	return u"%s %i %s" % (timestamp, seconds, C_FUNCS.pluralizeQuantity(seconds, 'second'))
	
Exemple #2
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()
Exemple #3
0
def _processCTCPString(data, user, server):
	"""
	This function replaces %-prefixed substrings by the following table::
	 %% -> %
	 %n -> current nick
	 %c -> user sending the CTCP request
	 %p -> local IP
	 %i -> time spent idle
	 %r -> realname
	 %u -> username
	 %d -> current day
	 %t -> current month
	 %y -> current year
	 %h -> current hour
	 %m -> current minute
	 %s -> current second
	
	@type data: basestring
	@param data: The CTCP response string to be processed.
	@type user: basestring
	@param user: The nickname of the user who requested this response.
	@type server: pyrc_irc_abstract.irc_server.Server
	@param server: The pyrc_irc_abstract.irc_server.Server object that received the
	    request for which this response is being prepared.
	
	@rtype: basestring
	@return: The processed CTCP response.
	"""
	current_time = time.localtime()
	data = data.replace("%%", "\x00")
	data = data.replace("%c", user)
	data = data.replace("%d", str(current_time[2]))
	data = data.replace("%t", str(current_time[1]))
	data = data.replace("%y", str(current_time[0]))
	data = data.replace("%h", str(current_time[3]))
	data = data.replace("%d", C_FUNCS.padInteger(current_time[4], 2))
	data = data.replace("%s", C_FUNCS.padInteger(current_time[5], 2))
	data = data.replace("%i", _getIdleTime(server))
	data = data.replace("%r", server.getRealName())
	data = data.replace("%u", server.getIdent())
	data = data.replace("%p", server.getLocalIP())
	data = data.replace("%n", server.getNickname())
	return data.replace("\x00", "%")
Exemple #4
0
def getCTCPs():
    """
	This function is used to get a list of static CTCPs for use by PyRC.
	
	@rtype: tuple
	@return: A tuple containing a list of all CTCPs defined for use by PyRC.
	    Its elements have the following form::
	     (<request:unicode>, <response:unicode>, <final:bool>)
	"""
    try:
        _xml_handler.lock()
        ctcps = []
        for i in _xml_handler.getNodes("/settings/ctcps/ctcp"):
            value = C_FUNCS.evaluateTruth(parsers.xml_getAttributeValue(i, "final"))
            request = parsers.xml_getSubNodeValue(i, "request")
            response = parsers.xml_getSubNodeValue(i, "response")

            ctcps.append((request, response, value))

        return tuple(ctcps)
    finally:
        _xml_handler.unlock()
Exemple #5
0
	#Initialisation is done, so dereference the setup resource.
	del pyrc_init
	print "Complete"


	#Load PyRC's settings
	########################################
	print "Loading settings...",
	try:
		settings.load()
		
		GLOBAL.USR_VARIABLES['userinfo'] = settings.getOption("irc.userinfo")
		GLOBAL.USR_VARIABLES['quitmessage'] = settings.getOption("irc.defaultquitmessage")
		GLOBAL.IRC_AUTO_RECONNECT = settings.getOption("irc.autoreconnect")
		
		GLOBAL.ENV_PSYCO = C_FUNCS.evaluateTruth(settings.getOption("pyrc.usepsyco"))
		GLOBAL.USR_SERVER_THREADS = int(settings.getOption("pyrc.serverworkerthreads"))
		ial_worker_threads = int(settings.getOption("pyrc.workerthreads"))
		
		#Validate IPv4.
		local_ip = re.search(r"(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", settings.getOption("dcc.localip"))
		if local_ip:
			if int(local_ip.group(1)) <= 255 and int(local_ip.group(2)) <= 255 and int(local_ip.group(3)) <= 255 and int(local_ip.group(4)) <= 255:
				GLOBAL.DCC_LOCAL_IP = '.'.join(local_ip.groups())
		del local_ip
		
		GLOBAL.USR_FORMATS['timestamp'] = settings.getFormat("timestamp")
		GLOBAL.USR_FORMATS['datestamp'] = settings.getFormat("datestamp")
		GLOBAL.USR_FORMATS['timedatestamp'] = settings.getFormat("timedatestamp")
		
		if not interface:
Exemple #6
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