#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
# -*- coding: UTF-8 -*-

'''
$RCSfile: dbconnection.py,v $
$Revision: 929 $
$Author: markus $
$Date: 2008-05-11 00:50:49 +0200 (So, 11. Mai 2008) $
The BioCASE querytool
'''

import os, sys
# ***** include the biocase.lib directory in the python sys path for importing *****
execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, 'lib', 'biocase', 'adjustpath.py' ) ))

from biocase.configtool.general import *


############################################################################################################
#
#   MAIN
#
#===========================================================================================================

# check authentication!
if dsa is None:
    execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), 'main.cgi' ) ))
    sys.exit()

# check authentication!
authorize(form, dsa=dsa)

# load html template
tmpl = PageMacro('Content', PageMacro.DELMODE)
tmpl.load('Content', os.path.join(templateDir, '_dbsettings.html'))


#
# get psfObj
#
psfObj = dsaObj.getPSFObj(tmp=False)

#
# look for new form values
#
if form.has_key('action'):
    psfObj.adminpassword = form.getfirst('adminpassword', None)
    try:
        psfObj.recLimit  = int(form.getfirst('resultlimit', None))
    except:
        log.debug( "REC LIMIT IS NO INTEGER")
    psfObj.loglevel = form.getfirst('loglevel', logging.INFO)
    # write new PSFile
    psfObj.writePSFile()
    log.debug( "PSFile written")


#
# fill template 
#
# general stuff
tmpl['dsa'] = dsa
tmpl['wrapper_url'] = dsaObj.getBioCASeAccessPoint()

# settings
tmpl['adminpassword'] = psfObj.adminpassword
tmpl['resultlimit']   = str(psfObj.recLimit)
tmpl['loglevel']    = getDropDownOptionHtml({"DEBUG":logging.DEBUG, "INFO":logging.INFO, "WARN":logging.WARN, "ERROR":logging.ERROR}, psfObj.loglevel, keysSorted=['DEBUG','INFO','WARN','ERROR'])

#
# print HTML !
#
printOverHTTP( tmpl )
