annotate decoupage/templates.py @ 69:9fac58348520

whitespace cleanup
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 03 Aug 2012 23:48:25 -0700
parents 16d41af2d8ef
children 78139c3cecfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
2
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
3 import os
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
4 import sys
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
5 from optparse import OptionParser
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
6 from pkg_resources import iter_entry_points
8
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
7 from pkg_resources import resource_filename
3
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
8
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
9 def template_dirs():
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
10 template_dirs = set()
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
11 for formatter in iter_entry_points('decoupage.formatters'):
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
12 try:
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
13 formatter.load()
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
14 except:
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
15 continue
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
16 template_dir = resource_filename(formatter.module_name, 'templates')
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
17 if os.path.isdir(template_dir):
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
18 template_dirs.add(template_dir)
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
19 return template_dirs
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
20
8
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
21 def templates():
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
22 templates = []
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
23 for directory in template_dirs():
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
24 templates.extend([os.path.join(directory, filename)
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
25 for filename in os.listdir(directory)
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
26 if filename.endswith('.html')])
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
27 return templates
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
28
3
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
29 def main(args=sys.argv[1:]):
8
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
30 for template in templates():
16d41af2d8ef add ability to print templates
k0s <k0scist@gmail.com>
parents: 7
diff changeset
31 print template
3
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
32
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
33 if __name__ == '__main__':
ea5a5ef8ae2e add stub for template printing; does not work yet
k0s <k0scist@gmail.com>
parents:
diff changeset
34 main()