From dbbf69f4561c352fe825f6c7b0a81912aab987c9 Mon Sep 17 00:00:00 2001 From: Eric Price Date: Mon, 12 Nov 2007 03:53:45 -0500 Subject: [PATCH] Use the compiled Cheetah templates. This means that you really need to run make after any change to the template, though. svn path=/trunk/web/; revision=235 --- templates/Makefile | 9 ++- templates/main.py | 73 +++++++++++++++----- templates/mainpage.py | 176 ----------------------------------------------- templates/mainpage.tmpl | 25 ------- templates/skeleton.tmpl | 6 ++ templates/templates.py | 9 +++ templates/validation.py | 2 +- 7 files changed, 78 insertions(+), 222 deletions(-) delete mode 100644 templates/mainpage.py delete mode 100644 templates/mainpage.tmpl create mode 100644 templates/templates.py diff --git a/templates/Makefile b/templates/Makefile index 72f3626..aa083e2 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -1,10 +1,13 @@ -TEMPLATES=functions.tmpl skeleton.tmpl +TEMPLATES=$(wildcard *.tmpl) OUTPUTS=$(TEMPLATES:.tmpl=.py) all: ${OUTPUTS} -${OUTPUTS}:${TEMPLATES} - cheetah compile $^ +%.py: %.tmpl + cheetah compile $< + +#${OUTPUTS}:${TEMPLATES} +# cheetah compile $^ clean: @rm -f ${OUTPUTS} *.pyo *.pyc *.py.bak diff --git a/templates/main.py b/templates/main.py index 0bf16b9..e7412ba 100755 --- a/templates/main.py +++ b/templates/main.py @@ -35,12 +35,29 @@ if __name__ == '__main__': sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages') +import templates from Cheetah.Template import Template from sipb_xen_database import Machine, CDROM, ctx, connect import validation from webcommon import InvalidInput, CodeError, g import controls +class Checkpoint: + def __init__(self): + self.start_time = time.time() + self.checkpoints = [] + + def checkpoint(self, s): + self.checkpoints.append((s, time.time())) + + def __str__(self): + return ('Timing info:\n%s\n' % + '\n'.join(['%s: %s' % (d, t - self.start_time) for + (d, t) in self.checkpoints])) + +checkpoint = Checkpoint() + + def helppopup(subj): """Return HTML code for a (?) link to a specified help topic""" return ('%s' % checkpoint except Exception, err: if not fields.has_key('js'): if isinstance(err, CodeError): @@ -585,7 +623,6 @@ def main(operation, user, fields): raise if __name__ == '__main__': - start_time = time.time() fields = cgi.FieldStorage() u = getUser() g.user = u @@ -600,5 +637,7 @@ if __name__ == '__main__': if not operation: operation = 'list' - main(operation, u, fields) + #main(operation, u, fields) + import profile + profile.run('main(operation, u, fields)', 'log-'+operation) diff --git a/templates/mainpage.py b/templates/mainpage.py deleted file mode 100644 index 5a83921..0000000 --- a/templates/mainpage.py +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/env python - - - - -################################################## -## DEPENDENCIES -import sys -import os -import os.path -from os.path import getmtime, exists -import time -import types -import __builtin__ -from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion -from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple -from Cheetah.Template import Template -from Cheetah.DummyTransaction import DummyTransaction -from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList -from Cheetah.CacheRegion import CacheRegion -import Cheetah.Filters as Filters -import Cheetah.ErrorCatchers as ErrorCatchers - -################################################## -## MODULE CONSTANTS -try: - True, False -except NameError: - True, False = (1==1), (1==0) -VFFSL=valueFromFrameOrSearchList -VFSL=valueFromSearchList -VFN=valueForName -currentTime=time.time -__CHEETAH_version__ = '2.0rc8' -__CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8) -__CHEETAH_genTime__ = 1191715796.9141691 -__CHEETAH_genTimestamp__ = 'Sat Oct 6 20:09:56 2007' -__CHEETAH_src__ = 'mainpage.tmpl' -__CHEETAH_srcLastModified__ = 'Sat Oct 6 20:09:44 2007' -__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 mainpage(Template): - - ################################################## - ## CHEETAH GENERATED METHODS - - - def __init__(self, *args, **KWs): - - Template.__init__(self, *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 respond(self, trans=None): - - - - ## CHEETAH: main method generated for this template - 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 - - write(''' -Status for order #''') - _v = VFFSL(SL,"order.id",True) # '$order.id' on line 2, col 32 - if _v is not None: write(_filter(_v, rawExpr='$order.id')) # from line 2, col 32. - write(''' - -

