Source code for pyramid.scaffolds

import binascii
import os
from textwrap import dedent

from pyramid.compat import native_

from pyramid.scaffolds.template import Template # API

[docs]class PyramidTemplate(Template): """ A class that can be used as a base class for Pyramid scaffolding templates. """
[docs] def pre(self, command, output_dir, vars): """ Overrides :meth:`pyramid.scaffold.template.Template.pre`, adding several variables to the default variables list (including ``random_string``, and ``package_logger``). It also prevents common misnamings (such as naming a package "site" or naming a package logger "root". """ if vars['package'] == 'site': raise ValueError('Sorry, you may not name your package "site". ' 'The package name "site" has a special meaning in ' 'Python. Please name it anything except "site".') vars['random_string'] = native_(binascii.hexlify(os.urandom(20))) package_logger = vars['package'] if package_logger == 'root': # Rename the app logger in the rare case a project is named 'root' package_logger = 'app' vars['package_logger'] = package_logger return Template.pre(self, command, output_dir, vars)
[docs] def post(self, command, output_dir, vars): # pragma: no cover """ Overrides :meth:``, to print "Welcome to Pyramid. Sorry for the convenience." after a successful scaffolding rendering.""" separator = "=" * 79 msg = dedent( """ %(separator)s Tutorials: Documentation: Twitter (tips & updates): Mailing List: Welcome to Pyramid. Sorry for the convenience. %(separator)s """ % {'separator': separator}) self.out(msg) return, command, output_dir, vars)
def out(self, msg): # pragma: no cover (replaceable testing hook) print(msg)
class StarterProjectTemplate(PyramidTemplate): _template_dir = 'starter' summary = 'Pyramid starter project' class ZODBProjectTemplate(PyramidTemplate): _template_dir = 'zodb' summary = 'Pyramid ZODB project using traversal' class AlchemyProjectTemplate(PyramidTemplate): _template_dir = 'alchemy' summary = 'Pyramid SQLAlchemy project using url dispatch'