Mercurial > hg > decoupage
comparison decoupage/templates.py @ 83:78139c3cecfa
CLI
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 15 Dec 2013 12:38:24 -0800 |
parents | 16d41af2d8ef |
children | 4a9c5cf9fec9 |
comparison
equal
deleted
inserted
replaced
82:8596a1d97740 | 83:78139c3cecfa |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 functionality related to templates | |
5 """ | |
2 | 6 |
3 import os | 7 import os |
4 import sys | 8 import sys |
5 from optparse import OptionParser | 9 from optparse import OptionParser |
6 from pkg_resources import iter_entry_points | 10 from pkg_resources import iter_entry_points |
15 continue | 19 continue |
16 template_dir = resource_filename(formatter.module_name, 'templates') | 20 template_dir = resource_filename(formatter.module_name, 'templates') |
17 if os.path.isdir(template_dir): | 21 if os.path.isdir(template_dir): |
18 template_dirs.add(template_dir) | 22 template_dirs.add(template_dir) |
19 return template_dirs | 23 return template_dirs |
20 | 24 |
25 | |
21 def templates(): | 26 def templates(): |
22 templates = [] | 27 templates = [] |
23 for directory in template_dirs(): | 28 for directory in template_dirs(): |
24 templates.extend([os.path.join(directory, filename) | 29 templates.extend([os.path.join(directory, filename) |
25 for filename in os.listdir(directory) | 30 for filename in os.listdir(directory) |
26 if filename.endswith('.html')]) | 31 if filename.endswith('.html')]) |
27 return templates | 32 return templates |
28 | 33 |
34 | |
29 def main(args=sys.argv[1:]): | 35 def main(args=sys.argv[1:]): |
36 | |
37 # comman line option parser | |
38 description = 'list available templates' | |
39 parser = OptionParser(description=description) | |
40 options, args = parser.parse_args(args) | |
41 | |
42 # list templates | |
30 for template in templates(): | 43 for template in templates(): |
31 print template | 44 print template |
32 | 45 |
46 | |
33 if __name__ == '__main__': | 47 if __name__ == '__main__': |
34 main() | 48 main() |