[You are logged in as ''') - _v = VFN(VFFSL(SL,"user",True),"getFullName",False)() # '$user.getFullName()' on line 4, col 26 - if _v is not None: write(_filter(_v, rawExpr='$user.getFullName()')) # from line 4, col 26. - write('''.]

-

-''') - if (VFN(VFFSL(SL,"order",True),"hasShipped",False)()): # generated from line 6, col 1 - write(''' Your order has shipped. Your tracking number is ''') - _v = VFFSL(SL,"order.trackingNumber",True) # '$order.trackingNumber' on line 7, col 50 - if _v is not None: write(_filter(_v, rawExpr='$order.trackingNumber')) # from line 7, col 50. - write('''. -''') - else: # generated from line 8, col 1 - write(''' Your order has not yet shipped. -''') - write('''

-

Order #''') - _v = VFFSL(SL,"order.id",True) # '$order.id' on line 12, col 11 - if _v is not None: write(_filter(_v, rawExpr='$order.id')) # from line 12, col 11. - write(''' contains the following items:

-
    -''') - for purchased, quantity in VFN(VFFSL(SL,"order.purchased",True),"items",False)(): # generated from line 14, col 1 - write('''
  • ''') - _v = VFFSL(SL,"purchased.name",True) # '$purchased.name' on line 15, col 6 - if _v is not None: write(_filter(_v, rawExpr='$purchased.name')) # from line 15, col 6. - write(''': ''') - _v = VFFSL(SL,"quantity",True) # '$quantity' on line 15, col 23 - if _v is not None: write(_filter(_v, rawExpr='$quantity')) # from line 15, col 23. - write(''' unit''') - if (VFFSL(SL,"quantity",True) != 1): # generated from line 16, col 1 - write('''s -''') - write('''
  • -''') - write('''
-
-Served by Online Store v1.0 - - -''') - - ######################################## - ## 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_mainpage= 'respond' - -## END CLASS DEFINITION - -if not hasattr(mainpage, '_initCheetahAttributes'): - templateAPIClass = getattr(mainpage, '_CHEETAH_templateClass', Template) - templateAPIClass._addCheetahPlumbingCodeToClass(mainpage) - - -# 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=mainpage()).run() - - diff --git a/templates/mainpage.tmpl b/templates/mainpage.tmpl deleted file mode 100644 index 4e9846d..0000000 --- a/templates/mainpage.tmpl +++ /dev/null @@ -1,25 +0,0 @@ - -Status for order #$order.id - -

[You are logged in as $user.]

-

-#if ($order.hasShipped()) - Your order has shipped. Your tracking number is $order.trackingNumber. -#else - Your order has not yet shipped. -#end if -

-

Order #$order.id contains the following items:

-
    -#for $purchased, $quantity in $order.purchased: -
  • $purchased: $quantity unit#slurp -#if ($quantity != 1) -s -#end if -
  • -#end for -
-
-Served by Online Store v1.0 - - diff --git a/templates/skeleton.tmpl b/templates/skeleton.tmpl index 60cca90..94802c4 100644 --- a/templates/skeleton.tmpl +++ b/templates/skeleton.tmpl @@ -31,6 +31,12 @@ function helppopup(name){ +#if True +
+

We are in the process of modifying the service. Things likely will not work.

+
+#end if +
#if $varExists('error_text')

STDERR:

$error_text
diff --git a/templates/templates.py b/templates/templates.py new file mode 100644 index 0000000..8e94be7 --- /dev/null +++ b/templates/templates.py @@ -0,0 +1,9 @@ +__all__ = 'info command error help invalid list vnc'.split() +for _name in __all__: + try: + _module = __import__(_name, globals(), {}, [_name]) + globals()[_name] = getattr(_module, _name) + except ImportError, e: + import sys + print >> sys.stderr, 'Importing template "%s" raised error: %s' % (_name, e) + diff --git a/templates/validation.py b/templates/validation.py index ccb4fef..bb459bf 100644 --- a/templates/validation.py +++ b/templates/validation.py @@ -67,7 +67,7 @@ def validAddVm(user): return True def haveAccess(user, machine): - """Return whether a user has adminstrative access to a machine""" + """Return whether a user has administrative access to a machine""" if user == 'moo': return True if user in (machine.administrator, machine.owner): -- 1.7.9.5