#!/usr/bin/env python




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
import fbcktemplate
from fbcktemplate import FbckTemplate

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.4.2.1'
__CHEETAH_versionTuple__ = (2, 4, 2, 'final', 1)
__CHEETAH_genTime__ = 1285018768.278949
__CHEETAH_genTimestamp__ = 'Mon Sep 20 14:39:28 2010'
__CHEETAH_src__ = 'fbcktemplate/fbckavconfig.tmpl'
__CHEETAH_srcLastModified__ = 'Mon Sep 20 14:39:21 2010'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class fbckavconfig(FbckTemplate):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        super(fbckavconfig, self).__init__(*args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def formula_element(self, name, pv, visible, **KWS):



        ## CHEETAH: generated from #def formula_element($name, $pv, $visible) at line 4, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        if len(VFFSL(SL,"name",True)) == 0: # generated from line 5, col 1
            name = VFFSL(SL,"pv",True)
        write(u'''    <formula directory_name="''')
        _v = VFFSL(SL,"ARCHIVE_DIRECTORY",True) # u'$ARCHIVE_DIRECTORY' on line 8, col 30
        if _v is not None: write(_filter(_v, rawExpr=u'$ARCHIVE_DIRECTORY')) # from line 8, col 30.
        write(u'''" name="''')
        _v = VFFSL(SL,"name",True) # u'$name' on line 8, col 56
        if _v is not None: write(_filter(_v, rawExpr=u'$name')) # from line 8, col 56.
        write(u'''">
        <term>x</term>
        <argument_ave name="''')
        _v = VFFSL(SL,"pv",True) # u'$pv' on line 10, col 29
        if _v is not None: write(_filter(_v, rawExpr=u'$pv')) # from line 10, col 29.
        write(u'''" variable="x"/>
        <method_name>linear</method_name>
        <nr_values>800</nr_values>
        <time_axis_name>Main Time Axis</time_axis_name>
        <range_axis_name>Main Range Axis</range_axis_name>
        <color>''')
        _v = VFN(VFFSL(SL,"fbcktemplate",True),"next_hex_color",False)() # u'$fbcktemplate.next_hex_color()' on line 15, col 16
        if _v is not None: write(_filter(_v, rawExpr=u'$fbcktemplate.next_hex_color()')) # from line 15, col 16.
        write(u'''</color>
        <draw_type>steps</draw_type>
        <draw_width>1.0</draw_width>
        <visibility>''')
        _v = VFFSL(SL,"visible",True) # u'$visible' on line 18, col 21
        if _v is not None: write(_filter(_v, rawExpr=u'$visible')) # from line 18, col 21.
        write(u'''</visibility>
    </formula>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        _v = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>"
        if _v is not None: write(_filter(_v))
        write(u'''<AVConfiguration>
    <connection_parameter>''')
        _v = VFFSL(SL,"ARCHIVER_URI",True) # u'$ARCHIVER_URI' on line 23, col 27
        if _v is not None: write(_filter(_v, rawExpr=u'$ARCHIVER_URI')) # from line 23, col 27.
        write(u'''</connection_parameter>
    <time_axis name="Main Time Axis">
        <start>-1d</start>
        <end>now</end>
        <location>bottom</location>
    </time_axis>
    <range_axis name="Main Range Axis">
        <min/>
        <max/>
        <type>normal</type>
        <location>left</location>
    </range_axis>
    <legend_configuration show_ave_name="true" show_directory_name="false" show_range="true" show_units="true"/>
    <plot_title/>
''')
        # ############## Actuators
        for i in VFFSL(SL,"used_indices",False)('A'): # generated from line 38, col 1
            name = VFFSL(SL,"indexed_var",False)('A{0}DEVNAME', VFFSL(SL,"i",True))
            pv = VFFSL(SL,"indexed_var",False)('A{0}_PV', VFFSL(SL,"i",True))
            _v = VFFSL(SL,"formula_element",False)(VFFSL(SL,"name",True), VFFSL(SL,"pv",True), 'true') # u"$formula_element($name, $pv, 'true')" on line 41, col 1
            if _v is not None: write(_filter(_v, rawExpr=u"$formula_element($name, $pv, 'true')")) # from line 41, col 1.
            write(u'''
''')
        # ############## States
        for i in VFFSL(SL,"used_indices",False)('S'): # generated from line 44, col 1
            name = VFFSL(SL,"indexed_var",False)('S{0}NAME', VFFSL(SL,"i",True))
            pv = VFFSL(SL,"indexed_var",False)('S{0}_PV', VFFSL(SL,"i",True))
            _v = VFFSL(SL,"formula_element",False)(VFFSL(SL,"name",True), VFFSL(SL,"pv",True), 'false') # u"$formula_element($name, $pv, 'false')" on line 47, col 1
            if _v is not None: write(_filter(_v, rawExpr=u"$formula_element($name, $pv, 'false')")) # from line 47, col 1.
            write(u'''
''')
            name = VFFSL(SL,"name",True) + " SP"
            pv = VFFSL(SL,"indexed_var",False)('S{0}DES_PV', VFFSL(SL,"i",True))
            _v = VFFSL(SL,"formula_element",False)(VFFSL(SL,"name",True), VFFSL(SL,"pv",True), 'false') # u"$formula_element($name, $pv, 'false')" on line 50, col 1
            if _v is not None: write(_filter(_v, rawExpr=u"$formula_element($name, $pv, 'false')")) # from line 50, col 1.
            write(u'''
''')
        # ############## Measurements
        for i in VFFSL(SL,"used_indices",False)('M'): # generated from line 53, col 1
            name = VFFSL(SL,"indexed_var",False)('M{0}DEVNAME', VFFSL(SL,"i",True))
            pv = VFFSL(SL,"indexed_var",False)('M{0}_PV', VFFSL(SL,"i",True))
            _v = VFFSL(SL,"formula_element",False)(VFFSL(SL,"name",True), VFFSL(SL,"pv",True), 'false') # u"$formula_element($name, $pv, 'false')" on line 56, col 1
            if _v is not None: write(_filter(_v, rawExpr=u"$formula_element($name, $pv, 'false')")) # from line 56, col 1.
            write(u'''
''')
        write(u'''</AVConfiguration>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_fbckavconfig= 'writeBody'

## END CLASS DEFINITION

if not hasattr(fbckavconfig, '_initCheetahAttributes'):
    templateAPIClass = getattr(fbckavconfig, '_CHEETAH_templateClass', Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(fbckavconfig)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=fbckavconfig()).run()


