Merge lp:~mvo/snapcraft/demo-pep8-pyflakes into lp:~snappy-dev/snapcraft/abandoned-go-trunk
- demo-pep8-pyflakes
- Merge into abandoned-go-trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~mvo/snapcraft/demo-pep8-pyflakes |
Merge into: | lp:~snappy-dev/snapcraft/abandoned-go-trunk |
Diff against target: |
1262 lines (+1057/-0) (has conflicts) 38 files modified
.bzrignore (+3/-0) bin/snapcraft (+260/-0) examples/godd/meta/package.yaml (+5/-0) examples/godd/meta/readme.md (+1/-0) examples/godd/snapcraft.yaml (+4/-0) examples/gopaste/Makefile (+8/-0) examples/gopaste/gopaste (+10/-0) examples/gopaste/meta/package.yaml (+7/-0) examples/gopaste/meta/readme.md (+1/-0) examples/gopaste/snapcraft.yaml (+4/-0) examples/libpipeline/Makefile (+11/-0) examples/libpipeline/meta/package.yaml (+5/-0) examples/libpipeline/meta/readme.md (+1/-0) examples/libpipeline/snapcraft.yaml (+9/-0) examples/libpipeline/test.c (+18/-0) examples/webcam-webui-snap/meta/package.yaml (+7/-0) examples/webcam-webui-snap/meta/readme.md (+3/-0) examples/webcam-webui-snap/snapcraft.yaml (+6/-0) examples/webcam-webui-snap/webcam-webui (+16/-0) examples/wget-deb/meta/package.yaml (+5/-0) examples/wget-deb/meta/readme.md (+1/-0) examples/wget-deb/snapcraft.yaml (+4/-0) plugins/autotools-project.py (+32/-0) plugins/autotools-project.yaml (+6/-0) plugins/go1.4-project.py (+42/-0) plugins/go1.4-project.yaml (+7/-0) plugins/go1.4.py (+44/-0) plugins/make-project.py (+21/-0) plugins/make-project.yaml (+4/-0) plugins/manifest.txt (+97/-0) plugins/readline.yaml (+3/-0) plugins/snapcraft.py (+93/-0) plugins/tgz-content.py (+16/-0) plugins/tgz-content.yaml (+5/-0) run-checks.sh (+17/-0) snapcraft/__init__.py (+75/-0) snapcraft/common.py (+34/-0) snapcraft/plugin.py (+172/-0) Conflict adding file .bzrignore. Moved existing file to .bzrignore.moved. |
To merge this branch: | bzr merge lp:~mvo/snapcraft/demo-pep8-pyflakes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Snappy Developers | Pending | ||
Review via email: mp+263358@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-06-30.
Commit message
pep8/pyflakes and reindent.
Description of the change
Sorry for the churn in this branch.
It fixes pep8/pyflakes issues and adds a "run-checks.py" script that enforces pep8/pyflakes. It also uses spaces instead of tabs as this is what pep8 recommends. I hope that is ok with you (ironically the reverse recommendation that go makes).
Its mostly mechanical so no human needs to go over the diff, I just didn't want to commit it directly in case there is concern about the changes :)
Unmerged revisions
- 48. By Michael Vogt
-
pep8/pyflakes
- 47. By Michael Vogt
-
run reindent.py
- 46. By Michael Terry
-
add missing Makefile
- 45. By Michael Terry
-
Fix deb packages
- 44. By Michael Terry
-
Fix some output
- 43. By Michael Terry
-
Some renames
- 42. By Michael Terry
-
Add more examples
- 41. By Michael Terry
-
Fix deb inclusion; add example for it
- 40. By Michael Terry
-
Wrap scripts when assembling
- 39. By Michael Terry
-
initial mostly-working pass at includedPackages support
Preview Diff
1 | === added file '.bzrignore' |
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 |
3 | +++ .bzrignore 2015-06-30 14:21:21 +0000 |
4 | @@ -0,0 +1,3 @@ |
5 | +**/parts/ |
6 | +**/snap/ |
7 | +**/stage/ |
8 | |
9 | === renamed file '.bzrignore' => '.bzrignore.moved' |
10 | === added directory 'bin' |
11 | === added file 'bin/snapcraft' |
12 | --- bin/snapcraft 1970-01-01 00:00:00 +0000 |
13 | +++ bin/snapcraft 2015-06-30 14:21:21 +0000 |
14 | @@ -0,0 +1,260 @@ |
15 | +#!/usr/bin/python3 |
16 | +# -*- Mode:Python; -*- |
17 | + |
18 | +import glob |
19 | +import os |
20 | +import subprocess |
21 | +import sys |
22 | +import tempfile |
23 | +import time |
24 | +import yaml |
25 | + |
26 | +sys.path.append(os.path.abspath(os.path.join(__file__, "..", ".."))) |
27 | +import snapcraft |
28 | +import snapcraft.common |
29 | +import snapcraft.plugin |
30 | + |
31 | +systemPackages = [] |
32 | +includedPackages = [] |
33 | +allParts = [] |
34 | +afterRequests = {} |
35 | + |
36 | +pluginDir = os.path.abspath(os.path.join(__file__, "..", "..", "plugins")) |
37 | + |
38 | + |
39 | +def loadPlugin(partName, pluginName, properties, loadCode=True): |
40 | + global allParts, systemPackages, includedPackages |
41 | + |
42 | + part = snapcraft.plugin.Plugin( |
43 | + pluginDir, pluginName, partName, properties, loadCode=loadCode) |
44 | + if not part.isValid(): |
45 | + snapcraft.common.log( |
46 | + "Could not load part %s" % pluginName, file=sys.stderr) |
47 | + sys.exit(1) |
48 | + |
49 | + systemPackages += part.config.get('systemPackages', []) |
50 | + includedPackages += part.config.get('includedPackages', []) |
51 | + allParts.append(part) |
52 | + return part |
53 | + |
54 | +cmds = sys.argv[1:] |
55 | +if not cmds: |
56 | + snapcraft.common.log("Need an argument", file=sys.stderr) |
57 | + sys.exit(1) |
58 | + |
59 | +forceAll = False |
60 | +forceCommand = None |
61 | +if "--force" in cmds: |
62 | + cmds.remove("--force") |
63 | + forceAll = True |
64 | + |
65 | +if cmds[0] == "all": |
66 | + cmds = snapcraft.common.commandOrder |
67 | +else: |
68 | + if cmds[0] in snapcraft.common.commandOrder: |
69 | + forceCommand = cmds[0] |
70 | + cmds = snapcraft.common.commandOrder[ |
71 | + 0:snapcraft.common.commandOrder.index(cmds[0])+1] |
72 | + |
73 | +if cmds[0] == "init": |
74 | + if os.path.exists("snapcraft.yaml"): |
75 | + snapcraft.common.log("snapcraft.yaml already exists!", file=sys.stderr) |
76 | + sys.exit(1) |
77 | + yamlstr = 'parts:\n' |
78 | + for partName in cmds[1:]: |
79 | + loadPlugin(partName, partName, {}, loadCode=False) |
80 | + for part in allParts: |
81 | + yamlstr += ' ' + part.names()[0] + ':\n' |
82 | + for opt in part.config.get('options', []): |
83 | + if part.config['options'][opt].get('required', False): |
84 | + yamlstr += ' ' + opt + ':\n' |
85 | + yamlstr = yamlstr.strip() |
86 | + with open('snapcraft.yaml', mode='w+') as f: |
87 | + f.write(yaml) |
88 | + snapcraft.common.log("Wrote the following as snapcraft.yaml.") |
89 | + print() |
90 | + print(yamlstr) |
91 | + sys.exit(0) |
92 | + |
93 | +data = yaml.load(open("snapcraft.yaml", 'r')) |
94 | +systemPackages = data.get('systemPackages', []) |
95 | +includedPackages = data.get('includedPackages', []) |
96 | + |
97 | +for partName in data.get("parts", []): |
98 | + properties = data["parts"][partName] |
99 | + |
100 | + pluginName = properties.get("plugin", partName) |
101 | + if "plugin" in properties: |
102 | + del properties["plugin"] |
103 | + |
104 | + if "after" in properties: |
105 | + afterRequests[partName] = properties["after"] |
106 | + del properties["after"] |
107 | + |
108 | + loadPlugin(partName, pluginName, properties) |
109 | + |
110 | +# Grab all required dependencies, if not already specified |
111 | +newParts = allParts.copy() |
112 | +while newParts: |
113 | + part = newParts.pop(0) |
114 | + requires = part.config.get('requires', []) |
115 | + for requiredPart in requires: |
116 | + alreadyPresent = False |
117 | + for p in allParts: |
118 | + if requiredPart in p.names(): |
119 | + alreadyPresent = True |
120 | + break |
121 | + if not alreadyPresent: |
122 | + newParts.append(loadPlugin(requiredPart, requiredPart, {})) |
123 | + |
124 | +# Now sort them |
125 | +partsToSort = allParts.copy() |
126 | +while partsToSort: |
127 | + part = partsToSort.pop(0) |
128 | + requires = part.config.get('requires', []) |
129 | + for requiredPart in requires: |
130 | + for i in range(len(allParts)): |
131 | + if requiredPart in allParts[i].names(): |
132 | + allParts.insert(0, allParts.pop(i)) |
133 | + break |
134 | + afterNames = afterRequests.get(part.names()[0], []) |
135 | + for afterName in afterNames: |
136 | + for i in range(len(allParts)): |
137 | + if afterName in allParts[i].names(): |
138 | + allParts.insert(0, allParts.pop(i)) |
139 | + break |
140 | + |
141 | +# Install local packages that we need |
142 | +if systemPackages: |
143 | + newPackages = [] |
144 | + for checkpkg in systemPackages: |
145 | + if subprocess.call( |
146 | + ['dpkg-query', '-s', checkpkg], |
147 | + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0: |
148 | + newPackages.append(checkpkg) |
149 | + if newPackages: |
150 | + print("Installing required packages on the host system: %s" % |
151 | + ", ".join(newPackages)) |
152 | + subprocess.call( |
153 | + ['sudo', 'apt-get', 'install'] + newPackages, |
154 | + stdout=subprocess.DEVNULL) |
155 | + |
156 | +if includedPackages: |
157 | + class Options: |
158 | + pass |
159 | + options = Options() |
160 | + setattr(options, 'includedPackages', includedPackages) |
161 | + part = snapcraft.plugin.Plugin( |
162 | + pluginDir, 'snapcraft', 'includedPackages', {}, |
163 | + optionsOverride=options, loadConfig=False) |
164 | + part.includedPackages = includedPackages |
165 | + allParts = [part] + allParts |
166 | + |
167 | +env = [] |
168 | +env.append("PATH=\"%s/bin:%s/usr/bin:$PATH\"" % ( |
169 | + snapcraft.common.stagedir, snapcraft.common.stagedir)) |
170 | +env.append("LD_LIBRARY_PATH=\"%s/lib:%s/usr/lib:$LD_LIBRARY_PATH\"" % ( |
171 | + snapcraft.common.stagedir, snapcraft.common.stagedir)) |
172 | +env.append("CFLAGS=\"-I%s/include $CFLAGS\"" % snapcraft.common.stagedir) |
173 | +env.append("LDFLAGS=\"-L%s/lib $LDFLAGS\"" % snapcraft.common.stagedir) |
174 | + |
175 | +if cmds[0] == "shell": |
176 | + for part in allParts: |
177 | + env += part.env() |
178 | + snapcraft.common.env = env |
179 | + userCommand = ' '.join(cmds[1:]) |
180 | + if not userCommand: |
181 | + userCommand = ("/usr/bin/env " + |
182 | + "PS1='\[\e[1;32m\]snapcraft:\w\$\[\e[0m\] ' " + |
183 | + "/bin/bash --norc") |
184 | + snapcraft.common.run(userCommand) |
185 | + |
186 | +elif cmds[0] == "assemble": |
187 | + snapcraft.common.run( |
188 | + "cp -arv %s %s" % (data["snap"]["meta"], snapcraft.common.snapdir)) |
189 | + |
190 | + # wrap all included commands |
191 | + for part in allParts: |
192 | + env += part.env() |
193 | + snapcraft.common.env = env |
194 | + script = "#!/bin/sh\n%s\nexec %%s $*" % \ |
195 | + snapcraft.common.assembleEnv().replace( |
196 | + snapcraft.common.stagedir, "$SNAP_APP_PATH") |
197 | + |
198 | + def wrapBins(bindir): |
199 | + absbindir = os.path.join(snapcraft.common.snapdir, bindir) |
200 | + if not os.path.exists(absbindir): |
201 | + return |
202 | + for exe in os.listdir(absbindir): |
203 | + if exe.endswith('.real'): |
204 | + continue |
205 | + exePath = os.path.join(absbindir, exe) |
206 | + try: |
207 | + os.remove(exePath + '.real') |
208 | + except: |
209 | + pass |
210 | + os.rename(exePath, exePath + '.real') |
211 | + with open(exePath, 'w+') as f: |
212 | + f.write(script % ( |
213 | + '"$SNAP_APP_PATH/' + bindir + '/' + exe + '.real"')) |
214 | + os.chmod(exePath, 0o755) |
215 | + wrapBins('bin') |
216 | + wrapBins('usr/bin') |
217 | + |
218 | + snapcraft.common.run("snappy build " + snapcraft.common.snapdir) |
219 | + |
220 | + |
221 | +elif cmds[0] == "run": |
222 | + qemudir = os.path.join(os.getcwd(), "image") |
223 | + qemu_img = os.path.join(qemudir, "15.04.img") |
224 | + if not os.path.exists(qemu_img): |
225 | + try: |
226 | + os.makedirs(qemudir) |
227 | + except FileExistsError: |
228 | + pass |
229 | + snapcraft.common.run( |
230 | + "sudo ubuntu-device-flash core --developer-mode" |
231 | + "--enable-ssh 15.04 -o %s" % qemu_img, |
232 | + cwd=qemudir) |
233 | + qemu = subprocess.Popen( |
234 | + ["kvm", "-m", "768", "-nographic", |
235 | + "-snapshot", "-redir", "tcp:8022::22", qemu_img], |
236 | + stdin=subprocess.PIPE) |
237 | + n = tempfile.NamedTemporaryFile() |
238 | + ssh_opts = [ |
239 | + "-oStrictHostKeyChecking=no", |
240 | + "-oUserKnownHostsFile=%s" % n.name |
241 | + ] |
242 | + while True: |
243 | + ret_code = subprocess.call( |
244 | + ["ssh"] + ssh_opts + |
245 | + ["ubuntu@localhost", "-p", "8022", "true"]) |
246 | + if ret_code == 0: |
247 | + break |
248 | + print("Waiting for device") |
249 | + time.sleep(1) |
250 | + snap_dir = os.path.join(os.getcwd(), "snap") |
251 | + # copy the snap |
252 | + snaps = glob.glob(snap_dir+"/*.snap") |
253 | + subprocess.call( |
254 | + ["scp"]+ssh_opts+[ |
255 | + "-P", "8022", "-r"]+snaps+["ubuntu@localhost:~/"]) |
256 | + # install the snap |
257 | + ret_code = subprocess.call( |
258 | + ["ssh"] + ssh_opts + |
259 | + ["ubuntu@localhost", "-p", "8022", "sudo snappy install *.snap"]) |
260 | + # "login" |
261 | + subprocess.call( |
262 | + ["ssh"]+ssh_opts+["-p", "8022", "ubuntu@localhost"], |
263 | + preexec_fn=os.setsid) |
264 | + qemu.kill() |
265 | +else: |
266 | + for part in allParts: |
267 | + env += part.env() |
268 | + snapcraft.common.env = env |
269 | + for cmd in cmds: |
270 | + force = forceAll or cmd == forceCommand |
271 | + if not getattr(part, cmd)(force=force): |
272 | + snapcraft.common.log( |
273 | + "Failed doing %s for %s!" % (cmd, part.names()[0])) |
274 | + sys.exit(1) |
275 | |
276 | === added directory 'examples' |
277 | === added directory 'examples/godd' |
278 | === added directory 'examples/godd/meta' |
279 | === added file 'examples/godd/meta/package.yaml' |
280 | --- examples/godd/meta/package.yaml 1970-01-01 00:00:00 +0000 |
281 | +++ examples/godd/meta/package.yaml 2015-06-30 14:21:21 +0000 |
282 | @@ -0,0 +1,5 @@ |
283 | +name: godd |
284 | +version: 1.0 |
285 | +vendor: Michael Vogt <mvo@ubuntu.com> |
286 | +binaries: |
287 | + - name: ./bin/godd |
288 | |
289 | === added file 'examples/godd/meta/readme.md' |
290 | --- examples/godd/meta/readme.md 1970-01-01 00:00:00 +0000 |
291 | +++ examples/godd/meta/readme.md 2015-06-30 14:21:21 +0000 |
292 | @@ -0,0 +1,1 @@ |
293 | +Simple dd like tool |
294 | |
295 | === added file 'examples/godd/snapcraft.yaml' |
296 | --- examples/godd/snapcraft.yaml 1970-01-01 00:00:00 +0000 |
297 | +++ examples/godd/snapcraft.yaml 2015-06-30 14:21:21 +0000 |
298 | @@ -0,0 +1,4 @@ |
299 | +parts: |
300 | + godd: |
301 | + plugin: go1.4-project |
302 | + source: git://github.com/mvo5/godd |
303 | |
304 | === added directory 'examples/gopaste' |
305 | === added file 'examples/gopaste/Makefile' |
306 | --- examples/gopaste/Makefile 1970-01-01 00:00:00 +0000 |
307 | +++ examples/gopaste/Makefile 2015-06-30 14:21:21 +0000 |
308 | @@ -0,0 +1,8 @@ |
309 | +# -*- Mode: Makefile; indent-tabs-mode:t; tab-width: 4 -*- |
310 | + |
311 | +all: |
312 | + cp parts/gopaste/src/github.com/wisnij/gopaste/web.template snap/ |
313 | + cp -r parts/gopaste/src/github.com/wisnij/gopaste/static snap/ |
314 | + cp -r meta snap/ |
315 | + cp gopaste snap/bin/ |
316 | + |
317 | |
318 | === added file 'examples/gopaste/gopaste' |
319 | --- examples/gopaste/gopaste 1970-01-01 00:00:00 +0000 |
320 | +++ examples/gopaste/gopaste 2015-06-30 14:21:21 +0000 |
321 | @@ -0,0 +1,10 @@ |
322 | +#!/bin/sh |
323 | + |
324 | +set -x |
325 | + |
326 | +cd $SNAP_APP_DATA_PATH |
327 | +cp $SNAP_APP_PATH/web.template . |
328 | +cp -r $SNAP_APP_PATH/static . |
329 | +export HOME=$SNAP_APP_DATA_PATH |
330 | + |
331 | +exec $SNAP_APP_PATH/bin/gopasted |
332 | |
333 | === added directory 'examples/gopaste/meta' |
334 | === added file 'examples/gopaste/meta/package.yaml' |
335 | --- examples/gopaste/meta/package.yaml 1970-01-01 00:00:00 +0000 |
336 | +++ examples/gopaste/meta/package.yaml 2015-06-30 14:21:21 +0000 |
337 | @@ -0,0 +1,7 @@ |
338 | +name: gopaste |
339 | +version: 1.0 |
340 | +vendor: mterry@ubuntu.com |
341 | +services: |
342 | + - name: gopaste |
343 | + description: "gopaste" |
344 | + start: bin/gopaste |
345 | |
346 | === added file 'examples/gopaste/meta/readme.md' |
347 | --- examples/gopaste/meta/readme.md 1970-01-01 00:00:00 +0000 |
348 | +++ examples/gopaste/meta/readme.md 2015-06-30 14:21:21 +0000 |
349 | @@ -0,0 +1,1 @@ |
350 | +Simple dd like tool |
351 | |
352 | === added file 'examples/gopaste/snapcraft.yaml' |
353 | --- examples/gopaste/snapcraft.yaml 1970-01-01 00:00:00 +0000 |
354 | +++ examples/gopaste/snapcraft.yaml 2015-06-30 14:21:21 +0000 |
355 | @@ -0,0 +1,4 @@ |
356 | +parts: |
357 | + gopaste: |
358 | + plugin: go1.4-project |
359 | + source: git://github.com/wisnij/gopaste/gopasted |
360 | |
361 | === added directory 'examples/libpipeline' |
362 | === added file 'examples/libpipeline/Makefile' |
363 | --- examples/libpipeline/Makefile 1970-01-01 00:00:00 +0000 |
364 | +++ examples/libpipeline/Makefile 2015-06-30 14:21:21 +0000 |
365 | @@ -0,0 +1,11 @@ |
366 | +# -*- Mode:Makefile; indent-tabs-mode:t; tab-width:4 -*- |
367 | + |
368 | +all: |
369 | + gcc -o test ./test.c $(CFLAGS) $(LDFLAGS) -lpipeline |
370 | + |
371 | +install: |
372 | + install -d -m755 $(DESTDIR)/bin/ |
373 | + install -m755 ./test $(DESTDIR)/bin/test |
374 | + |
375 | +clean: |
376 | + rm -f test |
377 | |
378 | === added directory 'examples/libpipeline/meta' |
379 | === added file 'examples/libpipeline/meta/package.yaml' |
380 | --- examples/libpipeline/meta/package.yaml 1970-01-01 00:00:00 +0000 |
381 | +++ examples/libpipeline/meta/package.yaml 2015-06-30 14:21:21 +0000 |
382 | @@ -0,0 +1,5 @@ |
383 | +name: pipelinetest |
384 | +version: 1.0 |
385 | +vendor: Mike Terry |
386 | +binaries: |
387 | + - name: ./bin/pipelinetest |
388 | |
389 | === added file 'examples/libpipeline/meta/readme.md' |
390 | --- examples/libpipeline/meta/readme.md 1970-01-01 00:00:00 +0000 |
391 | +++ examples/libpipeline/meta/readme.md 2015-06-30 14:21:21 +0000 |
392 | @@ -0,0 +1,1 @@ |
393 | +Libpipeline example |
394 | |
395 | === added file 'examples/libpipeline/snapcraft.yaml' |
396 | --- examples/libpipeline/snapcraft.yaml 1970-01-01 00:00:00 +0000 |
397 | +++ examples/libpipeline/snapcraft.yaml 2015-06-30 14:21:21 +0000 |
398 | @@ -0,0 +1,9 @@ |
399 | +parts: |
400 | + pipelinetest: |
401 | + plugin: make-project |
402 | + source: lp:~mterry/+junk/pipelinetest |
403 | + after: |
404 | + - libpipeline |
405 | + libpipeline: |
406 | + plugin: autotools-project |
407 | + source: lp:~mterry/libpipeline/printf |
408 | |
409 | === added file 'examples/libpipeline/test.c' |
410 | --- examples/libpipeline/test.c 1970-01-01 00:00:00 +0000 |
411 | +++ examples/libpipeline/test.c 2015-06-30 14:21:21 +0000 |
412 | @@ -0,0 +1,18 @@ |
413 | +#include <pipeline.h> |
414 | +#include <stdio.h> |
415 | + |
416 | +int main() |
417 | +{ |
418 | + pipeline *p; |
419 | + int status; |
420 | + |
421 | + printf("running ls | grep s | grep t\n"); |
422 | + |
423 | + p = pipeline_new (); |
424 | + pipeline_command_args (p, "ls", NULL); |
425 | + pipeline_command_args (p, "grep", "s", NULL); |
426 | + pipeline_command_args (p, "grep", "t", NULL); |
427 | + status = pipeline_run (p); |
428 | + |
429 | + return status; |
430 | +} |
431 | |
432 | === added directory 'examples/webcam-webui-snap' |
433 | === added directory 'examples/webcam-webui-snap/meta' |
434 | === added file 'examples/webcam-webui-snap/meta/package.yaml' |
435 | --- examples/webcam-webui-snap/meta/package.yaml 1970-01-01 00:00:00 +0000 |
436 | +++ examples/webcam-webui-snap/meta/package.yaml 2015-06-30 14:21:21 +0000 |
437 | @@ -0,0 +1,7 @@ |
438 | +name: webcam-webui |
439 | +version: 1.0.0 |
440 | +vendor: Loïc Minier <loic.minier@ubuntu.com> |
441 | +services: |
442 | + - name: webcam-webui |
443 | + start: bin/webcam-webui |
444 | + security-template: unconfined |
445 | |
446 | === added file 'examples/webcam-webui-snap/meta/readme.md' |
447 | --- examples/webcam-webui-snap/meta/readme.md 1970-01-01 00:00:00 +0000 |
448 | +++ examples/webcam-webui-snap/meta/readme.md 2015-06-30 14:21:21 +0000 |
449 | @@ -0,0 +1,3 @@ |
450 | +Webcam web UI |
451 | + |
452 | +Exposes your webcam over a web UI |
453 | |
454 | === added file 'examples/webcam-webui-snap/snapcraft.yaml' |
455 | --- examples/webcam-webui-snap/snapcraft.yaml 1970-01-01 00:00:00 +0000 |
456 | +++ examples/webcam-webui-snap/snapcraft.yaml 2015-06-30 14:21:21 +0000 |
457 | @@ -0,0 +1,6 @@ |
458 | +parts: |
459 | + golang-static-http: |
460 | + plugin: go1.4-project |
461 | + source: git://github.com/mikix/golang-static-http |
462 | +includedPackages: |
463 | + - fswebcam |
464 | |
465 | === added file 'examples/webcam-webui-snap/webcam-webui' |
466 | --- examples/webcam-webui-snap/webcam-webui 1970-01-01 00:00:00 +0000 |
467 | +++ examples/webcam-webui-snap/webcam-webui 2015-06-30 14:21:21 +0000 |
468 | @@ -0,0 +1,16 @@ |
469 | +#!/bin/sh |
470 | + |
471 | +set -e |
472 | + |
473 | +export PATH="${SNAPP_APP_PATH}/bin:${SNAPP_APP_PATH}/usr/bin${PATH:+:$PATH}" |
474 | +export LD_LIBRARY_PATH="${SNAPP_APP_PATH}/lib/x86_64-linux-gnu:${SNAPP_APP_PATH}/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" |
475 | + |
476 | +cd "$SNAPP_APP_DATA_PATH" |
477 | + |
478 | +golang-static-http & |
479 | + |
480 | +while :; do |
481 | + fswebcam shot.jpeg |
482 | + sleep 10 |
483 | +done |
484 | + |
485 | |
486 | === added directory 'examples/wget-deb' |
487 | === added directory 'examples/wget-deb/meta' |
488 | === added file 'examples/wget-deb/meta/package.yaml' |
489 | --- examples/wget-deb/meta/package.yaml 1970-01-01 00:00:00 +0000 |
490 | +++ examples/wget-deb/meta/package.yaml 2015-06-30 14:21:21 +0000 |
491 | @@ -0,0 +1,5 @@ |
492 | +name: wget |
493 | +version: 0 |
494 | +vendor: mterry@ubuntu.com |
495 | +binaries: |
496 | + - name: usr/bin/wget |
497 | |
498 | === added file 'examples/wget-deb/meta/readme.md' |
499 | --- examples/wget-deb/meta/readme.md 1970-01-01 00:00:00 +0000 |
500 | +++ examples/wget-deb/meta/readme.md 2015-06-30 14:21:21 +0000 |
501 | @@ -0,0 +1,1 @@ |
502 | +wget |
503 | |
504 | === added file 'examples/wget-deb/snapcraft.yaml' |
505 | --- examples/wget-deb/snapcraft.yaml 1970-01-01 00:00:00 +0000 |
506 | +++ examples/wget-deb/snapcraft.yaml 2015-06-30 14:21:21 +0000 |
507 | @@ -0,0 +1,4 @@ |
508 | +includedPackages: |
509 | + - wget |
510 | +snap: |
511 | + meta: meta |
512 | |
513 | === added directory 'plugins' |
514 | === added file 'plugins/autotools-project.py' |
515 | --- plugins/autotools-project.py 1970-01-01 00:00:00 +0000 |
516 | +++ plugins/autotools-project.py 2015-06-30 14:21:21 +0000 |
517 | @@ -0,0 +1,32 @@ |
518 | +# -*- Mode:Python; -*- |
519 | + |
520 | +import os |
521 | +import snapcraft |
522 | + |
523 | + |
524 | +class AutotoolsHandler(snapcraft.BaseHandler): |
525 | + |
526 | + def __init__(self, name, options): |
527 | + super().__init__(name, options) |
528 | + if self.options.configflags is None: |
529 | + self.options.configflags = '' |
530 | + |
531 | + def pull(self): |
532 | + return self.pullBranch(self.options.source) |
533 | + |
534 | + def build(self): |
535 | + if not os.path.exists(os.path.join(self.builddir, "configure")): |
536 | + if not self.run("env NOCONFIGURE=1 ./autogen.sh"): |
537 | + return False |
538 | + if not self.run("./configure --prefix= " + self.options.configflags): |
539 | + return False |
540 | + return self.run("make all") |
541 | + |
542 | + def stage(self): |
543 | + return self.run("make install DESTDIR=" + self.stagedir) |
544 | + |
545 | + def snap(self): |
546 | + return self.doDeploy(["bin", "share", "lib"]) # not "include" |
547 | + |
548 | + def test(self): |
549 | + return self.run("make check") |
550 | |
551 | === added file 'plugins/autotools-project.yaml' |
552 | --- plugins/autotools-project.yaml 1970-01-01 00:00:00 +0000 |
553 | +++ plugins/autotools-project.yaml 2015-06-30 14:21:21 +0000 |
554 | @@ -0,0 +1,6 @@ |
555 | +systemPackages: [autoconf, automake, autopoint] |
556 | +options: |
557 | + source: |
558 | + required: true |
559 | + configflags: |
560 | + required: false |
561 | |
562 | === added file 'plugins/go1.4-project.py' |
563 | --- plugins/go1.4-project.py 1970-01-01 00:00:00 +0000 |
564 | +++ plugins/go1.4-project.py 2015-06-30 14:21:21 +0000 |
565 | @@ -0,0 +1,42 @@ |
566 | +# -*- Mode:Python; -*- |
567 | + |
568 | +import os |
569 | +import snapcraft |
570 | + |
571 | + |
572 | +class Go14ProjectHandler(snapcraft.BaseHandler): |
573 | + def __init__(self, name, options): |
574 | + super().__init__(name, options) |
575 | + if self.options.source.startswith("lp:"): |
576 | + self.fullname = self.options.source.split(":~")[1] |
577 | + else: |
578 | + self.fullname = self.options.source.split("://")[1] |
579 | + self.godir = os.path.join( |
580 | + os.path.join(os.getcwd(), "parts", self.name)) |
581 | + try: |
582 | + os.makedirs(self.godir) |
583 | + except FileExistsError: |
584 | + pass |
585 | + |
586 | + def env(self): |
587 | + return [ |
588 | + "GOPATH=%s" % self.godir, |
589 | + ] |
590 | + |
591 | + def pull(self): |
592 | + return self.run("go get -t %s" % (self.fullname), self.godir) |
593 | + |
594 | + def build(self): |
595 | + return self.run("go build %s" % (self.fullname), self.godir) |
596 | + |
597 | + def stage(self): |
598 | + if not self.run("go install %s" % (self.fullname), self.godir): |
599 | + return False |
600 | + return self.run("cp -rf %s %s" % ( |
601 | + os.path.join(self.godir, "bin"), self.stagedir)) |
602 | + |
603 | + def snap(self): |
604 | + return self.doDeploy(["bin"]) |
605 | + |
606 | + def test(self): |
607 | + return self.run("go test %s" % (self.fullname), self.godir) |
608 | |
609 | === added file 'plugins/go1.4-project.yaml' |
610 | --- plugins/go1.4-project.yaml 1970-01-01 00:00:00 +0000 |
611 | +++ plugins/go1.4-project.yaml 2015-06-30 14:21:21 +0000 |
612 | @@ -0,0 +1,7 @@ |
613 | +requires: |
614 | + - go1.4 |
615 | +options: |
616 | + source: |
617 | + required: true |
618 | + configflags: |
619 | + required: false |
620 | |
621 | === added file 'plugins/go1.4.py' |
622 | --- plugins/go1.4.py 1970-01-01 00:00:00 +0000 |
623 | +++ plugins/go1.4.py 2015-06-30 14:21:21 +0000 |
624 | @@ -0,0 +1,44 @@ |
625 | +# -*- Mode:Python; -*- |
626 | + |
627 | +import os |
628 | +import snapcraft |
629 | + |
630 | + |
631 | +# FIXME: add support for i386 |
632 | +URLS = { |
633 | + 'amd64': |
634 | + "https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz", |
635 | +} |
636 | + |
637 | + |
638 | +class Go14Handler(snapcraft.BaseHandler): |
639 | + |
640 | + def __init__(self, name, options): |
641 | + super().__init__(name, options) |
642 | + # FIXME: horrible |
643 | + self.arch = "amd64" |
644 | + self.godir = os.path.join( |
645 | + os.path.join(os.getcwd(), "parts", self.name)) |
646 | + self.goroot = os.path.join(os.path.join( |
647 | + os.getcwd(), "parts", "go1.4", "go")) |
648 | + self.gorootbin = os.path.join(self.goroot, "bin") |
649 | + self.tar_file = os.path.join( |
650 | + self.godir, os.path.basename(URLS[self.arch])) |
651 | + try: |
652 | + os.makedirs(self.godir) |
653 | + except FileExistsError: |
654 | + pass |
655 | + |
656 | + def env(self): |
657 | + return [ |
658 | + "PATH=%s:$PATH" % self.gorootbin, |
659 | + "GOROOT=%s" % self.goroot, |
660 | + ] |
661 | + |
662 | + def pull(self): |
663 | + # FIXME: use the internal downloader (once its there) to get stuff |
664 | + if not self.run("wget -c %s " % URLS[self.arch], cwd=self.godir): |
665 | + return False |
666 | + if not os.path.exists(os.path.join(self.godir, "go/bin/go")): |
667 | + return self.run("tar xf %s" % self.tar_file, cwd=self.godir) |
668 | + return True |
669 | |
670 | === added file 'plugins/go1.4.yaml' |
671 | === added file 'plugins/make-project.py' |
672 | --- plugins/make-project.py 1970-01-01 00:00:00 +0000 |
673 | +++ plugins/make-project.py 2015-06-30 14:21:21 +0000 |
674 | @@ -0,0 +1,21 @@ |
675 | +# -*- Mode:Python; -*- |
676 | + |
677 | +import snapcraft |
678 | + |
679 | + |
680 | +class MakeHandler(snapcraft.BaseHandler): |
681 | + |
682 | + def pull(self): |
683 | + return self.pullBranch(self.options.source) |
684 | + |
685 | + def build(self): |
686 | + return self.run("make all") |
687 | + |
688 | + def stage(self): |
689 | + return self.run("make install DESTDIR=" + self.stagedir) |
690 | + |
691 | + def snap(self): |
692 | + return self.doDeploy(["bin", "share", "lib"]) # not "include" |
693 | + |
694 | + def test(self): |
695 | + return self.run("make check") |
696 | |
697 | === added file 'plugins/make-project.yaml' |
698 | --- plugins/make-project.yaml 1970-01-01 00:00:00 +0000 |
699 | +++ plugins/make-project.yaml 2015-06-30 14:21:21 +0000 |
700 | @@ -0,0 +1,4 @@ |
701 | +systemPackages: [make] |
702 | +options: |
703 | + source: |
704 | + required: true |
705 | |
706 | === added file 'plugins/manifest.txt' |
707 | --- plugins/manifest.txt 1970-01-01 00:00:00 +0000 |
708 | +++ plugins/manifest.txt 2015-06-30 14:21:21 +0000 |
709 | @@ -0,0 +1,97 @@ |
710 | +adduser |
711 | +apt |
712 | +base-files |
713 | +base-passwd |
714 | +bash |
715 | +bsdutils |
716 | +coreutils |
717 | +dash |
718 | +debconf |
719 | +debianutils |
720 | +diffutils |
721 | +dmsetup |
722 | +dpkg |
723 | +e2fslibs |
724 | +e2fsprogs |
725 | +findutils |
726 | +gcc-4.9-base |
727 | +gcc-5-base |
728 | +gnupg |
729 | +gpgv |
730 | +grep |
731 | +gzip |
732 | +hostname |
733 | +init |
734 | +initscripts |
735 | +insserv |
736 | +libacl1 |
737 | +libapparmor1 |
738 | +libapt-pkg4.12 |
739 | +libattr1 |
740 | +libaudit-common |
741 | +libaudit1 |
742 | +libblkid1 |
743 | +libbz2-1.0 |
744 | +libc-bin |
745 | +libc6 |
746 | +libcap2 |
747 | +libcap2-bin |
748 | +libcomerr2 |
749 | +libcryptsetup4 |
750 | +libdb5.3 |
751 | +libdebconfclient0 |
752 | +libdevmapper1.02.1 |
753 | +libgcc1 |
754 | +libgcrypt20 |
755 | +libgpg-error0 |
756 | +libkmod2 |
757 | +liblzma5 |
758 | +libmount1 |
759 | +libncurses5 |
760 | +libncursesw5 |
761 | +libpam-modules |
762 | +libpam-modules-bin |
763 | +libpam-runtime |
764 | +libpam0g |
765 | +libpcre3 |
766 | +libprocps3 |
767 | +libreadline6 |
768 | +libselinux1 |
769 | +libsemanage-common |
770 | +libsemanage1 |
771 | +libsepol1 |
772 | +libslang2 |
773 | +libsmartcols1 |
774 | +libss2 |
775 | +libstdc++6 |
776 | +libsystemd0 |
777 | +libtinfo5 |
778 | +libudev1 |
779 | +libusb-0.1-4 |
780 | +libustr-1.0-1 |
781 | +libuuid1 |
782 | +locales |
783 | +login |
784 | +lsb-base |
785 | +makedev |
786 | +mawk |
787 | +mount |
788 | +multiarch-support |
789 | +ncurses-base |
790 | +ncurses-bin |
791 | +passwd |
792 | +perl-base |
793 | +procps |
794 | +readline-common |
795 | +sed |
796 | +sensible-utils |
797 | +systemd |
798 | +systemd-sysv |
799 | +sysv-rc |
800 | +sysvinit-utils |
801 | +tar |
802 | +tzdata |
803 | +ubuntu-keyring |
804 | +udev |
805 | +util-linux |
806 | +zlib1g |
807 | |
808 | === added file 'plugins/readline.yaml' |
809 | --- plugins/readline.yaml 1970-01-01 00:00:00 +0000 |
810 | +++ plugins/readline.yaml 2015-06-30 14:21:21 +0000 |
811 | @@ -0,0 +1,3 @@ |
812 | +source: git://git.sv.gnu.org/readline.git |
813 | +requires: |
814 | + - autotools-project |
815 | |
816 | === added file 'plugins/snapcraft.py' |
817 | --- plugins/snapcraft.py 1970-01-01 00:00:00 +0000 |
818 | +++ plugins/snapcraft.py 2015-06-30 14:21:21 +0000 |
819 | @@ -0,0 +1,93 @@ |
820 | +# -*- Mode:Python; -*- |
821 | + |
822 | +import apt |
823 | +import os |
824 | +import snapcraft.common |
825 | +import subprocess |
826 | +import sys |
827 | + |
828 | + |
829 | +class SnapcraftHandler(snapcraft.BaseHandler): |
830 | + |
831 | + def __init__(self, name, options): |
832 | + super().__init__(name, options) |
833 | + self.debdir = os.path.join(os.getcwd(), "parts", self.name, "debs") |
834 | + self.downloadablePackages = [] |
835 | + self.includedPackages = options.includedPackages |
836 | + |
837 | + def pull(self): |
838 | + self.downloadablePackages = self.getAllDepPackages( |
839 | + self.includedPackages) |
840 | + return self.downloadDebs(self.downloadablePackages) |
841 | + |
842 | + def stage(self): |
843 | + if not self.downloadablePackages: |
844 | + self.downloadablePackages = self.getAllDepPackages( |
845 | + self.includedPackages) |
846 | + return self.unpackDebs(self.downloadablePackages, self.stagedir) |
847 | + |
848 | + def snap(self): |
849 | + if not self.downloadablePackages: |
850 | + self.downloadablePackages = self.getAllDepPackages( |
851 | + self.includedPackages) |
852 | + return self.unpackDebs(self.downloadablePackages, self.snapdir) |
853 | + |
854 | + def getAllDepPackages(self, packages): |
855 | + cache = apt.Cache() |
856 | + alldeps = set() |
857 | + manifestdeps = set() |
858 | + skipped = set() |
859 | + |
860 | + manif = os.path.abspath(os.path.join(__file__, '..', 'manifest.txt')) |
861 | + with open(manif) as f: |
862 | + for line in f: |
863 | + pkg = line.strip() |
864 | + if pkg in cache: |
865 | + manifestdeps.add(pkg) |
866 | + |
867 | + def addDeps(pkgs): |
868 | + for p in pkgs: |
869 | + if p in alldeps: |
870 | + continue |
871 | + if p in manifestdeps and p not in packages: |
872 | + skipped.add(p) |
873 | + continue |
874 | + try: |
875 | + deps = set() |
876 | + candidatePkg = cache[p].candidate |
877 | + deps = candidatePkg.dependencies + candidatePkg.recommends |
878 | + alldeps.add(p) |
879 | + addDeps([x[0].name for x in deps]) |
880 | + except: |
881 | + pass |
882 | + |
883 | + addDeps(packages) |
884 | + |
885 | + exit = False |
886 | + for p in packages: |
887 | + if p not in alldeps: |
888 | + exit = True |
889 | + snapcraft.common.log( |
890 | + "Package %s not recognized" % p, file=sys.stderr) |
891 | + if exit: |
892 | + sys.exit(1) |
893 | + |
894 | + return sorted(alldeps) |
895 | + |
896 | + def downloadDebs(self, pkgs): |
897 | + try: |
898 | + os.makedirs(self.debdir) |
899 | + except: |
900 | + pass |
901 | + if pkgs: |
902 | + return self.run( |
903 | + ['dget'] + pkgs, cwd=self.debdir, stdout=subprocess.DEVNULL) |
904 | + else: |
905 | + return True |
906 | + |
907 | + def unpackDebs(self, pkgs, targetDir): |
908 | + for p in pkgs: |
909 | + cmd = ['dpkg-deb', '--extract', p + '_*.deb', targetDir] |
910 | + if not self.run(cmd, cwd=self.debdir): |
911 | + return False |
912 | + return True |
913 | |
914 | === added file 'plugins/tgz-content.py' |
915 | --- plugins/tgz-content.py 1970-01-01 00:00:00 +0000 |
916 | +++ plugins/tgz-content.py 2015-06-30 14:21:21 +0000 |
917 | @@ -0,0 +1,16 @@ |
918 | +# -*- Mode:Python; -*- |
919 | + |
920 | +import os |
921 | +import snapcraft |
922 | + |
923 | + |
924 | +class TgzContentHandler(snapcraft.BaseHandler): |
925 | + |
926 | + def __init__(self, name, options): |
927 | + super().__init__(name, options) |
928 | + self.partdir = os.path.join(os.getcwd(), "parts", self.name) |
929 | + |
930 | + def pull(self): |
931 | + self.run("wget -c %s " % self.options.source, cwd=self.partdir) |
932 | + tar_file = os.path.basename(self.partdir) |
933 | + return self.run("tar xf %s" % tar_file, cwd=self.partdir) |
934 | |
935 | === added file 'plugins/tgz-content.yaml' |
936 | --- plugins/tgz-content.yaml 1970-01-01 00:00:00 +0000 |
937 | +++ plugins/tgz-content.yaml 2015-06-30 14:21:21 +0000 |
938 | @@ -0,0 +1,5 @@ |
939 | +# FIXME: this will become part of the language |
940 | +name: tgz-content |
941 | +options: |
942 | + source: |
943 | + required: true |
944 | |
945 | === added file 'run-checks.sh' |
946 | --- run-checks.sh 1970-01-01 00:00:00 +0000 |
947 | +++ run-checks.sh 2015-06-30 14:21:21 +0000 |
948 | @@ -0,0 +1,17 @@ |
949 | +#!/bin/sh |
950 | + |
951 | +set -e |
952 | + |
953 | +# no "py fmt" so we need to make do with reident |
954 | +PYVER="$(python3 -c 'import sys;print(sys.version[0:3])')" |
955 | +PYFMT=/usr/share/doc/python${PYVER}/examples/scripts/reindent.py |
956 | + |
957 | + |
958 | +PY=$(find . -name "*.py" -or -name "snapcraft" -type f) |
959 | +if echo $PY |xargs $PYFMT --verbose | grep "... changed"; then |
960 | + echo "Warning: please commit indent changes" |
961 | + exit 1 |
962 | +fi |
963 | + |
964 | +pyflakes3 $PY |
965 | +pep8 $PY |
966 | |
967 | === added directory 'snapcraft' |
968 | === added file 'snapcraft/__init__.py' |
969 | --- snapcraft/__init__.py 1970-01-01 00:00:00 +0000 |
970 | +++ snapcraft/__init__.py 2015-06-30 14:21:21 +0000 |
971 | @@ -0,0 +1,75 @@ |
972 | +# -*- Mode:Python; -*- |
973 | + |
974 | +import os |
975 | +import snapcraft.common |
976 | + |
977 | + |
978 | +class BaseHandler: |
979 | + |
980 | + def __init__(self, name, options): |
981 | + self.name = name |
982 | + self.options = options |
983 | + self.sourcedir = os.path.join(os.getcwd(), "parts", self.name, "src") |
984 | + self.builddir = os.path.join(os.getcwd(), "parts", self.name, "build") |
985 | + self.stagedir = os.path.join(os.getcwd(), "stage") |
986 | + self.snapdir = os.path.join(os.getcwd(), "snap") |
987 | + |
988 | + # The API |
989 | + def pull(self): |
990 | + return True |
991 | + |
992 | + def build(self): |
993 | + return True |
994 | + |
995 | + def stage(self): |
996 | + return True |
997 | + |
998 | + def snap(self): |
999 | + return True |
1000 | + |
1001 | + def test(self): |
1002 | + return True |
1003 | + |
1004 | + def env(self): |
1005 | + return [] |
1006 | + |
1007 | + # Helpers |
1008 | + def run(self, cmd, cwd=None, **kwargs): |
1009 | + if cwd is None: |
1010 | + cwd = self.builddir |
1011 | + if True: |
1012 | + print(cmd) |
1013 | + return snapcraft.common.run(cmd, cwd=cwd, **kwargs) |
1014 | + |
1015 | + def pullBranch(self, url): |
1016 | + if url.startswith("bzr:") or url.startswith("lp:"): |
1017 | + if os.path.exists(os.path.join(self.sourcedir, ".bzr")): |
1018 | + return self.run("bzr pull " + url, self.sourcedir) |
1019 | + else: |
1020 | + os.rmdir(self.sourcedir) |
1021 | + return self.run("bzr branch " + url + " " + self.sourcedir) |
1022 | + elif url.startswith("git:"): |
1023 | + if os.path.exists(os.path.join(self.sourcedir, ".git")): |
1024 | + return self.run("git pull", self.sourcedir) |
1025 | + else: |
1026 | + return self.run("git clone " + url + " .", self.sourcedir) |
1027 | + else: |
1028 | + raise Exception("Did not recognize branch url: " + url) |
1029 | + |
1030 | + def doDeploy(self, dirs): |
1031 | + try: |
1032 | + os.makedirs(self.snapdir) |
1033 | + except: |
1034 | + pass |
1035 | + |
1036 | + for d in dirs: |
1037 | + if os.path.exists(os.path.join(self.stagedir, d)): |
1038 | + try: |
1039 | + os.makedirs(os.path.join(self.snapdir, d)) |
1040 | + except: |
1041 | + pass |
1042 | + if not self.run( |
1043 | + "cp -rf " + d + " " + self.snapdir + "/", |
1044 | + cwd=self.stagedir): |
1045 | + return False |
1046 | + return True |
1047 | |
1048 | === added file 'snapcraft/common.py' |
1049 | --- snapcraft/common.py 1970-01-01 00:00:00 +0000 |
1050 | +++ snapcraft/common.py 2015-06-30 14:21:21 +0000 |
1051 | @@ -0,0 +1,34 @@ |
1052 | +# -*- Mode:Python; -*- |
1053 | + |
1054 | +# Data/methods shared between plugins and snapcraft |
1055 | + |
1056 | +import os |
1057 | +import subprocess |
1058 | +import tempfile |
1059 | + |
1060 | +env = [] |
1061 | + |
1062 | + |
1063 | +def assembleEnv(): |
1064 | + return '\n'.join(['export ' + e for e in env]) |
1065 | + |
1066 | + |
1067 | +def run(cmd, **kwargs): |
1068 | + # FIXME: This is gross to keep writing this, even when env is the same |
1069 | + if isinstance(cmd, list): |
1070 | + cmd = ' '.join(cmd) |
1071 | + with tempfile.NamedTemporaryFile(mode='w+') as f: |
1072 | + f.write(assembleEnv()) |
1073 | + f.write('\n') |
1074 | + f.write('exec ' + cmd) |
1075 | + f.flush() |
1076 | + return subprocess.call(['/bin/sh', f.name], **kwargs) == 0 |
1077 | + |
1078 | + |
1079 | +def log(msg, file=None): |
1080 | + print('\033[01m' + msg + '\033[0m', file=None) |
1081 | + |
1082 | + |
1083 | +commandOrder = ["pull", "build", "test", "stage", "snap"] |
1084 | +stagedir = os.path.join(os.getcwd(), "stage") |
1085 | +snapdir = os.path.join(os.getcwd(), "snap") |
1086 | |
1087 | === added file 'snapcraft/plugin.py' |
1088 | --- snapcraft/plugin.py 1970-01-01 00:00:00 +0000 |
1089 | +++ snapcraft/plugin.py 2015-06-30 14:21:21 +0000 |
1090 | @@ -0,0 +1,172 @@ |
1091 | +# -*- Mode:Python; -*- |
1092 | + |
1093 | +import importlib.machinery |
1094 | +import os |
1095 | +import snapcraft |
1096 | +import subprocess |
1097 | +import sys |
1098 | +import yaml |
1099 | + |
1100 | + |
1101 | +class Plugin: |
1102 | + |
1103 | + def __init__(self, pluginDir, name, partName, properties, |
1104 | + optionsOverride=None, loadCode=True, loadConfig=True): |
1105 | + self.valid = False |
1106 | + self.code = None |
1107 | + self.config = None |
1108 | + self.partNames = [] |
1109 | + |
1110 | + self.sourcedir = os.path.join(os.getcwd(), "parts", partName, "src") |
1111 | + self.builddir = os.path.join(os.getcwd(), "parts", partName, "build") |
1112 | + self.stagedir = os.path.join(os.getcwd(), "stage") |
1113 | + self.snapdir = os.path.join(os.getcwd(), "snap") |
1114 | + self.statefile = os.path.join(os.getcwd(), "parts", partName, "state") |
1115 | + |
1116 | + if loadConfig: |
1117 | + configPath = os.path.join(pluginDir, name + ".yaml") |
1118 | + if not os.path.exists(configPath): |
1119 | + snapcraft.common.log( |
1120 | + "Missing config for part %s" % (name), file=sys.stderr) |
1121 | + return |
1122 | + self.config = yaml.load(open(configPath, 'r')) or {} |
1123 | + |
1124 | + codePath = os.path.join(pluginDir, name + ".py") |
1125 | + if loadCode and os.path.exists(codePath): |
1126 | + class Options(): |
1127 | + pass |
1128 | + options = Options() |
1129 | + |
1130 | + if self.config: |
1131 | + for opt in self.config.get('options', []): |
1132 | + if opt in properties: |
1133 | + setattr(options, opt, properties[opt]) |
1134 | + else: |
1135 | + if self.config['options'][opt].get('required', False): |
1136 | + snapcraft.common.log( |
1137 | + "Required field %s missing on part %s" % ( |
1138 | + opt, name), file=sys.stderr) |
1139 | + return |
1140 | + setattr(options, opt, None) |
1141 | + if optionsOverride: |
1142 | + options = optionsOverride |
1143 | + |
1144 | + loader = importlib.machinery.SourceFileLoader( |
1145 | + "snapcraft.plugins." + name, codePath) |
1146 | + module = loader.load_module() |
1147 | + for propName in dir(module): |
1148 | + prop = getattr(module, propName) |
1149 | + if issubclass(prop, snapcraft.BaseHandler): |
1150 | + self.code = prop(partName, options) |
1151 | + break |
1152 | + |
1153 | + self.partNames.append(partName) |
1154 | + self.valid = True |
1155 | + |
1156 | + def makedirs(self): |
1157 | + try: |
1158 | + os.makedirs(self.sourcedir) |
1159 | + except: |
1160 | + pass |
1161 | + try: |
1162 | + os.makedirs(self.builddir) |
1163 | + except: |
1164 | + pass |
1165 | + try: |
1166 | + os.makedirs(self.stagedir) |
1167 | + except: |
1168 | + pass |
1169 | + try: |
1170 | + os.makedirs(self.snapdir) |
1171 | + except: |
1172 | + pass |
1173 | + |
1174 | + def isValid(self): |
1175 | + return self.valid |
1176 | + |
1177 | + def names(self): |
1178 | + return self.partNames |
1179 | + |
1180 | + def notifyStage(self, stage, hint=''): |
1181 | + snapcraft.common.log(stage + " " + self.partNames[0] + hint) |
1182 | + |
1183 | + def isDirty(self, stage): |
1184 | + try: |
1185 | + with open(self.statefile, 'r') as f: |
1186 | + lastStep = f.read() |
1187 | + return ( |
1188 | + snapcraft.common.commandOrder.index(stage) > |
1189 | + snapcraft.common.commandOrder.index(lastStep)) |
1190 | + except Exception: |
1191 | + return True |
1192 | + |
1193 | + def shouldStageRun(self, stage, force): |
1194 | + if not force and not self.isDirty(stage): |
1195 | + self.notifyStage('Skipping ' + stage, ' (already ran)') |
1196 | + return False |
1197 | + return True |
1198 | + |
1199 | + def markDone(self, stage): |
1200 | + with open(self.statefile, 'w+') as f: |
1201 | + f.write(stage) |
1202 | + |
1203 | + def pull(self, force=False): |
1204 | + if not self.shouldStageRun('pull', force): |
1205 | + return True |
1206 | + self.makedirs() |
1207 | + if self.code and hasattr(self.code, 'pull'): |
1208 | + self.notifyStage("Pulling") |
1209 | + if not getattr(self.code, 'pull')(): |
1210 | + return False |
1211 | + self.markDone('pull') |
1212 | + return True |
1213 | + |
1214 | + def build(self, force=False): |
1215 | + if not self.shouldStageRun('build', force): |
1216 | + return True |
1217 | + self.makedirs() |
1218 | + subprocess.call(['cp', '-Trf', self.sourcedir, self.builddir]) |
1219 | + if self.code and hasattr(self.code, 'build'): |
1220 | + self.notifyStage("Building") |
1221 | + if not getattr(self.code, 'build')(): |
1222 | + return False |
1223 | + self.markDone('build') |
1224 | + return True |
1225 | + |
1226 | + def test(self, force=False): |
1227 | + if not self.shouldStageRun('test', force): |
1228 | + return True |
1229 | + self.makedirs() |
1230 | + if self.code and hasattr(self.code, 'test'): |
1231 | + self.notifyStage("Testing") |
1232 | + if not getattr(self.code, 'test')(): |
1233 | + return False |
1234 | + self.markDone('test') |
1235 | + return True |
1236 | + |
1237 | + def stage(self, force=False): |
1238 | + if not self.shouldStageRun('stage', force): |
1239 | + return True |
1240 | + self.makedirs() |
1241 | + if self.code and hasattr(self.code, 'stage'): |
1242 | + self.notifyStage("Staging") |
1243 | + if not getattr(self.code, 'stage')(): |
1244 | + return False |
1245 | + self.markDone('stage') |
1246 | + return True |
1247 | + |
1248 | + def snap(self, force=False): |
1249 | + if not self.shouldStageRun('snap', force): |
1250 | + return True |
1251 | + self.makedirs() |
1252 | + if self.code and hasattr(self.code, 'snap'): |
1253 | + self.notifyStage("Snapping") |
1254 | + if not getattr(self.code, 'snap')(): |
1255 | + return False |
1256 | + self.markDone('snap') |
1257 | + return True |
1258 | + |
1259 | + def env(self): |
1260 | + if self.code and hasattr(self.code, 'env'): |
1261 | + return getattr(self.code, 'env')() |
1262 | + return [] |