#


import sys, os
import language
from configlets import needModule

try:
	from pysqlite2 import dbapi2 as sqlite
except ImportError:
	print _("Note: you should install python-pysqlite2 to have CDR functionality")

try:
	if not  os.access("/usr/lib/asterisk/modules/cdr_sqlite3_custom.so", os.F_OK):
		raise ImportError
	needModule("cdr_sqlite3_custom")
except:
	print _("Note: you need the cdr_sqlite3_custom module to have CDR and Stats functionalities")
	

try:
	db_fn = "/var/log/asterisk/master.db"
	if not os.access(db_fn, os.O_RDWR):
		raise ImportError
	db = sqlite.connect(db_fn, isolation_level="IMMEDIATE")
except:
	print _("Note: you don't seem to have access to %s yet created by cdr_sqlite3_custom. See INSTALL.txt for details.") % db_fn
	if __name__ == "__main__": sys.exit(0)
	db = None

def N_(message): return message

import sys, os
import language
from configlets import needModule
from config import *

try:
	import MySQLdb as mysql
except ImportError:
	print _("Note: you should install python mysql libs to have CDR Stats in MySQL")

try:
	if not  os.access("/usr/lib/asterisk/modules/cdr_addon_mysql.so", os.F_OK):
		raise ImportError
	needModule("cdr_addon_mysql")
except:
	print _("Note: you need the cdr_addon_mysql module to have CDR and Stats functionalities")
	
try:
	db = mysql.connect(host = DBHOST, db = DBNAME, user = DBUSER, passwd = DBPASSWD)
#	db3.isolation_level = None
except:
	print _("Note: you don't seem to have access to mysql.")
	if __name__ == "__main__": sys.exit(0)
	db = None

def N_(message): return message

def select(
		fields=['calldate as %s' % N_("Time_of_start"),