Merge lp:~sergiusens/snapcraft/1500726 into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Superseded
Proposed branch: lp:~sergiusens/snapcraft/1500726
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 113 lines (+29/-1)
5 files modified
integration-tests/data/simple-tar/snapcraft.yaml (+3/-0)
integration-tests/units/jobs.pxu (+3/-0)
snapcraft/__init__.py (+3/-0)
snapcraft/sources.py (+7/-1)
snapcraft/tests/test_base_plugin.py (+13/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1500726
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+272700@code.launchpad.net

This proposal has been superseded by a proposal from 2015-09-29.

Commit message

Auto detect tar sources

To post a comment you must log in.
lp:~sergiusens/snapcraft/1500726 updated
214. By Sergio Schvezov

Detect tars in sources automatically

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'integration-tests/data/simple-tar/readonly-files.tar.gz'
2Binary files integration-tests/data/simple-tar/readonly-files.tar.gz 1970-01-01 00:00:00 +0000 and integration-tests/data/simple-tar/readonly-files.tar.gz 2015-09-29 08:13:32 +0000 differ
3=== modified file 'integration-tests/data/simple-tar/snapcraft.yaml'
4--- integration-tests/data/simple-tar/snapcraft.yaml 2015-09-08 11:48:30 +0000
5+++ integration-tests/data/simple-tar/snapcraft.yaml 2015-09-29 08:13:32 +0000
6@@ -27,6 +27,9 @@
7 evil-slash:
8 type: tar-content
9 source: evil-slash.tar.gz
10+ readonly-files:
11+ type: tar-content
12+ source: readonly-files.tar.gz
13 project:
14 type: make-project
15 source: project.tar.xz
16
17=== modified file 'integration-tests/units/jobs.pxu'
18--- integration-tests/units/jobs.pxu 2015-09-23 13:42:57 +0000
19+++ integration-tests/units/jobs.pxu 2015-09-29 08:13:32 +0000
20@@ -93,7 +93,10 @@
21 test -e stage/notopdir
22 test -e stage/parent
23 test -e stage/slash
24+ test -e stage/readonly_file
25 test "$(./stage/bin/test)" = "tarproject"
26+ # Regression test for https://bugs.launchpad.net/snapcraft/+bug/1500728
27+ ${SNAPCRAFT} pull --force
28 flags: simple has-leftovers
29
30 id: snapcraft/normal/pypi-config
31
32=== modified file 'snapcraft/__init__.py'
33--- snapcraft/__init__.py 2015-09-23 13:42:57 +0000
34+++ snapcraft/__init__.py 2015-09-29 08:13:32 +0000
35@@ -16,6 +16,7 @@
36
37 import logging
38 import os
39+import re
40
41 import snapcraft.common
42 import snapcraft.sources
43@@ -150,6 +151,8 @@
44 source_type = 'bzr'
45 elif source.startswith("git:"):
46 source_type = 'git'
47+ elif re.compile(r'.*\.((tar\.(xz|gz|bz|bz2)$)|tgz$)').match(source):
48+ source_type = 'tar'
49 elif snapcraft.common.isurl(source):
50 raise ValueError()
51
52
53=== modified file 'snapcraft/sources.py'
54--- snapcraft/sources.py 2015-09-15 05:17:14 +0000
55+++ snapcraft/sources.py 2015-09-29 08:13:32 +0000
56@@ -17,6 +17,7 @@
57 import logging
58 import os
59 import os.path
60+import shutil
61 import tarfile
62 import re
63
64@@ -130,13 +131,17 @@
65 else:
66 return True
67
68- def provision(self, dst):
69+ def provision(self, dst, clean_target=True):
70 # TODO add unit tests.
71 if snapcraft.common.isurl(self.source):
72 tarball = os.path.join(self.source_dir, os.path.basename(self.source))
73 else:
74 tarball = os.path.abspath(self.source)
75
76+ if clean_target:
77+ shutil.rmtree(dst)
78+ os.makedirs(dst)
79+
80 with tarfile.open(tarball) as tar:
81 def filter_members(tar):
82 """Filters members and member names:
83@@ -163,6 +168,7 @@
84 m.name = m.name[len(common + "/"):]
85 # strip leading "/", "./" or "../" as many times as needed
86 m.name = re.sub(r'^(\.{0,2}/)*', r'', m.name)
87+ m.mode = m.mode | 0o222
88 yield m
89
90 tar.extractall(members=filter_members(tar), path=dst)
91
92=== modified file 'snapcraft/tests/test_base_plugin.py'
93--- snapcraft/tests/test_base_plugin.py 2015-08-28 20:26:41 +0000
94+++ snapcraft/tests/test_base_plugin.py 2015-09-29 08:13:32 +0000
95@@ -57,6 +57,19 @@
96 plugin.makedirs(path)
97 self.assertTrue(os.path.exists(path))
98
99+ def test_get_tar_source_from_uri(self):
100+ sources = [
101+ 'https://golang.tar.gz',
102+ 'https://golang.tar.xz',
103+ 'https://golang.tar.bz2',
104+ 'https://golang.tar.tgz',
105+ ]
106+
107+ for source in sources:
108+ with self.subTest(key=source):
109+ self.assertEqual(
110+ snapcraft._get_source_type_from_uri(source), 'tar')
111+
112
113 class GetSourceWithBranches(tests.TestCase):
114

Subscribers

People subscribed via source and target branches