Kristian Spangsege | 1 Mar 15:56
Picon
Gravatar

C++

Hi

I'm trying to generate C++ output with Cheetah, and I'm having trouble with # (hash marks) because it is used both by C++ preprocessor and by Cheetah. I've come to believe that it is possible to reconfigure Cheetah such that it recognizes '%' instead of '#' for example. However, I cannot find any documentation or other specific information on how to do it.

Any help would be greatly appreciated.

Regards
Kristian

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Cheetahtemplate-discuss mailing list
Cheetahtemplate-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
Kerry Kurian | 17 Jan 22:20
Picon

issues installing Cheetah on OS X 10.7.2

Hi group,

two parts:

1. I installed Cheetah 2.4.4 via package download and python setup.py
install, and got this:

One or more C extensions failed to build. Performance enhancements
will not be available. Pure Python installation succeeded.

If anyone knows how to fix that, I'd love to know. (FWIW I have
XCode 4.2.1 installed.)

2. cheetah test gives me a boadload of errors and two fails.

The errors look like this:

===================================ERROR: test1
(Cheetah.Tests.NameMapper.VFFSL) string in dict lookup
---------------------------------- Traceback (most recentcall last): File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/Cheetah-2.4.4-py2.7.egg/Cheetah/Tests/NameMapper.py",
line 510, in setUp del ns['anInt'] # will be picked up by globals
KeyError: 'anInt'

The two fails are as follows:

====================================FAIL:
test_compilationCache (Cheetah.Tests.Template.ClassMethods_compile)
---------------------------------- Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/Cheetah-2.4.4-py2.7.egg/Cheetah/Tests/Template.py",
line 158, in test_compilationCache assert not
klass._CHEETAH_isInCompilationCache AssertionError

====================================FAIL:
test_keepRefToGeneratedCodeArg (Cheetah.Tests.Template.ClassMethods_compile)
---------------------------------- Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
site-packages/Cheetah-2.4.4-py2.7.egg/Cheetah/Tests/Template.py", line 133,
in test_keepRefToGeneratedCodeArg assert not t.generatedModuleCode()
AssertionError

----------------------------------------------------------------------

Any ideas? Safe to ignore those? If not, what's the fix?

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Jan Werner | 6 Dec 22:22
Picon
Favicon

Compiling _namemapper.c on win32 with MinGW

Hi group,


since I don't have (and like) VC+, I would like to build _namemapper.c, which is not available in binary form for Python 2.7, with MinGW. 

I created a simple compile script:

======
from distutils.core import setup, Extension

module1 = Extension('namemapper', sources = ['cheetah/c/_namemapper.c'])

setup (name = 'namemapper',
        version = '1.0',
        description = 'Namemapper C Version',
        ext_modules = [module1])
======

When trying to compile with 

python nm.py build -cmingw32

I get the following output:

======
$ python nm.py build -cmingw32
running build
running build_ext
building 'namemapper' extension
d:\MinGW\bin\gcc.exe -mdll -O -Wall -Id:\tools2\python\include -Id:\tools2\python\PC -c cheetah/c/_namemapper.c -o build\temp.win32-2.7\Release\cheetah\c\_namemapper.o
writing build\temp.win32-2.7\Release\cheetah\c\namemapper.def
d:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\cheetah\c\_namemapper.o build\temp.win32-2.7\Release\cheetah\c\namemapper.def -Ld:\tools2\python\libs -Ld:\tools2\python\PCbuild -lpython27 -lmsvcr90 -o build\lib.win32-2.7\namema
pper.pyd
Cannot export initnamemapper: symbol not defined
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


Could someone give me a hint as to what I'm doing wrong?

Thanks
Jan
------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
Cheetahtemplate-discuss mailing list
Cheetahtemplate-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
Ben Hoyt | 30 Nov 23:48
Picon
Gravatar

Placement of "self" in searchList during #include

Hi Cheetah folks,

