Merge lp:~tvansteenburgh/charm-tools/lp-1341688 into lp:charm-tools/1.3

Proposed by Tim Van Steenburgh
Status: Merged
Merged at revision: 337
Proposed branch: lp:~tvansteenburgh/charm-tools/lp-1341688
Merge into: lp:charm-tools/1.3
Diff against target: 95 lines (+18/-9)
4 files modified
charmtools/generators/template.py (+10/-0)
charmtools/templates/bash/template.py (+2/-2)
charmtools/templates/python/files/scripts/charm_helpers_sync.py (+1/-1)
charmtools/templates/python/template.py (+5/-6)
To merge this branch: bzr merge lp:~tvansteenburgh/charm-tools/lp-1341688
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+228743@code.launchpad.net

Description of the change

Ensure *.pyc files are skipped during template processing.

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/generators/template.py'
2--- charmtools/generators/template.py 2014-05-27 21:23:41 +0000
3+++ charmtools/generators/template.py 2014-07-29 18:18:49 +0000
4@@ -15,6 +15,7 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8+from fnmatch import fnmatch
9 import inspect
10 import os
11 import yaml
12@@ -25,6 +26,15 @@
13 class CharmTemplate(object):
14 """Base plugin for creating a new charm."""
15
16+ skip_parsing = ['README.ex', '*.pyc']
17+
18+ def skip_template(self, filename):
19+ """Return True if file should not be processed for template
20+ variable substitution.
21+
22+ """
23+ return any(fnmatch(filename, pat) for pat in self.skip_parsing)
24+
25 def prompts(self):
26 """Return a list :class:`Prompt` objects that will be used for
27 configuring the charm created by this plugin.
28
29=== modified file 'charmtools/templates/bash/template.py'
30--- charmtools/templates/bash/template.py 2014-06-20 18:57:25 +0000
31+++ charmtools/templates/bash/template.py 2014-07-29 18:18:49 +0000
32@@ -32,14 +32,14 @@
33
34
35 class BashCharmTemplate(CharmTemplate):
36- skip_parsing = ['README.ex']
37+ """Creates a bash-based charm"""
38
39 def create_charm(self, config, output_dir):
40 self._copy_files(output_dir)
41
42 for root, dirs, files in os.walk(output_dir):
43 for outfile in files:
44- if outfile in self.skip_parsing:
45+ if self.skip_template(outfile):
46 continue
47
48 self._template_file(config, path.join(root, outfile))
49
50=== modified file 'charmtools/templates/python/files/scripts/charm_helpers_sync.py'
51--- charmtools/templates/python/files/scripts/charm_helpers_sync.py 2014-05-23 20:10:24 +0000
52+++ charmtools/templates/python/files/scripts/charm_helpers_sync.py 2014-07-29 18:18:49 +0000
53@@ -1,4 +1,4 @@
54-#!/usr/bin/python
55+#!/usr/bin/env python
56 #
57 # Copyright 2013 Canonical Ltd.
58
59
60=== modified file 'charmtools/templates/python/template.py'
61--- charmtools/templates/python/template.py 2014-06-20 18:57:25 +0000
62+++ charmtools/templates/python/template.py 2014-07-29 18:18:49 +0000
63@@ -34,14 +34,14 @@
64
65
66 class PythonCharmTemplate(CharmTemplate):
67- skip_parsing = ['README.ex']
68+ """Creates a python-based charm"""
69
70 def create_charm(self, config, output_dir):
71 self._copy_files(output_dir)
72
73 for root, dirs, files in os.walk(output_dir):
74 for outfile in files:
75- if outfile in self.skip_parsing:
76+ if self.skip_template(outfile):
77 continue
78
79 self._template_file(config, path.join(root, outfile))
80@@ -81,12 +81,11 @@
81 os.path.join(output_dir, 'hooks_symlinked'),
82 os.path.join(output_dir, 'hooks')
83 )
84+ # Symlinks must be relative so that they are copied properly
85+ # when output_dir is moved to it's final location.
86 for link in ['config-changed', 'install', 'start', 'stop',
87 'upgrade-charm']:
88- os.symlink(
89- os.path.join(output_dir, 'hooks', 'hooks.py'),
90- os.path.join(output_dir, 'hooks', link)
91- )
92+ os.symlink('hooks.py', os.path.join(output_dir, 'hooks', link))
93
94 def _install_charmhelpers(self, output_dir):
95 helpers_dest = os.path.join(output_dir, 'lib', 'charmhelpers')

Subscribers

People subscribed via source and target branches