Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finish removing optik parser, added --shbang option as well (re #2)

Usage: cheetah compile mytemplate.tmpl --shbang="#!/usr/bin/python2.6"

NOTE: Depending on how your shell deals with the exclaimation point, you may need to escape it (as in zsh(1)) like this:
	cheetah compile mytemplate.tmpl --shbang="#\!/usr/bin/python2.6"

Signed-off-by: R. Tyler Ballance <tyler@slide.com>
  • Loading branch information...
commit 28f765227ef327dcaf92965055d65727edad3c49 1 parent 6f21865
R. Tyler Ballance authored
Showing with 6 additions and 15 deletions.
  1. +3 −13 src/CheetahWrapper.py
  2. +3 −2 src/Template.py
View
16 src/CheetahWrapper.py
@@ -53,18 +53,6 @@ def __repr__(self):
return "<Bundle %r>" % self.__dict__
-class MyOptionParser(OptionParser):
- standard_option_list = []
-
- def error(self, msg):
- """Print our usage+error page."""
- usage(HELP_PAGE2, msg)
-
- def print_usage(self, file=None):
- """Our usage+error page already has this."""
- pass
-
-
##################################################
## USAGE FUNCTION & MESSAGES
@@ -167,7 +155,7 @@ def parseOpts(self, args):
C, D, W = self.chatter, self.debug, self.warn
self.isCompile = isCompile = self.command[0] == 'c'
defaultOext = isCompile and ".py" or ".html"
- self.parser = MyOptionParser()
+ self.parser = OptionParser()
pao = self.parser.add_option
pao("--idir", action="store", dest="idir", default='', help='Input directory (defaults to current directory)')
pao("--odir", action="store", dest="odir", default="", help='Output directory (defaults to current directory)')
@@ -183,6 +171,7 @@ def parseOpts(self, args):
pao("--settings", action="store", dest="compilerSettingsString", default=None, help='String of compiler settings to pass through, e.g. --settings="useNameMapper=False,useFilters=False"')
pao("--templateAPIClass", action="store", dest="templateClassName", default=None, help='Name of a subclass of Cheetah.Template.Template to use for compilation, e.g. MyTemplateClass')
pao("--parallel", action="store", type="int", dest="parallel", default=1, help='Compile/fill templates in parallel, e.g. --parallel=4')
+ pao('--shbang', dest='shbang', default='#!/usr/bin/env python', help='Specify the shbang to place at the top of compiled templates, e.g. --shbang="#!/usr/bin/python2.6"')
self.opts, self.pathArgs = opts, files = self.parser.parse_args(args)
D("""\
@@ -579,6 +568,7 @@ def _compileOrFillBundle(self, b):
pysrc = TemplateClass.compile(file=src, returnAClass=False,
moduleName=basename,
className=basename,
+ commandlineopts=self.opts,
compilerSettings=compilerSettings)
output = pysrc
else:
View
5 src/Template.py
@@ -344,7 +344,7 @@ def compile(klass, source=None, file=None,
preprocessors=Unspecified,
cacheModuleFilesForTracebacks=Unspecified,
cacheDirForModuleFiles=Unspecified,
-
+ commandlineopts=None,
keepRefToGeneratedCode=Unspecified,
):
@@ -622,7 +622,6 @@ def __str__(self): return self.respond()
vt(compilerSettings, 'compilerSettings', [D], 'dictionary')
compilerClass = valOrDefault(compilerClass, klass._getCompilerClass(source, file))
-
preprocessors = valOrDefault(preprocessors, klass._CHEETAH_preprocessors)
keepRefToGeneratedCode = valOrDefault(
@@ -730,6 +729,8 @@ def __str__(self): return self.respond()
baseclassName=baseclassName,
mainMethodName=mainMethodName,
settings=(compilerSettings or {}))
+ if commandlineopts:
+ compiler.setShBang(commandlineopts.shbang)
compiler.compile()
generatedModuleCode = compiler.getModuleCode()
Please sign in to comment.
Something went wrong with that request. Please try again.