For some reason when you #include a file, Cheetah adds the new
Template instance's "self" to the end of the searchList, instead of at
the beginning (or at least above the calling template's self). This
causes rather non-intuitive behaviour when you're #def-ining a
function in an included template that's already been #def-ined in a
calling template.

This code for this is:
https://github.com/tavisrudd/cheetah/blob/master/cheetah/Template.py#L1478

As an example of when this is an issue, consider these templates:

main.tmpl
-----
#def greet(name)
Hello, $name.
#end def
$greet('Ben')
#include 'included.tmpl'
-----

included.tmpl
-----
#def greet(name)
Bye bye, $name!
#end def
$greet('Ben')
-----

You'd expect this to print out "Hello, Ben.\n\nBye bye, Ben!" but
instead it prints out "Hello, Ben.\n\nHello, Ben.", because
main.tmpl's "self" is above included.tmpl's "self" in the searchList,
so the $greet() in included.tmpl is still calling main.tmpl's greet
function.

You can work around this by explicitly calling $self.greet() in the
included template, but it's rare to use "self." in Cheetah templates
and so is easy to forget, leading to potential bugs.

So my question is, why doesn't #include add the included template's
"self" to the searchList before the calling template's "self", to give
the more natural search order? I'm tempted to change this behaviour,
but there's probably a good reason for it, so I'm hesitant.

To change it, you can replace these two lines in Template.py:

            self._CHEETAH__searchList = list(_preBuiltSearchList)
            self._CHEETAH__searchList.append(self)

with:

            self._CHEETAH__searchList = []
            selfAdded = False
            for item in _preBuiltSearchList:
                if not selfAdded and isinstance(item, Template):
                    self._CHEETAH__searchList.append(self)
                    selfAdded = True
                self._CHEETAH__searchList.append(item)

This will place the #include template's "self" above the caller's, as
(at least we) expected.

Thanks,
Ben.

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
Buck Golemon | 22 Nov 19:27
Favicon

Re: macros don't follow #extends

I see two options here:

A) Change the #extends statement to honor #defmacro statements in the
extended template

    Necessary steps would be:

    1. Find the parent template. This is probably the hardest part,
since Cheetah generally relies on the python import mechanism to
create the connection to the parent templates. Templates (previously)
don't need to be compiled in order, so using the `imp` module is
probably out.

    2. Parse the parent template for #defmacro (and #extends)
statements. I have no clue how this would be done, but I think a
similar thing happens when parsing a #defmacro statement.

    3. Merge the found macro definitions from the parent parser into
the current parser. This is tricky and easy to get wrong, I imagine.

B) Extend the #include statement to be able to pull in template
snippets which contain the #defmacro statements. I don't like this
since this template-reuse is generally the job of #extends, and having
More Than One Way To Do It breaks the Zen of Python.

    Necessary steps:

    1. Make the parser look for statements like "#include template
../macros/foo.tmpl". Implementing this is simple. Open issue: what
directory should relative paths be based upon? My preference is to use
the real-absolute directory of the current script, but I'll probably
use whatever is pre-existing in the #include code.

    2. Make the parser run through the included file. I hope this
isn't hard. I need to take care to preserve line numbers.

I think #A is the Right Thing, but #B is *much* easier.

-buck

On Mon, Nov 21, 2011 at 7:17 PM, Buck Golemon <buck <at> yelp.com> wrote:
> If I define a macro in one template, and #extend that template elsewhere, the macro is not available in the
extended template, as expected.
> When looking at the cheetah code, I see why this is: since the macros are implemented purely in the parser,
and the #extended (parent, superclass) template is never parsed, the macro never exists in the context of
the #extended (child, subclass) template.
> What would it take to get this working?
> What would be the best approach?
> -buck

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
Buck Golemon | 22 Nov 04:20
Favicon

macros don't follow #extends

If I define a macro in one template, and #extend that template elsewhere, the macro is not available in the extended template, as expected.

When looking at the cheetah code, I see why this is: since the macros are implemented purely in the parser, and the #extended (parent, superclass) template is never parsed, the macro never exists in the context of the #extended (child, subclass) template.

What would it take to get this working?
What would be the best approach?

-buck


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Cheetahtemplate-discuss mailing list
Cheetahtemplate-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
Thibaud Roussillat | 9 Nov 13:59
Picon

Filter isn't played for None value

Hello,

I have to apply filter to placeholders which can have None value. However, the filter isn't apply.

For example :

import Cheetah.Template
from Cheetah.Filters import Filter

class MyFilter(Filter):

    def filter(self, val, **kw):
       
        return "tit"
       

if __name__ == '__main__':
   
    print "test01"
   
    searchList=[{'myvar1': u'test'}, {'myvar2': None}]
   
    t = Cheetah.Template.Template('''
        1. -${getVar('myvar1', '456')}-
        2. -${getVar('myvar2', ''), maxlen=2}-
        3. -${getVar('myvar3', None), maxlen=2}-
        ''', searchList,
        filter=MyFilter
        )
    print t

The output is as follow :

1. -tit-
2. --
3. --

Is there any way to apply filter to None value ?

Thanks a lot.

Thibaud

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Cheetahtemplate-discuss mailing list
Cheetahtemplate-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
Rémi ALVADO | 19 Sep 19:04
Picon

Using a variable inside another variable name

Hi,


I'm new with Cheetah and I'm trying to use it to build a deployment tool and replace my old configuration files with brand new cheetah templates. 
I'm working for a company which edit websites all over the world so lots of our configuration keys are overriden by country.
With Cheetah, I'm storing my configuration into a YAML data storage files and I use a Python script combined with some Bash scripts to find, fill and replace all *.cheetah files. 
Please find below an example of my test configuration file, my YAML data storage and the expected result file

