""" Utility functions """

__version__ = "$Revision: 1.16 $"
# $Source: /home/vladap/src/mysqlUserFolder/RCS/util.py,v $
#
# $Author: vladap $
# $Date: 2004/05/15 18:25:16 $

import Globals, zLOG, AccessControl
import cfg
import os

# --------------------------------------------------------------------- */
# Utility functions

def base_prod_dir ():
	h1 = Globals.INSTANCE_HOME
	h2 = Globals.SOFTWARE_HOME
	
	d1 = "%s/%s" % (h1, 'Products/mysqlUserFolder')
	d2 = "%s/%s" % (h2, 'Products/mysqlUserFolder')
	
	if os.path.isdir (d1): return d1
	else: return d2

def get_obj_from_request (REQUEST):
	p = REQUEST ['PARENTS'] [0]
	return p
	
def get_path_from_request (REQUEST):
	url = REQUEST ['URL']

	if REQUEST.has_key ('QUERY_STRING'):
		query_string = REQUEST['QUERY_STRING']
	else:
		query_string = ''
	
	ret = url
	if query_string != '':
		ret = ret + '?' + query_string
	
	return ret

def get_port_from_request (REQUEST):
	return REQUEST ['SERVER_PORT']

def get_address_from_request (REQUEST):
	try:
		return REQUEST.getClientAddr ()
	except:
		return REQUEST.get (cfg.REQUEST_RADDR_FIELD, '')

def validate_domain_spec (spec, request):
	return AccessControl.User.domainSpecMatch (spec, request)
	
# --------------------------------------------------------------------- */
# Log functions

def log_debug2 (str):
	if cfg.DEBUG > 1:
		zLOG.LOG ("mysqlUserFolder", zLOG.INFO, 
							"Internal info", '*** ' + str, None, 0)

def log_debug (str):
	if cfg.DEBUG > 0:
		zLOG.LOG ("mysqlUserFolder", zLOG.INFO, 
							"Internal info", str, None, 0)

def log_error (str):
	zLOG.LOG ("mysqlUserFolder", zLOG.ERROR, 
							"Internal error", str, None, 0)
							
							
							
							
