# -*- coding: utf-8 -*-
"""
UTc! module: src.path_utils

Purpose
=======
 Provides routines for resolving paths relevant to UTc!'s operation.
 
Legal
=====
 All code, unless otherwise indicated, is original, and subject to the
 terms of the GPLv3, which is provided in COPYING.
 
 (C) Neil Tallim, 2009
"""
import os
import sys

def getClientPath():
	"""
	Returns the absolute path to the directory in which the main script resides.
	
	@rtype: str
	@return: The absolute path to the directory in which the main script
	    resides.
	"""
	main_path =  sys.modules['__main__'].__file__
	client_path = getCurrentPath() + main_path[:-(len(main_path) - main_path.rfind(os.sep))]
	
	if not client_path.endswith(os.sep):
		return client_path + os.sep
	return client_path
	
def getCurrentPath():
	"""
	Returns the current working directory, terminated with an OS-specific
	directory delimiter.
	
	@rtype: str
	@return: The current working directory, terminated with an OS-specific
	    directory delimiter.
	"""
	main_path = os.path.abspath(".")
	if not main_path.endswith(os.sep):
		return main_path + os.sep
	return main_path
	
def getObjectsPath():
	"""
	Returns the absolute path of the objects assets directory.
	
	@rtype: str
	@return: The absolute path of the objects assets directory.
	"""
	return getClientPath() + "assets" + os.sep + "objects" + os.sep
	
def getTexturesPath():
	"""
	Returns the absolute path of the textures assets directory.
	
	@rtype: str
	@return: The absolute path of the textures assets directory.
	"""
	return getClientPath() + "assets" + os.sep + "textures" + os.sep
	
def getSoundsPath():
	"""
	Returns the absolute path of the sounds assets directory.
	
	@rtype: str
	@return: The absolute path of the sounds assets directory.
	"""
	return getClientPath() + "assets" + os.sep + "sounds" + os.sep
	
def getUserPath():
	"""
	Returns the location of ~/.UTc!/, creating it if it does not already exist.
	
	@rtype: str
	@return: The location of ~/.UTc!/.
	"""
	user_path = os.path.expanduser("~" + os.sep + ".UTc!" + os.sep)
	if not os.path.isdir(user_path):
		print "Creating '~/.UTc!/'..."
		os.mkdir(user_path)
	return user_path
	