Skip to content

Commit a98e27f

Browse files
committed
Merge pull request #2 from daenney/pylint
Make pylint happy
2 parents 5648b46 + 85a4811 commit a98e27f

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

puppetdb_stencil.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#!/usr/bin/env python
2+
"""
3+
puppetdb-stencil is a tool to render puppet resources using templates.
4+
"""
5+
26
from __future__ import print_function
37
from __future__ import unicode_literals
48

@@ -7,30 +11,38 @@
711
import pypuppetdb
812
import jinja2
913

10-
log = logging.getLogger('puppetdb_stencil')
14+
LOG = logging.getLogger('puppetdb_stencil')
1115

1216
METAPARAMS = ('require', 'before', 'subscribe', 'notify', 'audit', 'loglevel',
13-
'noop', 'schedule', 'stage', 'alias', 'tag')
17+
'noop', 'schedule', 'stage', 'alias', 'tag')
1418

1519
# Allow templates from anywhere on the filesystem
16-
loader = jinja2.FileSystemLoader(['.', '/'])
17-
environment = jinja2.Environment(trim_blocks=True, lstrip_blocks=True,
18-
loader=loader,
19-
extensions=['jinja2.ext.with_', 'jinja2.ext.loopcontrols'])
20+
LOADER = jinja2.FileSystemLoader(['.', '/'])
21+
EXTENSIONS = ['jinja2.ext.with_', 'jinja2.ext.loopcontrols']
22+
ENVIRONMENT = jinja2.Environment(trim_blocks=True, lstrip_blocks=True,
23+
loader=LOADER, extensions=EXTENSIONS)
2024

2125

22-
def render_resources(db, resource_type, template_names):
23-
resources = db.resources(resource_type)
26+
def render_resources(database, resource_type, template_names):
27+
"""
28+
Render resources of the given type. They are queried from the given
29+
database and rendered using the first template from template_names that can
30+
be loaded.
31+
"""
32+
resources = database.resources(resource_type)
2433
try:
25-
template = environment.select_template(template_names)
34+
template = ENVIRONMENT.select_template(template_names)
2635
except jinja2.TemplatesNotFound:
27-
log.error('No template found for {0}'.format(resource_type))
36+
LOG.error('No template found for {0}'.format(resource_type))
2837
else:
2938
return template.render(resource_type=resource_type,
30-
resources=resources, metaparams=METAPARAMS)
39+
resources=resources, metaparams=METAPARAMS)
3140

3241

33-
if __name__ == '__main__':
42+
def main():
43+
"""
44+
Main function
45+
"""
3446
parser = argparse.ArgumentParser(prog='puppetdb_stencil')
3547
parser.add_argument('resource_types', metavar='RESOURCE_TYPE', nargs='+')
3648
parser.add_argument('--templates', '-t', metavar='TEMPLATE', nargs='*')
@@ -41,10 +53,14 @@ def render_resources(db, resource_type, template_names):
4153
args = parser.parse_args()
4254
logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARN)
4355

44-
db = pypuppetdb.connect(host=args.host, port=args.port)
56+
database = pypuppetdb.connect(host=args.host, port=args.port)
4557

4658
for resource_type in args.resource_types:
4759
templates = ['{0}.jinja2'.format(resource_type)]
4860
if args.templates:
4961
templates += args.templates
50-
print(render_resources(db, resource_type, templates))
62+
print(render_resources(database, resource_type, templates))
63+
64+
65+
if __name__ == '__main__':
66+
main()

0 commit comments

Comments
 (0)