Merge lp:~elopio/snapcraft/fix1477638-format_strings1 into lp:~snappy-dev/snapcraft/core
- fix1477638-format_strings1
- Merge into core
Proposed by
Leo Arias
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~elopio/snapcraft/fix1477638-format_strings1 | ||||
Merge into: | lp:~snappy-dev/snapcraft/core | ||||
Diff against target: |
919 lines (+244/-110) 16 files modified
integration-tests/units/jobs.pxu (+4/-4) snapcraft/__init__.py (+17/-7) snapcraft/cmds.py (+29/-24) snapcraft/common.py (+20/-10) snapcraft/dirs.py (+3/-3) snapcraft/main.py (+8/-0) snapcraft/plugin.py (+17/-11) snapcraft/plugins/ant_project.py (+7/-2) snapcraft/plugins/copy.py (+5/-1) snapcraft/plugins/ubuntu.py (+10/-4) snapcraft/tests/__init__.py (+3/-3) snapcraft/tests/test_cmds.py (+46/-8) snapcraft/tests/test_copy_plugin.py (+15/-8) snapcraft/tests/test_plugin.py (+17/-4) snapcraft/tests/test_yaml.py (+30/-14) snapcraft/yaml.py (+13/-7) |
||||
To merge this branch: | bzr merge lp:~elopio/snapcraft/fix1477638-format_strings1 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Snappy Developers | Pending | ||
Review via email:
|
Commit message
Cleanups to prepare for changing the format strings safely.
Description of the change
To post a comment you must log in.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'integration-tests/units/jobs.pxu' | |||
2 | --- integration-tests/units/jobs.pxu 2015-07-22 21:05:20 +0000 | |||
3 | +++ integration-tests/units/jobs.pxu 2015-07-23 17:20:28 +0000 | |||
4 | @@ -3,7 +3,7 @@ | |||
5 | 3 | estimated_duration: 0.1 | 3 | estimated_duration: 0.1 |
6 | 4 | command: | 4 | command: |
7 | 5 | set -x | 5 | set -x |
9 | 6 | OUTPUT=$(${SNAPCRAFT} pull) | 6 | OUTPUT=$(${SNAPCRAFT} pull 2>&1) |
10 | 7 | test $? = 1 || exit 1 | 7 | test $? = 1 || exit 1 |
11 | 8 | echo $OUTPUT | grep "Could not find snapcraft\.yaml\." | 8 | echo $OUTPUT | grep "Could not find snapcraft\.yaml\." |
12 | 9 | 9 | ||
13 | @@ -13,7 +13,7 @@ | |||
14 | 13 | command: | 13 | command: |
15 | 14 | set -x | 14 | set -x |
16 | 15 | cp -rT $PLAINBOX_PROVIDER_DATA/assemble . | 15 | cp -rT $PLAINBOX_PROVIDER_DATA/assemble . |
18 | 16 | OUTPUT=$(${SNAPCRAFT} assemble) | 16 | OUTPUT=$(${SNAPCRAFT} assemble 2>&1) |
19 | 17 | test $? = 1 || exit 1 | 17 | test $? = 1 || exit 1 |
20 | 18 | echo $OUTPUT | grep "Missing snappy metadata file" | 18 | echo $OUTPUT | grep "Missing snappy metadata file" |
21 | 19 | 19 | ||
22 | @@ -117,7 +117,7 @@ | |||
23 | 117 | command: | 117 | command: |
24 | 118 | set -x | 118 | set -x |
25 | 119 | cp -rT $PLAINBOX_PROVIDER_DATA/conflicts . | 119 | cp -rT $PLAINBOX_PROVIDER_DATA/conflicts . |
27 | 120 | OUTPUT=$(${SNAPCRAFT} stage) | 120 | OUTPUT=$(${SNAPCRAFT} stage 2>&1) |
28 | 121 | test $? = 1 || exit 1 | 121 | test $? = 1 || exit 1 |
29 | 122 | echo $OUTPUT | grep "Error: parts p1 and p2 have the following files in common: bin/test" # squished output by bash | 122 | echo $OUTPUT | grep "Error: parts p1 and p2 have the following files in common: bin/test" # squished output by bash |
30 | 123 | 123 | ||
31 | @@ -140,7 +140,7 @@ | |||
32 | 140 | set -x | 140 | set -x |
33 | 141 | cp -rT $PLAINBOX_PROVIDER_DATA/dependencies . | 141 | cp -rT $PLAINBOX_PROVIDER_DATA/dependencies . |
34 | 142 | sed -i "s/p1:/p1:\n after: [p3]/" snapcraft.yaml | 142 | sed -i "s/p1:/p1:\n after: [p3]/" snapcraft.yaml |
36 | 143 | OUTPUT=$(${SNAPCRAFT} pull) | 143 | OUTPUT=$(${SNAPCRAFT} pull 2>&1) |
37 | 144 | test $? = 1 || exit 1 | 144 | test $? = 1 || exit 1 |
38 | 145 | echo $OUTPUT | grep -i "circular dependency" | 145 | echo $OUTPUT | grep -i "circular dependency" |
39 | 146 | 146 | ||
40 | 147 | 147 | ||
41 | === modified file 'snapcraft/__init__.py' | |||
42 | --- snapcraft/__init__.py 2015-07-22 18:59:28 +0000 | |||
43 | +++ snapcraft/__init__.py 2015-07-23 17:20:28 +0000 | |||
44 | @@ -14,11 +14,16 @@ | |||
45 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
46 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
47 | 16 | 16 | ||
48 | 17 | import logging | ||
49 | 17 | import os | 18 | import os |
50 | 18 | import snapcraft.common | ||
51 | 19 | import subprocess | 19 | import subprocess |
52 | 20 | import urllib.parse | 20 | import urllib.parse |
53 | 21 | 21 | ||
54 | 22 | import snapcraft.common | ||
55 | 23 | |||
56 | 24 | |||
57 | 25 | logger = logging.getLogger(__name__) | ||
58 | 26 | |||
59 | 22 | 27 | ||
60 | 23 | class BasePlugin: | 28 | class BasePlugin: |
61 | 24 | 29 | ||
62 | @@ -53,7 +58,7 @@ | |||
63 | 53 | if cwd is None: | 58 | if cwd is None: |
64 | 54 | cwd = self.builddir | 59 | cwd = self.builddir |
65 | 55 | if True: | 60 | if True: |
67 | 56 | print(' '.join(cmd)) | 61 | logger.info(' '.join(cmd)) |
68 | 57 | return snapcraft.common.run(cmd, cwd=cwd, **kwargs) | 62 | return snapcraft.common.run(cmd, cwd=cwd, **kwargs) |
69 | 58 | 63 | ||
70 | 59 | def isurl(self, url): | 64 | def isurl(self, url): |
71 | @@ -71,7 +76,8 @@ | |||
72 | 71 | 76 | ||
73 | 72 | def pull_git(self, source, source_tag=None, source_branch=None): | 77 | def pull_git(self, source, source_tag=None, source_branch=None): |
74 | 73 | if source_tag and source_branch: | 78 | if source_tag and source_branch: |
76 | 74 | snapcraft.common.fatal("You can't specify both source-tag and source-branch for a git source (part '%s')." % self.name) | 79 | logger.error("You can't specify both source-tag and source-branch for a git source (part '%s')." % self.name) |
77 | 80 | snapcraft.common.fatal() | ||
78 | 75 | 81 | ||
79 | 76 | if os.path.exists(os.path.join(self.sourcedir, ".git")): | 82 | if os.path.exists(os.path.join(self.sourcedir, ".git")): |
80 | 77 | refspec = 'HEAD' | 83 | refspec = 'HEAD' |
81 | @@ -120,11 +126,13 @@ | |||
82 | 120 | elif source.startswith("git:"): | 126 | elif source.startswith("git:"): |
83 | 121 | source_type = 'git' | 127 | source_type = 'git' |
84 | 122 | elif self.isurl(source): | 128 | elif self.isurl(source): |
86 | 123 | snapcraft.common.fatal("Unrecognized source '%s' for part '%s'." % (source, self.name)) | 129 | logger.error("Unrecognized source '%s' for part '%s'." % (source, self.name)) |
87 | 130 | snapcraft.common.fatal() | ||
88 | 124 | 131 | ||
89 | 125 | if source_type == 'bzr': | 132 | if source_type == 'bzr': |
90 | 126 | if source_branch: | 133 | if source_branch: |
92 | 127 | snapcraft.common.fatal("You can't specify source-branch for a bzr source (part '%s')." % self.name) | 134 | logger.error("You can't specify source-branch for a bzr source (part '%s')." % self.name) |
93 | 135 | snapcraft.common.fatal() | ||
94 | 128 | if not self.pull_bzr(source, source_tag=source_tag): | 136 | if not self.pull_bzr(source, source_tag=source_tag): |
95 | 129 | return False | 137 | return False |
96 | 130 | if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]): | 138 | if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]): |
97 | @@ -136,9 +144,11 @@ | |||
98 | 136 | return False | 144 | return False |
99 | 137 | elif source_type == 'tar': | 145 | elif source_type == 'tar': |
100 | 138 | if source_branch: | 146 | if source_branch: |
102 | 139 | snapcraft.common.fatal("You can't specify source-branch for a tar source (part '%s')." % self.name) | 147 | logger.error("You can't specify source-branch for a tar source (part '%s')." % self.name) |
103 | 148 | snapcraft.common.fatal() | ||
104 | 140 | if source_tag: | 149 | if source_tag: |
106 | 141 | snapcraft.common.fatal("You can't specify source-tag for a tar source (part '%s')." % self.name) | 150 | logger.error("You can't specify source-tag for a tar source (part '%s')." % self.name) |
107 | 151 | snapcraft.common.fatal() | ||
108 | 142 | if not self.pull_tarball(source): | 152 | if not self.pull_tarball(source): |
109 | 143 | return False | 153 | return False |
110 | 144 | if not self.extract_tarball(source): | 154 | if not self.extract_tarball(source): |
111 | 145 | 155 | ||
112 | === modified file 'snapcraft/cmds.py' | |||
113 | --- snapcraft/cmds.py 2015-07-22 21:05:20 +0000 | |||
114 | +++ snapcraft/cmds.py 2015-07-23 17:20:28 +0000 | |||
115 | @@ -15,21 +15,27 @@ | |||
116 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
117 | 16 | 16 | ||
118 | 17 | import glob | 17 | import glob |
119 | 18 | import logging | ||
120 | 18 | import os | 19 | import os |
121 | 19 | import shlex | 20 | import shlex |
122 | 20 | import snapcraft.common | ||
123 | 21 | import snapcraft.plugin | ||
124 | 22 | import snapcraft.yaml | ||
125 | 23 | import subprocess | 21 | import subprocess |
126 | 24 | import sys | 22 | import sys |
127 | 25 | import tempfile | 23 | import tempfile |
128 | 26 | import time | 24 | import time |
129 | 25 | |||
130 | 27 | import yaml | 26 | import yaml |
131 | 28 | 27 | ||
132 | 28 | import snapcraft.plugin | ||
133 | 29 | import snapcraft.yaml | ||
134 | 30 | from snapcraft import common | ||
135 | 31 | |||
136 | 32 | |||
137 | 33 | logger = logging.getLogger(__name__) | ||
138 | 34 | |||
139 | 29 | 35 | ||
140 | 30 | def init(args): | 36 | def init(args): |
141 | 31 | if os.path.exists("snapcraft.yaml"): | 37 | if os.path.exists("snapcraft.yaml"): |
143 | 32 | snapcraft.common.log("snapcraft.yaml already exists!", file=sys.stderr) | 38 | logger.error('snapcraft.yaml already exists!') |
144 | 33 | sys.exit(1) | 39 | sys.exit(1) |
145 | 34 | yaml = 'parts:\n' | 40 | yaml = 'parts:\n' |
146 | 35 | for part_name in args.part: | 41 | for part_name in args.part: |
147 | @@ -41,23 +47,22 @@ | |||
148 | 41 | yaml = yaml.strip() | 47 | yaml = yaml.strip() |
149 | 42 | with open('snapcraft.yaml', mode='w+') as f: | 48 | with open('snapcraft.yaml', mode='w+') as f: |
150 | 43 | f.write(yaml) | 49 | f.write(yaml) |
154 | 44 | snapcraft.common.log("Wrote the following as snapcraft.yaml.") | 50 | logger.info('Wrote the following as snapcraft.yaml:\n{}'.format(yaml)) |
152 | 45 | print() | ||
153 | 46 | print(yaml) | ||
155 | 47 | sys.exit(0) | 51 | sys.exit(0) |
156 | 48 | 52 | ||
157 | 49 | 53 | ||
158 | 50 | def shell(args): | 54 | def shell(args): |
159 | 51 | config = snapcraft.yaml.Config() | 55 | config = snapcraft.yaml.Config() |
161 | 52 | snapcraft.common.env = config.stage_env() | 56 | common.env = config.stage_env() |
162 | 53 | userCommand = args.userCommand | 57 | userCommand = args.userCommand |
163 | 54 | if not userCommand: | 58 | if not userCommand: |
164 | 55 | userCommand = ['/usr/bin/env', 'PS1=\[\e[1;32m\]snapcraft:\w\$\[\e[0m\] ', '/bin/bash', '--norc'] | 59 | userCommand = ['/usr/bin/env', 'PS1=\[\e[1;32m\]snapcraft:\w\$\[\e[0m\] ', '/bin/bash', '--norc'] |
166 | 56 | snapcraft.common.run(userCommand) | 60 | common.run(userCommand) |
167 | 57 | 61 | ||
168 | 58 | 62 | ||
169 | 59 | def wrap_exe(relexepath): | 63 | def wrap_exe(relexepath): |
171 | 60 | exepath = os.path.join(snapcraft.common.snapdir, relexepath) | 64 | snapdir = common.get_snapdir() |
172 | 65 | exepath = os.path.join(snapdir, relexepath) | ||
173 | 61 | wrappath = exepath + '.wrapper' | 66 | wrappath = exepath + '.wrapper' |
174 | 62 | 67 | ||
175 | 63 | try: | 68 | try: |
176 | @@ -65,13 +70,13 @@ | |||
177 | 65 | except Exception: | 70 | except Exception: |
178 | 66 | pass | 71 | pass |
179 | 67 | 72 | ||
181 | 68 | script = "#!/bin/sh\n%s\nexec %s $*" % (snapcraft.common.assemble_env().replace(snapcraft.common.snapdir, "$SNAP_APP_PATH"), '"$SNAP_APP_PATH/%s"' % relexepath) | 73 | script = "#!/bin/sh\n%s\nexec %s $*" % (common.assemble_env().replace(snapdir, "$SNAP_APP_PATH"), '"$SNAP_APP_PATH/%s"' % relexepath) |
182 | 69 | with open(wrappath, 'w+') as f: | 74 | with open(wrappath, 'w+') as f: |
183 | 70 | f.write(script) | 75 | f.write(script) |
184 | 71 | 76 | ||
185 | 72 | os.chmod(wrappath, 0o755) | 77 | os.chmod(wrappath, 0o755) |
186 | 73 | 78 | ||
188 | 74 | return os.path.relpath(wrappath, snapcraft.common.snapdir) | 79 | return os.path.relpath(wrappath, snapdir) |
189 | 75 | 80 | ||
190 | 76 | 81 | ||
191 | 77 | def snap(args): | 82 | def snap(args): |
192 | @@ -81,17 +86,17 @@ | |||
193 | 81 | config = snapcraft.yaml.Config() | 86 | config = snapcraft.yaml.Config() |
194 | 82 | 87 | ||
195 | 83 | if 'snappy-metadata' in config.data: | 88 | if 'snappy-metadata' in config.data: |
198 | 84 | snapcraft.common.run( | 89 | common.run( |
199 | 85 | ['cp', '-arvT', config.data['snappy-metadata'], snapcraft.common.snapdir + '/meta']) | 90 | ['cp', '-arvT', config.data['snappy-metadata'], common.get_snapdir() + '/meta']) |
200 | 86 | if not os.path.exists('snap/meta/package.yaml'): | 91 | if not os.path.exists('snap/meta/package.yaml'): |
202 | 87 | snapcraft.common.log("Missing snappy metadata file 'meta/package.yaml'. Try specifying 'snappy-metadata' in snapcraft.yaml, pointing to a meta directory in your source tree.") | 92 | logger.error("Missing snappy metadata file 'meta/package.yaml'. Try specifying 'snappy-metadata' in snapcraft.yaml, pointing to a meta directory in your source tree.") |
203 | 88 | sys.exit(1) | 93 | sys.exit(1) |
204 | 89 | 94 | ||
205 | 90 | # wrap all included commands | 95 | # wrap all included commands |
206 | 91 | with open("snap/meta/package.yaml", 'r') as f: | 96 | with open("snap/meta/package.yaml", 'r') as f: |
207 | 92 | package = yaml.load(f) | 97 | package = yaml.load(f) |
208 | 93 | 98 | ||
210 | 94 | snapcraft.common.env = config.snap_env() | 99 | common.env = config.snap_env() |
211 | 95 | 100 | ||
212 | 96 | def replace_cmd(execparts, cmd): | 101 | def replace_cmd(execparts, cmd): |
213 | 97 | newparts = [cmd] + execparts[1:] | 102 | newparts = [cmd] + execparts[1:] |
214 | @@ -125,7 +130,7 @@ | |||
215 | 125 | def assemble(args): | 130 | def assemble(args): |
216 | 126 | args.cmd = 'snap' | 131 | args.cmd = 'snap' |
217 | 127 | snap(args) | 132 | snap(args) |
219 | 128 | snapcraft.common.run(['snappy', 'build', snapcraft.common.snapdir]) | 133 | common.run(['snappy', 'build', common.get_snapdir()]) |
220 | 129 | 134 | ||
221 | 130 | 135 | ||
222 | 131 | def run(args): | 136 | def run(args): |
223 | @@ -136,7 +141,7 @@ | |||
224 | 136 | os.makedirs(qemudir) | 141 | os.makedirs(qemudir) |
225 | 137 | except FileExistsError: | 142 | except FileExistsError: |
226 | 138 | pass | 143 | pass |
228 | 139 | snapcraft.common.run( | 144 | common.run( |
229 | 140 | ['sudo', 'ubuntu-device-flash', 'core', '--developer-mode', '--enable-ssh', '15.04', '-o', qemu_img], | 145 | ['sudo', 'ubuntu-device-flash', 'core', '--developer-mode', '--enable-ssh', '15.04', '-o', qemu_img], |
230 | 141 | cwd=qemudir) | 146 | cwd=qemudir) |
231 | 142 | qemu = subprocess.Popen( | 147 | qemu = subprocess.Popen( |
232 | @@ -186,7 +191,7 @@ | |||
233 | 186 | for otherPartName in partsFiles: | 191 | for otherPartName in partsFiles: |
234 | 187 | common = partFiles & partsFiles[otherPartName] | 192 | common = partFiles & partsFiles[otherPartName] |
235 | 188 | if common: | 193 | if common: |
237 | 189 | snapcraft.common.log("Error: parts %s and %s have the following files in common:\n %s" % (otherPartName, part.names()[0], '\n '.join(sorted(common)))) | 194 | logger.error('Error: parts %s and %s have the following files in common:\n %s' % (otherPartName, part.names()[0], '\n '.join(sorted(common)))) |
238 | 190 | return False | 195 | return False |
239 | 191 | 196 | ||
240 | 192 | # And add our files to the list | 197 | # And add our files to the list |
241 | @@ -201,9 +206,9 @@ | |||
242 | 201 | 206 | ||
243 | 202 | cmds = [args.cmd] | 207 | cmds = [args.cmd] |
244 | 203 | 208 | ||
246 | 204 | if cmds[0] in snapcraft.common.commandOrder: | 209 | if cmds[0] in common.COMMAND_ORDER: |
247 | 205 | forceCommand = cmds[0] | 210 | forceCommand = cmds[0] |
249 | 206 | cmds = snapcraft.common.commandOrder[0:snapcraft.common.commandOrder.index(cmds[0]) + 1] | 211 | cmds = common.COMMAND_ORDER[0:common.COMMAND_ORDER.index(cmds[0]) + 1] |
250 | 207 | 212 | ||
251 | 208 | config = snapcraft.yaml.Config() | 213 | config = snapcraft.yaml.Config() |
252 | 209 | 214 | ||
253 | @@ -214,7 +219,7 @@ | |||
254 | 214 | if subprocess.call(['dpkg-query', '-s', checkpkg], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: | 219 | if subprocess.call(['dpkg-query', '-s', checkpkg], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: |
255 | 215 | newPackages.append(checkpkg) | 220 | newPackages.append(checkpkg) |
256 | 216 | if newPackages: | 221 | if newPackages: |
258 | 217 | print("Installing required packages on the host system: " + ", ".join(newPackages)) | 222 | logger.info('Installing required packages on the host system: ' + ', '.join(newPackages)) |
259 | 218 | subprocess.call(['sudo', 'apt-get', '-y', 'install'] + newPackages, stdout=subprocess.DEVNULL) | 223 | subprocess.call(['sudo', 'apt-get', '-y', 'install'] + newPackages, stdout=subprocess.DEVNULL) |
260 | 219 | 224 | ||
261 | 220 | for part in config.all_parts: | 225 | for part in config.all_parts: |
262 | @@ -229,8 +234,8 @@ | |||
263 | 229 | if not check_for_collisions(config.all_parts): | 234 | if not check_for_collisions(config.all_parts): |
264 | 230 | sys.exit(1) | 235 | sys.exit(1) |
265 | 231 | 236 | ||
267 | 232 | snapcraft.common.env = config.build_env_for_part(part) | 237 | common.env = config.build_env_for_part(part) |
268 | 233 | force = forceAll or cmd == forceCommand | 238 | force = forceAll or cmd == forceCommand |
269 | 234 | if not getattr(part, cmd)(force=force): | 239 | if not getattr(part, cmd)(force=force): |
271 | 235 | snapcraft.common.log("Failed doing %s for %s!" % (cmd, part.names()[0])) | 240 | logger.error('Failed doing %s for %s!' % (cmd, part.names()[0])) |
272 | 236 | sys.exit(1) | 241 | sys.exit(1) |
273 | 237 | 242 | ||
274 | === modified file 'snapcraft/common.py' | |||
275 | --- snapcraft/common.py 2015-07-14 21:15:07 +0000 | |||
276 | +++ snapcraft/common.py 2015-07-23 17:20:28 +0000 | |||
277 | @@ -21,6 +21,11 @@ | |||
278 | 21 | import sys | 21 | import sys |
279 | 22 | import tempfile | 22 | import tempfile |
280 | 23 | 23 | ||
281 | 24 | |||
282 | 25 | COMMAND_ORDER = ["pull", "build", "stage", "snap"] | ||
283 | 26 | _DEFAULT_PLUGINDIR = '/usr/share/snapcraft/plugins' | ||
284 | 27 | _plugindir = _DEFAULT_PLUGINDIR | ||
285 | 28 | |||
286 | 24 | env = [] | 29 | env = [] |
287 | 25 | 30 | ||
288 | 26 | 31 | ||
289 | @@ -39,17 +44,22 @@ | |||
290 | 39 | return subprocess.call(['/bin/sh', f.name] + cmd, **kwargs) == 0 | 44 | return subprocess.call(['/bin/sh', f.name] + cmd, **kwargs) == 0 |
291 | 40 | 45 | ||
292 | 41 | 46 | ||
293 | 42 | def log(msg, file=None): | ||
294 | 43 | print('\033[01m' + msg + '\033[0m', file=None) | ||
295 | 44 | |||
296 | 45 | |||
297 | 46 | def fatal(msg): | 47 | def fatal(msg): |
298 | 47 | log(msg, file=sys.stderr) | ||
299 | 48 | sys.exit(1) | 48 | sys.exit(1) |
300 | 49 | 49 | ||
301 | 50 | 50 | ||
307 | 51 | commandOrder = ["pull", "build", "stage", "snap"] | 51 | def get_stagedir(): |
308 | 52 | stagedir = os.path.join(os.getcwd(), "stage") | 52 | return os.path.join(os.getcwd(), 'stage') |
309 | 53 | snapdir = os.path.join(os.getcwd(), "snap") | 53 | |
310 | 54 | 54 | ||
311 | 55 | plugindir = '/usr/share/snapcraft/plugins' | 55 | def get_snapdir(): |
312 | 56 | return os.path.join(os.getcwd(), 'snap') | ||
313 | 57 | |||
314 | 58 | |||
315 | 59 | def set_plugindir(plugindir): | ||
316 | 60 | global _plugindir | ||
317 | 61 | _plugindir = plugindir | ||
318 | 62 | |||
319 | 63 | |||
320 | 64 | def get_plugindir(): | ||
321 | 65 | return _plugindir | ||
322 | 56 | 66 | ||
323 | === modified file 'snapcraft/dirs.py' | |||
324 | --- snapcraft/dirs.py 2015-07-20 13:53:07 +0000 | |||
325 | +++ snapcraft/dirs.py 2015-07-23 17:20:28 +0000 | |||
326 | @@ -19,11 +19,11 @@ | |||
327 | 19 | 19 | ||
328 | 20 | def setup_dirs(): | 20 | def setup_dirs(): |
329 | 21 | """ | 21 | """ |
331 | 22 | Ensure that snapcraft.common.plugindir are setup correctly | 22 | Ensure that snapcraft.common plugindir is setup correctly |
332 | 23 | and support running out of a development snapshot | 23 | and support running out of a development snapshot |
333 | 24 | """ | 24 | """ |
335 | 25 | import snapcraft.common | 25 | from snapcraft import common |
336 | 26 | topdir = os.path.abspath(os.path.join(__file__, "..", "..")) | 26 | topdir = os.path.abspath(os.path.join(__file__, "..", "..")) |
337 | 27 | # only change the default if we are running from a checkout | 27 | # only change the default if we are running from a checkout |
338 | 28 | if os.path.exists(os.path.join(topdir, "setup.py")): | 28 | if os.path.exists(os.path.join(topdir, "setup.py")): |
340 | 29 | snapcraft.common.plugindir = os.path.join(topdir, 'plugins') | 29 | common.set_plugindir(os.path.join(topdir, 'plugins')) |
341 | 30 | 30 | ||
342 | === modified file 'snapcraft/main.py' | |||
343 | --- snapcraft/main.py 2015-07-17 17:19:04 +0000 | |||
344 | +++ snapcraft/main.py 2015-07-23 17:20:28 +0000 | |||
345 | @@ -16,12 +16,20 @@ | |||
346 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
347 | 17 | 17 | ||
348 | 18 | import argparse | 18 | import argparse |
349 | 19 | import logging | ||
350 | 19 | import sys | 20 | import sys |
351 | 20 | 21 | ||
352 | 21 | import snapcraft.cmds | 22 | import snapcraft.cmds |
353 | 22 | 23 | ||
354 | 23 | 24 | ||
355 | 25 | _COLOR_BOLD = '\033[1m' | ||
356 | 26 | _COLOR_END = '\033[0m' | ||
357 | 27 | |||
358 | 28 | |||
359 | 24 | def main(): | 29 | def main(): |
360 | 30 | logging.basicConfig( | ||
361 | 31 | format=_COLOR_BOLD + '%(message)s' + _COLOR_END, level=logging.INFO) | ||
362 | 32 | |||
363 | 25 | root_parser = argparse.ArgumentParser() | 33 | root_parser = argparse.ArgumentParser() |
364 | 26 | subparsers = root_parser.add_subparsers(dest='cmd') | 34 | subparsers = root_parser.add_subparsers(dest='cmd') |
365 | 27 | 35 | ||
366 | 28 | 36 | ||
367 | === modified file 'snapcraft/plugin.py' | |||
368 | --- snapcraft/plugin.py 2015-07-22 18:59:28 +0000 | |||
369 | +++ snapcraft/plugin.py 2015-07-23 17:20:28 +0000 | |||
370 | @@ -16,12 +16,18 @@ | |||
371 | 16 | 16 | ||
372 | 17 | import glob | 17 | import glob |
373 | 18 | import importlib | 18 | import importlib |
374 | 19 | import logging | ||
375 | 19 | import os | 20 | import os |
376 | 20 | import snapcraft | ||
377 | 21 | import snapcraft.common | ||
378 | 22 | import sys | 21 | import sys |
379 | 22 | |||
380 | 23 | import yaml | 23 | import yaml |
381 | 24 | 24 | ||
382 | 25 | import snapcraft | ||
383 | 26 | from snapcraft import common | ||
384 | 27 | |||
385 | 28 | |||
386 | 29 | logger = logging.getLogger(__name__) | ||
387 | 30 | |||
388 | 25 | 31 | ||
389 | 26 | def is_local_plugin(name): | 32 | def is_local_plugin(name): |
390 | 27 | return name.startswith("x-") | 33 | return name.startswith("x-") |
391 | @@ -31,7 +37,7 @@ | |||
392 | 31 | if is_local_plugin(name): | 37 | if is_local_plugin(name): |
393 | 32 | return os.path.abspath(os.path.join('parts', 'plugins')) | 38 | return os.path.abspath(os.path.join('parts', 'plugins')) |
394 | 33 | else: | 39 | else: |
396 | 34 | return snapcraft.common.plugindir | 40 | return common.get_plugindir() |
397 | 35 | 41 | ||
398 | 36 | 42 | ||
399 | 37 | class PluginError(Exception): | 43 | class PluginError(Exception): |
400 | @@ -69,7 +75,7 @@ | |||
401 | 69 | def _load_config(self, name): | 75 | def _load_config(self, name): |
402 | 70 | configPath = os.path.join(plugindir(name), name + ".yaml") | 76 | configPath = os.path.join(plugindir(name), name + ".yaml") |
403 | 71 | if not os.path.exists(configPath): | 77 | if not os.path.exists(configPath): |
405 | 72 | snapcraft.common.log("Unknown plugin %s" % name, file=sys.stderr) | 78 | logger.error("Unknown plugin %s" % name) |
406 | 73 | raise PluginError() | 79 | raise PluginError() |
407 | 74 | with open(configPath, 'r') as fp: | 80 | with open(configPath, 'r') as fp: |
408 | 75 | self.config = yaml.load(fp) or {} | 81 | self.config = yaml.load(fp) or {} |
409 | @@ -86,7 +92,7 @@ | |||
410 | 86 | setattr(options, attrname, properties[opt]) | 92 | setattr(options, attrname, properties[opt]) |
411 | 87 | else: | 93 | else: |
412 | 88 | if opt_parameters.get('required', False): | 94 | if opt_parameters.get('required', False): |
414 | 89 | snapcraft.common.log("Required field %s missing on part %s" % (opt, name), file=sys.stderr) | 95 | logger.error("Required field %s missing on part %s" % (opt, name)) |
415 | 90 | raise PluginError() | 96 | raise PluginError() |
416 | 91 | setattr(options, attrname, None) | 97 | setattr(options, attrname, None) |
417 | 92 | 98 | ||
418 | @@ -147,13 +153,13 @@ | |||
419 | 147 | return self.part_names | 153 | return self.part_names |
420 | 148 | 154 | ||
421 | 149 | def notify_stage(self, stage, hint=''): | 155 | def notify_stage(self, stage, hint=''): |
423 | 150 | snapcraft.common.log(stage + " " + self.part_names[0] + hint) | 156 | logger.info(stage + " " + self.part_names[0] + hint) |
424 | 151 | 157 | ||
425 | 152 | def is_dirty(self, stage): | 158 | def is_dirty(self, stage): |
426 | 153 | try: | 159 | try: |
427 | 154 | with open(self.statefile, 'r') as f: | 160 | with open(self.statefile, 'r') as f: |
428 | 155 | lastStep = f.read() | 161 | lastStep = f.read() |
430 | 156 | return snapcraft.common.commandOrder.index(stage) > snapcraft.common.commandOrder.index(lastStep) | 162 | return common.COMMAND_ORDER.index(stage) > common.COMMAND_ORDER.index(lastStep) |
431 | 157 | except Exception: | 163 | except Exception: |
432 | 158 | return True | 164 | return True |
433 | 159 | 165 | ||
434 | @@ -197,7 +203,7 @@ | |||
435 | 197 | return True | 203 | return True |
436 | 198 | 204 | ||
437 | 199 | self.notify_stage("Staging") | 205 | self.notify_stage("Staging") |
439 | 200 | snapcraft.common.run(['cp', '-arT', self.installdir, self.stagedir]) | 206 | common.run(['cp', '-arT', self.installdir, self.stagedir]) |
440 | 201 | self.mark_done('stage') | 207 | self.mark_done('stage') |
441 | 202 | return True | 208 | return True |
442 | 203 | 209 | ||
443 | @@ -213,9 +219,9 @@ | |||
444 | 213 | snapDirs, snap_files = self.collect_snap_files(includes, excludes) | 219 | snapDirs, snap_files = self.collect_snap_files(includes, excludes) |
445 | 214 | 220 | ||
446 | 215 | if snapDirs: | 221 | if snapDirs: |
448 | 216 | snapcraft.common.run(['mkdir', '-p'] + list(snapDirs), cwd=self.stagedir) | 222 | common.run(['mkdir', '-p'] + list(snapDirs), cwd=self.stagedir) |
449 | 217 | if snap_files: | 223 | if snap_files: |
451 | 218 | snapcraft.common.run(['cp', '-a', '--parent'] + list(snap_files) + [self.snapdir], cwd=self.stagedir) | 224 | common.run(['cp', '-a', '--parent'] + list(snap_files) + [self.snapdir], cwd=self.stagedir) |
452 | 219 | 225 | ||
453 | 220 | self.mark_done('snap') | 226 | self.mark_done('snap') |
454 | 221 | return True | 227 | return True |
455 | @@ -274,6 +280,6 @@ | |||
456 | 274 | def load_plugin(part_name, plugin_name, properties={}, load_code=True): | 280 | def load_plugin(part_name, plugin_name, properties={}, load_code=True): |
457 | 275 | part = PluginHandler(plugin_name, part_name, properties, load_code=load_code) | 281 | part = PluginHandler(plugin_name, part_name, properties, load_code=load_code) |
458 | 276 | if not part.is_valid(): | 282 | if not part.is_valid(): |
460 | 277 | snapcraft.common.log("Could not load part %s" % plugin_name, file=sys.stderr) | 283 | logger.error("Could not load part %s" % plugin_name) |
461 | 278 | sys.exit(1) | 284 | sys.exit(1) |
462 | 279 | return part | 285 | return part |
463 | 280 | 286 | ||
464 | === modified file 'snapcraft/plugins/ant_project.py' | |||
465 | --- snapcraft/plugins/ant_project.py 2015-07-22 18:23:16 +0000 | |||
466 | +++ snapcraft/plugins/ant_project.py 2015-07-23 17:20:28 +0000 | |||
467 | @@ -15,10 +15,15 @@ | |||
468 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
469 | 16 | 16 | ||
470 | 17 | import glob | 17 | import glob |
471 | 18 | import logging | ||
472 | 18 | import os | 19 | import os |
473 | 20 | import sys | ||
474 | 21 | |||
475 | 19 | import snapcraft | 22 | import snapcraft |
476 | 20 | import snapcraft.common | 23 | import snapcraft.common |
478 | 21 | import sys | 24 | |
479 | 25 | |||
480 | 26 | logger = logging.getLogger(__name__) | ||
481 | 22 | 27 | ||
482 | 23 | 28 | ||
483 | 24 | class AntProjectPlugin(snapcraft.BasePlugin): | 29 | class AntProjectPlugin(snapcraft.BasePlugin): |
484 | @@ -31,7 +36,7 @@ | |||
485 | 31 | return False | 36 | return False |
486 | 32 | files = glob.glob(os.path.join(self.builddir, 'target', '*.jar')) | 37 | files = glob.glob(os.path.join(self.builddir, 'target', '*.jar')) |
487 | 33 | if not files: | 38 | if not files: |
489 | 34 | snapcraft.common.log('Could not find any built jar files for part %s' % self.name) | 39 | logger.error('Could not find any built jar files for part %s' % self.name) |
490 | 35 | sys.exit(1) | 40 | sys.exit(1) |
491 | 36 | jardir = os.path.join(self.installdir, 'jar') | 41 | jardir = os.path.join(self.installdir, 'jar') |
492 | 37 | return self.run(['mkdir', '-p', jardir]) and \ | 42 | return self.run(['mkdir', '-p', jardir]) and \ |
493 | 38 | 43 | ||
494 | === modified file 'snapcraft/plugins/copy.py' | |||
495 | --- snapcraft/plugins/copy.py 2015-07-22 14:55:48 +0000 | |||
496 | +++ snapcraft/plugins/copy.py 2015-07-23 17:20:28 +0000 | |||
497 | @@ -14,11 +14,15 @@ | |||
498 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
499 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
500 | 16 | 16 | ||
501 | 17 | import logging | ||
502 | 17 | import os | 18 | import os |
503 | 18 | 19 | ||
504 | 19 | import snapcraft | 20 | import snapcraft |
505 | 20 | 21 | ||
506 | 21 | 22 | ||
507 | 23 | logger = logging.getLogger(__name__) | ||
508 | 24 | |||
509 | 25 | |||
510 | 22 | class CopyPlugin(snapcraft.BasePlugin): | 26 | class CopyPlugin(snapcraft.BasePlugin): |
511 | 23 | 27 | ||
512 | 24 | def build(self): | 28 | def build(self): |
513 | @@ -26,7 +30,7 @@ | |||
514 | 26 | for src in sorted(self.options.files): | 30 | for src in sorted(self.options.files): |
515 | 27 | dst = self.options.files[src] | 31 | dst = self.options.files[src] |
516 | 28 | if not os.path.lexists(src): | 32 | if not os.path.lexists(src): |
518 | 29 | snapcraft.common.log("WARNING: file '%s' missing" % src) | 33 | logger.warning("WARNING: file '%s' missing" % src) |
519 | 30 | res = False | 34 | res = False |
520 | 31 | continue | 35 | continue |
521 | 32 | dst = os.path.join(self.installdir, dst) | 36 | dst = os.path.join(self.installdir, dst) |
522 | 33 | 37 | ||
523 | === modified file 'snapcraft/plugins/ubuntu.py' | |||
524 | --- snapcraft/plugins/ubuntu.py 2015-07-22 18:23:16 +0000 | |||
525 | +++ snapcraft/plugins/ubuntu.py 2015-07-23 17:20:28 +0000 | |||
526 | @@ -14,12 +14,18 @@ | |||
527 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
528 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
529 | 16 | 16 | ||
531 | 17 | import apt | 17 | import logging |
532 | 18 | import os | 18 | import os |
533 | 19 | import snapcraft.common | ||
534 | 20 | import subprocess | 19 | import subprocess |
535 | 21 | import sys | 20 | import sys |
536 | 22 | 21 | ||
537 | 22 | import apt | ||
538 | 23 | |||
539 | 24 | import snapcraft.common | ||
540 | 25 | |||
541 | 26 | |||
542 | 27 | logger = logging.getLogger(__name__) | ||
543 | 28 | |||
544 | 23 | 29 | ||
545 | 24 | class UbuntuPlugin(snapcraft.BasePlugin): | 30 | class UbuntuPlugin(snapcraft.BasePlugin): |
546 | 25 | 31 | ||
547 | @@ -32,7 +38,7 @@ | |||
548 | 32 | else: | 38 | else: |
549 | 33 | # User didn't specify a package, use the part name | 39 | # User didn't specify a package, use the part name |
550 | 34 | if name == 'ubuntu': | 40 | if name == 'ubuntu': |
552 | 35 | snapcraft.common.log("Part %s needs either a package option or a name" % name) | 41 | logger.error('Part %s needs either a package option or a name' % name) |
553 | 36 | sys.exit(1) | 42 | sys.exit(1) |
554 | 37 | self.included_packages.append(name) | 43 | self.included_packages.append(name) |
555 | 38 | 44 | ||
556 | @@ -83,7 +89,7 @@ | |||
557 | 83 | for p in packages: | 89 | for p in packages: |
558 | 84 | if p not in alldeps: | 90 | if p not in alldeps: |
559 | 85 | exit = True | 91 | exit = True |
561 | 86 | snapcraft.common.log("Package %s not recognized" % p, file=sys.stderr) | 92 | logger.error('Package %s not recognized' % p, file=sys.stderr) |
562 | 87 | if exit: | 93 | if exit: |
563 | 88 | sys.exit(1) | 94 | sys.exit(1) |
564 | 89 | 95 | ||
565 | 90 | 96 | ||
566 | === modified file 'snapcraft/tests/__init__.py' | |||
567 | --- snapcraft/tests/__init__.py 2015-07-22 15:03:34 +0000 | |||
568 | +++ snapcraft/tests/__init__.py 2015-07-23 17:20:28 +0000 | |||
569 | @@ -16,7 +16,6 @@ | |||
570 | 16 | 16 | ||
571 | 17 | import fixtures | 17 | import fixtures |
572 | 18 | 18 | ||
573 | 19 | import snapcraft.dirs | ||
574 | 20 | from snapcraft.tests import fixture_setup | 19 | from snapcraft.tests import fixture_setup |
575 | 21 | 20 | ||
576 | 22 | 21 | ||
577 | @@ -24,5 +23,6 @@ | |||
578 | 24 | 23 | ||
579 | 25 | def setUp(self): | 24 | def setUp(self): |
580 | 26 | super().setUp() | 25 | super().setUp() |
583 | 27 | snapcraft.dirs.setup_dirs() | 26 | temp_cwd_fixture = fixture_setup.TempCWD() |
584 | 28 | self.useFixture(fixture_setup.TempCWD()) | 27 | self.useFixture(temp_cwd_fixture) |
585 | 28 | self.path = temp_cwd_fixture.path | ||
586 | 29 | 29 | ||
587 | === modified file 'snapcraft/tests/test_cmds.py' | |||
588 | --- snapcraft/tests/test_cmds.py 2015-07-15 09:00:46 +0000 | |||
589 | +++ snapcraft/tests/test_cmds.py 2015-07-23 17:20:28 +0000 | |||
590 | @@ -14,18 +14,23 @@ | |||
591 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
592 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
593 | 16 | 16 | ||
594 | 17 | import logging | ||
595 | 17 | import os | 18 | import os |
596 | 18 | import tempfile | 19 | import tempfile |
597 | 19 | from unittest import mock | 20 | from unittest import mock |
598 | 20 | 21 | ||
600 | 21 | from snapcraft.cmds import check_for_collisions | 22 | import fixtures |
601 | 23 | |||
602 | 24 | from snapcraft import cmds | ||
603 | 22 | from snapcraft.tests import TestCase | 25 | from snapcraft.tests import TestCase |
604 | 23 | 26 | ||
605 | 24 | 27 | ||
606 | 25 | class TestCommands(TestCase): | 28 | class TestCommands(TestCase): |
607 | 26 | 29 | ||
610 | 27 | @mock.patch('snapcraft.common.log') | 30 | def test_check_for_collisions(self): |
611 | 28 | def test_check_for_collisions(self, logmock): | 31 | fake_logger = fixtures.FakeLogger(level=logging.ERROR) |
612 | 32 | self.useFixture(fake_logger) | ||
613 | 33 | |||
614 | 29 | tmpdirObject = tempfile.TemporaryDirectory() | 34 | tmpdirObject = tempfile.TemporaryDirectory() |
615 | 30 | self.addCleanup(tmpdirObject.cleanup) | 35 | self.addCleanup(tmpdirObject.cleanup) |
616 | 31 | tmpdir = tmpdirObject.name | 36 | tmpdir = tmpdirObject.name |
617 | @@ -52,8 +57,41 @@ | |||
618 | 52 | open(part3.installdir + '/1', mode='w').close() | 57 | open(part3.installdir + '/1', mode='w').close() |
619 | 53 | open(part3.installdir + '/a/2', mode='w').close() | 58 | open(part3.installdir + '/a/2', mode='w').close() |
620 | 54 | 59 | ||
626 | 55 | self.assertTrue(check_for_collisions([part1, part2])) | 60 | self.assertTrue(cmds.check_for_collisions([part1, part2])) |
627 | 56 | self.assertFalse(logmock.called) | 61 | self.assertEqual('', fake_logger.output) |
628 | 57 | 62 | ||
629 | 58 | self.assertFalse(check_for_collisions([part1, part2, part3])) | 63 | self.assertFalse(cmds.check_for_collisions([part1, part2, part3])) |
630 | 59 | logmock.assert_called_with("Error: parts part2 and part3 have the following files in common:\n 1\n a/2") | 64 | self.assertEqual( |
631 | 65 | 'Error: parts part2 and part3 have the following files in common:\n' | ||
632 | 66 | ' 1\n' | ||
633 | 67 | ' a/2\n', | ||
634 | 68 | fake_logger.output) | ||
635 | 69 | |||
636 | 70 | |||
637 | 71 | class InitTestCase(TestCase): | ||
638 | 72 | |||
639 | 73 | def test_init_with_existing_snapcraft_yaml_must_fail(self): | ||
640 | 74 | fake_logger = fixtures.FakeLogger(level=logging.ERROR) | ||
641 | 75 | self.useFixture(fake_logger) | ||
642 | 76 | |||
643 | 77 | open('snapcraft.yaml', 'w').close() | ||
644 | 78 | |||
645 | 79 | with self.assertRaises(SystemExit) as raised: | ||
646 | 80 | cmds.init('dummy args') | ||
647 | 81 | self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.') | ||
648 | 82 | self.assertEqual( | ||
649 | 83 | 'snapcraft.yaml already exists!\n', fake_logger.output) | ||
650 | 84 | |||
651 | 85 | def test_init_without_parts_must_write_snapcraft_yaml(self): | ||
652 | 86 | fake_logger = fixtures.FakeLogger(level=logging.INFO) | ||
653 | 87 | self.useFixture(fake_logger) | ||
654 | 88 | |||
655 | 89 | snap_without_parts = type('obj', (object, ), {'part': []}) | ||
656 | 90 | with self.assertRaises(SystemExit) as raised: | ||
657 | 91 | cmds.init(snap_without_parts) | ||
658 | 92 | |||
659 | 93 | self.assertEqual(raised.exception.code, 0, 'Wrong exit code returned.') | ||
660 | 94 | self.assertEqual( | ||
661 | 95 | 'Wrote the following as snapcraft.yaml:\n' | ||
662 | 96 | 'parts:\n', | ||
663 | 97 | fake_logger.output) | ||
664 | 60 | 98 | ||
665 | === modified file 'snapcraft/tests/test_copy_plugin.py' | |||
666 | --- snapcraft/tests/test_copy_plugin.py 2015-07-22 21:05:20 +0000 | |||
667 | +++ snapcraft/tests/test_copy_plugin.py 2015-07-23 17:20:28 +0000 | |||
668 | @@ -14,11 +14,11 @@ | |||
669 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
670 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
671 | 16 | 16 | ||
672 | 17 | import logging | ||
673 | 17 | import os.path | 18 | import os.path |
678 | 18 | from unittest.mock import ( | 19 | from unittest.mock import Mock |
679 | 19 | Mock, | 20 | |
680 | 20 | patch, | 21 | import fixtures |
677 | 21 | ) | ||
681 | 22 | 22 | ||
682 | 23 | from snapcraft.plugins.copy import CopyPlugin | 23 | from snapcraft.plugins.copy import CopyPlugin |
683 | 24 | from snapcraft.tests import TestCase | 24 | from snapcraft.tests import TestCase |
684 | @@ -43,12 +43,17 @@ | |||
685 | 43 | } | 43 | } |
686 | 44 | open("zzz", "w").close() | 44 | open("zzz", "w").close() |
687 | 45 | c = CopyPlugin("copy", self.mock_options) | 45 | c = CopyPlugin("copy", self.mock_options) |
692 | 46 | with patch("snapcraft.common.log") as mock_log: | 46 | |
693 | 47 | res = c.build() | 47 | fake_logger = fixtures.FakeLogger(level=logging.WARNING) |
694 | 48 | self.assertFalse(res) | 48 | self.useFixture(fake_logger) |
695 | 49 | mock_log.assert_called_with("WARNING: file 'src' missing") | 49 | |
696 | 50 | res = c.build() | ||
697 | 51 | self.assertFalse(res) | ||
698 | 52 | self.assertEqual("WARNING: file 'src' missing\n", fake_logger.output) | ||
699 | 50 | 53 | ||
700 | 51 | def test_copy_plugin_copies(self): | 54 | def test_copy_plugin_copies(self): |
701 | 55 | self.useFixture(fixtures.FakeLogger()) | ||
702 | 56 | |||
703 | 52 | self.mock_options.files = { | 57 | self.mock_options.files = { |
704 | 53 | "src": "dst", | 58 | "src": "dst", |
705 | 54 | } | 59 | } |
706 | @@ -59,6 +64,8 @@ | |||
707 | 59 | self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst"))) | 64 | self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst"))) |
708 | 60 | 65 | ||
709 | 61 | def test_copy_plugin_creates_prefixes(self): | 66 | def test_copy_plugin_creates_prefixes(self): |
710 | 67 | self.useFixture(fixtures.FakeLogger()) | ||
711 | 68 | |||
712 | 62 | self.mock_options.files = { | 69 | self.mock_options.files = { |
713 | 63 | "src": "dir/dst", | 70 | "src": "dir/dst", |
714 | 64 | } | 71 | } |
715 | 65 | 72 | ||
716 | === modified file 'snapcraft/tests/test_plugin.py' | |||
717 | --- snapcraft/tests/test_plugin.py 2015-07-22 21:05:20 +0000 | |||
718 | +++ snapcraft/tests/test_plugin.py 2015-07-23 17:20:28 +0000 | |||
719 | @@ -14,25 +14,29 @@ | |||
720 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
721 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
722 | 16 | 16 | ||
723 | 17 | import logging | ||
724 | 17 | import os | 18 | import os |
725 | 18 | import sys | 19 | import sys |
726 | 19 | import tempfile | 20 | import tempfile |
727 | 20 | 21 | ||
728 | 22 | import fixtures | ||
729 | 21 | from unittest.mock import ( | 23 | from unittest.mock import ( |
730 | 22 | Mock, | 24 | Mock, |
731 | 23 | patch, | 25 | patch, |
732 | 24 | ) | 26 | ) |
733 | 25 | 27 | ||
734 | 28 | import snapcraft.tests.mock_plugin | ||
735 | 26 | from snapcraft.plugin import PluginHandler, PluginError | 29 | from snapcraft.plugin import PluginHandler, PluginError |
736 | 27 | from snapcraft.tests import TestCase | 30 | from snapcraft.tests import TestCase |
737 | 28 | 31 | ||
738 | 29 | import snapcraft.tests.mock_plugin | ||
739 | 30 | |||
740 | 31 | 32 | ||
741 | 32 | class TestPlugin(TestCase): | 33 | class TestPlugin(TestCase): |
742 | 33 | 34 | ||
743 | 35 | def get_test_plugin(self): | ||
744 | 36 | return PluginHandler('mock', 'mock-part', {}, load_config=False, load_code=False) | ||
745 | 37 | |||
746 | 34 | def test_is_dirty(self): | 38 | def test_is_dirty(self): |
748 | 35 | p = PluginHandler("mock", "mock-part", {}, load_config=False, load_code=False) | 39 | p = self.get_test_plugin() |
749 | 36 | p.statefile = tempfile.NamedTemporaryFile().name | 40 | p.statefile = tempfile.NamedTemporaryFile().name |
750 | 37 | self.addCleanup(os.remove, p.statefile) | 41 | self.addCleanup(os.remove, p.statefile) |
751 | 38 | p.code = Mock() | 42 | p.code = Mock() |
752 | @@ -45,7 +49,7 @@ | |||
753 | 45 | self.assertFalse(p.code.pull.called) | 49 | self.assertFalse(p.code.pull.called) |
754 | 46 | 50 | ||
755 | 47 | def test_collect_snap_files(self): | 51 | def test_collect_snap_files(self): |
757 | 48 | p = PluginHandler("mock", "mock-part", {}, load_config=False, load_code=False) | 52 | p = self.get_test_plugin() |
758 | 49 | 53 | ||
759 | 50 | tmpdirObject = tempfile.TemporaryDirectory() | 54 | tmpdirObject = tempfile.TemporaryDirectory() |
760 | 51 | self.addCleanup(tmpdirObject.cleanup) | 55 | self.addCleanup(tmpdirObject.cleanup) |
761 | @@ -92,6 +96,15 @@ | |||
762 | 92 | set(['1', '1/1a', '1/1a/1b', '2', '2/2a']), | 96 | set(['1', '1/1a', '1/1a/1b', '2', '2/2a']), |
763 | 93 | set())) | 97 | set())) |
764 | 94 | 98 | ||
765 | 99 | def test_notify_stage_must_log_information(self): | ||
766 | 100 | fake_logger = fixtures.FakeLogger(level=logging.INFO) | ||
767 | 101 | self.useFixture(fake_logger) | ||
768 | 102 | |||
769 | 103 | plugin = self.get_test_plugin() | ||
770 | 104 | plugin.notify_stage('test stage') | ||
771 | 105 | |||
772 | 106 | self.assertEqual('test stage mock-part\n', fake_logger.output) | ||
773 | 107 | |||
774 | 95 | def test_local_plugins(self): | 108 | def test_local_plugins(self): |
775 | 96 | """Ensure local plugins are loaded from parts/plugins""" | 109 | """Ensure local plugins are loaded from parts/plugins""" |
776 | 97 | def mock_import_modules(module_name): | 110 | def mock_import_modules(module_name): |
777 | 98 | 111 | ||
778 | === modified file 'snapcraft/tests/test_yaml.py' | |||
779 | --- snapcraft/tests/test_yaml.py 2015-07-17 17:00:18 +0000 | |||
780 | +++ snapcraft/tests/test_yaml.py 2015-07-23 17:20:28 +0000 | |||
781 | @@ -14,15 +14,18 @@ | |||
782 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
783 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
784 | 16 | 16 | ||
785 | 17 | import logging | ||
786 | 17 | import os | 18 | import os |
787 | 18 | import tempfile | 19 | import tempfile |
788 | 19 | import unittest | 20 | import unittest |
791 | 20 | from unittest.mock import ( | 21 | |
792 | 21 | patch, | 22 | import fixtures |
793 | 23 | |||
794 | 24 | from snapcraft import ( | ||
795 | 25 | common, | ||
796 | 26 | dirs | ||
797 | 22 | ) | 27 | ) |
798 | 23 | |||
799 | 24 | from snapcraft.yaml import Config | 28 | from snapcraft.yaml import Config |
800 | 25 | |||
801 | 26 | from snapcraft.tests import TestCase | 29 | from snapcraft.tests import TestCase |
802 | 27 | 30 | ||
803 | 28 | 31 | ||
804 | @@ -46,16 +49,27 @@ | |||
805 | 46 | "package": "fswebcam", | 49 | "package": "fswebcam", |
806 | 47 | }) | 50 | }) |
807 | 48 | 51 | ||
810 | 49 | @patch("snapcraft.common.log") | 52 | def test_config_raises_on_missing_snapcraft_yaml(self): |
811 | 50 | def test_config_raises_on_missing_snapcraft_yaml(self, mock_log): | 53 | fake_logger = fixtures.FakeLogger(level=logging.ERROR) |
812 | 54 | self.useFixture(fake_logger) | ||
813 | 55 | |||
814 | 51 | # no snapcraft.yaml | 56 | # no snapcraft.yaml |
816 | 52 | with self.assertRaises(SystemExit): | 57 | with self.assertRaises(SystemExit) as raised: |
817 | 53 | Config() | 58 | Config() |
823 | 54 | mock_log.assert_called_with("""Could not find snapcraft.yaml. Are you sure you're in the right directory? | 59 | |
824 | 55 | To start a new project, use 'snapcraft init'""") | 60 | self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.') |
825 | 56 | 61 | self.assertEqual( | |
826 | 57 | @patch("snapcraft.common.log") | 62 | "Could not find snapcraft.yaml. Are you sure you're in the right directory?\n" |
827 | 58 | def test_config_loop(self, mock_log): | 63 | "To start a new project, use 'snapcraft init'\n", |
828 | 64 | fake_logger.output) | ||
829 | 65 | |||
830 | 66 | def test_config_loop(self): | ||
831 | 67 | self.addCleanup(common.set_plugindir, common.get_plugindir()) | ||
832 | 68 | dirs.setup_dirs() | ||
833 | 69 | |||
834 | 70 | fake_logger = fixtures.FakeLogger(level=logging.ERROR) | ||
835 | 71 | self.useFixture(fake_logger) | ||
836 | 72 | |||
837 | 59 | self.make_snapcraft_yaml("""parts: | 73 | self.make_snapcraft_yaml("""parts: |
838 | 60 | p1: | 74 | p1: |
839 | 61 | plugin: ubuntu | 75 | plugin: ubuntu |
840 | @@ -64,6 +78,8 @@ | |||
841 | 64 | plugin: ubuntu | 78 | plugin: ubuntu |
842 | 65 | after: [p1] | 79 | after: [p1] |
843 | 66 | """) | 80 | """) |
845 | 67 | with self.assertRaises(SystemExit): | 81 | with self.assertRaises(SystemExit) as raised: |
846 | 68 | Config() | 82 | Config() |
848 | 69 | mock_log.assert_called_with("Circular dependency chain!") | 83 | |
849 | 84 | self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.') | ||
850 | 85 | self.assertEqual('Circular dependency chain!\n', fake_logger.output) | ||
851 | 70 | 86 | ||
852 | === modified file 'snapcraft/yaml.py' | |||
853 | --- snapcraft/yaml.py 2015-07-22 13:57:19 +0000 | |||
854 | +++ snapcraft/yaml.py 2015-07-23 17:20:28 +0000 | |||
855 | @@ -14,11 +14,17 @@ | |||
856 | 14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
857 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
858 | 16 | 16 | ||
861 | 17 | import snapcraft.common | 17 | import logging |
860 | 18 | import snapcraft.plugin | ||
862 | 19 | import sys | 18 | import sys |
863 | 19 | |||
864 | 20 | import yaml | 20 | import yaml |
865 | 21 | 21 | ||
866 | 22 | import snapcraft.plugin | ||
867 | 23 | from snapcraft import common | ||
868 | 24 | |||
869 | 25 | |||
870 | 26 | logger = logging.getLogger(__name__) | ||
871 | 27 | |||
872 | 22 | 28 | ||
873 | 23 | class Config: | 29 | class Config: |
874 | 24 | 30 | ||
875 | @@ -31,7 +37,7 @@ | |||
876 | 31 | with open("snapcraft.yaml", 'r') as fp: | 37 | with open("snapcraft.yaml", 'r') as fp: |
877 | 32 | self.data = yaml.load(fp) | 38 | self.data = yaml.load(fp) |
878 | 33 | except FileNotFoundError: | 39 | except FileNotFoundError: |
880 | 34 | snapcraft.common.log("Could not find snapcraft.yaml. Are you sure you're in the right directory?\nTo start a new project, use 'snapcraft init'") | 40 | logger.error("Could not find snapcraft.yaml. Are you sure you're in the right directory?\nTo start a new project, use 'snapcraft init'") |
881 | 35 | sys.exit(1) | 41 | sys.exit(1) |
882 | 36 | self.build_tools = self.data.get('build-tools', []) | 42 | self.build_tools = self.data.get('build-tools', []) |
883 | 37 | 43 | ||
884 | @@ -75,7 +81,7 @@ | |||
885 | 75 | foundIt = True | 81 | foundIt = True |
886 | 76 | break | 82 | break |
887 | 77 | if not foundIt: | 83 | if not foundIt: |
889 | 78 | snapcraft.common.log("Could not find part name %s" % dep) | 84 | logger.error("Could not find part name %s" % dep) |
890 | 79 | sys.exit(1) | 85 | sys.exit(1) |
891 | 80 | 86 | ||
892 | 81 | # Now sort them (this is super inefficient, but easy-ish to follow) | 87 | # Now sort them (this is super inefficient, but easy-ish to follow) |
893 | @@ -92,7 +98,7 @@ | |||
894 | 92 | topPart = part | 98 | topPart = part |
895 | 93 | break | 99 | break |
896 | 94 | if not topPart: | 100 | if not topPart: |
898 | 95 | snapcraft.common.log("Circular dependency chain!") | 101 | logger.error("Circular dependency chain!") |
899 | 96 | sys.exit(1) | 102 | sys.exit(1) |
900 | 97 | sortedParts = [topPart] + sortedParts | 103 | sortedParts = [topPart] + sortedParts |
901 | 98 | self.all_parts.remove(topPart) | 104 | self.all_parts.remove(topPart) |
902 | @@ -132,7 +138,7 @@ | |||
903 | 132 | return env | 138 | return env |
904 | 133 | 139 | ||
905 | 134 | def stage_env(self): | 140 | def stage_env(self): |
907 | 135 | root = snapcraft.common.stagedir | 141 | root = common.get_stagedir() |
908 | 136 | env = [] | 142 | env = [] |
909 | 137 | 143 | ||
910 | 138 | env += self.runtime_env(root) | 144 | env += self.runtime_env(root) |
911 | @@ -143,7 +149,7 @@ | |||
912 | 143 | return env | 149 | return env |
913 | 144 | 150 | ||
914 | 145 | def snap_env(self): | 151 | def snap_env(self): |
916 | 146 | root = snapcraft.common.snapdir | 152 | root = common.get_snapdir() |
917 | 147 | env = [] | 153 | env = [] |
918 | 148 | 154 | ||
919 | 149 | env += self.runtime_env(root) | 155 | env += self.runtime_env(root) |