commit | author | age
|
bb69a0
|
1 |
import binascii |
810942
|
2 |
import os |
4e2f1f
|
3 |
from textwrap import dedent |
810942
|
4 |
|
fe219c
|
5 |
from pyramid.compat import native_ |
5e21d5
|
6 |
|
24362a
|
7 |
from pyramid.scaffolds.template import Template # API |
810942
|
8 |
|
CM |
9 |
class PyramidTemplate(Template): |
bfd4b3
|
10 |
""" |
CM |
11 |
A class that can be used as a base class for Pyramid scaffolding |
|
12 |
templates. |
|
13 |
""" |
810942
|
14 |
def pre(self, command, output_dir, vars): |
aaedf5
|
15 |
""" Overrides :meth:`pyramid.scaffolds.template.Template.pre`, adding |
bfd4b3
|
16 |
several variables to the default variables list (including |
CM |
17 |
``random_string``, and ``package_logger``). It also prevents common |
|
18 |
misnamings (such as naming a package "site" or naming a package |
|
19 |
logger "root". |
|
20 |
""" |
bb69a0
|
21 |
vars['random_string'] = native_(binascii.hexlify(os.urandom(20))) |
810942
|
22 |
package_logger = vars['package'] |
CM |
23 |
if package_logger == 'root': |
|
24 |
# Rename the app logger in the rare case a project is named 'root' |
|
25 |
package_logger = 'app' |
|
26 |
vars['package_logger'] = package_logger |
|
27 |
return Template.pre(self, command, output_dir, vars) |
|
28 |
|
fe219c
|
29 |
def post(self, command, output_dir, vars): # pragma: no cover |
aaedf5
|
30 |
""" Overrides :meth:`pyramid.scaffolds.template.Template.post`, to |
bfd4b3
|
31 |
print "Welcome to Pyramid. Sorry for the convenience." after a |
CM |
32 |
successful scaffolding rendering.""" |
4e2f1f
|
33 |
|
GC |
34 |
separator = "=" * 79 |
|
35 |
msg = dedent( |
|
36 |
""" |
|
37 |
%(separator)s |
19d341
|
38 |
Tutorials: https://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/ |
SP |
39 |
Documentation: https://docs.pylonsproject.org/projects/pyramid/en/latest/ |
6c38f2
|
40 |
Twitter: https://twitter.com/PylonsProject |
a95408
|
41 |
Mailing List: https://groups.google.com/forum/#!forum/pylons-discuss |
4e2f1f
|
42 |
|
GC |
43 |
Welcome to Pyramid. Sorry for the convenience. |
|
44 |
%(separator)s |
647063
|
45 |
""" % {'separator': separator}) |
4e2f1f
|
46 |
|
GC |
47 |
self.out(msg) |
810942
|
48 |
return Template.post(self, command, output_dir, vars) |
CM |
49 |
|
|
50 |
def out(self, msg): # pragma: no cover (replaceable testing hook) |
fe219c
|
51 |
print(msg) |
810942
|
52 |
|
CM |
53 |
class StarterProjectTemplate(PyramidTemplate): |
|
54 |
_template_dir = 'starter' |
00a16d
|
55 |
summary = 'Pyramid starter project using URL dispatch and Jinja2' |
810942
|
56 |
|
CM |
57 |
class ZODBProjectTemplate(PyramidTemplate): |
|
58 |
_template_dir = 'zodb' |
a95408
|
59 |
summary = 'Pyramid project using ZODB, traversal, and Chameleon' |
810942
|
60 |
|
CM |
61 |
class AlchemyProjectTemplate(PyramidTemplate): |
|
62 |
_template_dir = 'alchemy' |
24362a
|
63 |
summary = ( |
MM |
64 |
'Pyramid project using SQLAlchemy, SQLite, URL dispatch, and ' |
|
65 |
'Jinja2') |