--------------- CONF FILE -------------------
prod:
  sso:
    hosts:
#for myLanguage in $cultures
      sso_$myLanguage:
        host:   $eval("sso_host_" + myLanguage)
        port:   $eval("sso_port_" + myLanguage)
#end for

--------------- YAML DATA STORAGE -------------------
# Global 
cultures:
  - de
  - en
  - fr

# DE
sso_host_de:         sso-de.example.com
sso_port_de:         8081
[...]

# EN
sso_host_en:         sso-en.example.com
sso_port_en:         8082
[...]

# FR
sso_host_fr:         sso-fr.example.com
sso_port_fr:         8083
[...]

--------------- YAML DATA STORAGE -------------------
prod:
  sso:
    hosts:
      sso_de:
        host:   sso-de.example.com
        port:   8081
      sso_en:
        host:   sso-en.example.com
        port:   8082
      sso_fr:
        host:   sso-fr.example.com
        port:   8083

-------------------------------------

I know using "eval" is not a good idea (eval = evil :) ) but I've tried several other  solutions ("$sso_public_host_$myLanguage", "$(sso_public_host_$myLanguage)", ...) and none of them work.
I've also tried to change my data storage file to have something like :
de: 
   sso_host_public: ...
but I've got the exact same issue with $self[$myLanguage]['sso_host_public'] and I don't like this representation since it's less natural than a list of <key,value> tuples.

Do you have any idea how I can use a variable inside another variable name ? It seems to be a bit odd but it would be very convenient in a production environnement to have a very simple data storage file with only <key,value> tuples : easy to read and easy to share with a simple copy/paste into release note on a mail, a twiki, ...

Thanks and congratulations this templating engine : despite this little issue, it's really great and I might consider using it on another projects, more web oriented :)

Rémi
------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
Cheetahtemplate-discuss mailing list
Cheetahtemplate-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
Markos Kapes | 15 Sep 20:29
Picon

Templates, inheritance, etc….

I've got an abstract base template, and Im trying to do a few things,  but I'm not sure of the cheetah way to do
it. 

First,  the pages in question are results pages for a search, and as such have a table. There are two things I'm
trying to do.

1) I:mplement clickable rows by implementing a click handler on all rows. I've determined that you can't
put a block inside a loop, or else cheetah chokes. A def statement seems to cause the same problem, even
though I can display the text of the click handler (eg, in a header).

2) Is there anyway in the abstract class to have a conditional block
#if $do_this
Thing to do
#end if
and set $do_this in the ineherited class or in the server url call? It seems to choke for me unless I set
$do_this to a value in the abstract class. But then it's not reset in the inherited classs.

Sure part of it is that  I must be mucking up basic python inheritance.

Thanks,
--Marko
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
Dov Feldstern | 23 Aug 11:37
Picon

indentation

Hi!

Say I have the following template:

void foo(int a)
{
    int i = 0;
    $do_something
    for (i = 0; i < 10; i++) {
        $do_something
    }
}

This works just fine if $do_something consists of a single line;
however, if $do_something consists of multiple lines, then I have a
problem with the indentation, depending on what exactly the
placeholder itself looks like:

1) if the placeholder does not include any indentation itself, then
the first line is indented correctly (because the indentation appears
outside of the placeholder), but the rest are not;
2) so, I could have the placeholder already include the indentation,
but this has two problems:
  (a) the placeholder would have to appear unindented in the template,
which is not pretty; and
  (b) more importantly, the placeholder may appear in multiple places,
each requiring different indentation.

I'm aware of the "undocumented" #indent function (as documented in the
TODO), and by playing around with it (using cheetah 2.4.4) I see that
some of the options work, and am able to get the indentation correct.
However, I'm a little wary of using undocumented features which may be
in flux; and also, the resulting templates are much more verbose than
I would like (too many #indent commands).

Ideally --- what seems to me like the natural solution (without having
considered use-cases that are different than mine, and without having
looked at the implementation at all ;) ) --- I would like the
indentation of a placeholder to be added to each line of the
placeholder's contents. Is that possible / difficult to implement /
inappropriate for other use-cases? Does anyone have any other
suggestions for achieving what I want?

Thanks!
Dov

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
Alexander Egorov | 24 Jul 10:38
Picon

How to test Cheetah templates

Hi,
What I am trying to do is to write up the series of kickstart
snippets, based on cheetah, for e.g. for : fstab generation,
network-interfaces info generation and etc
How can I verify what my template is going to do without relaunching
the cobbler-based reinstallation of the server?

Cheers,
Alexander

------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/

Gmane