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

Proposed by Sergio Schvezov on 2015-09-21
Status: Merged
Approved by: Oliver Grawert on 2015-09-22
Approved revision: 187
Merged at revision: 192
Proposed branch: lp:~sergiusens/snapcraft/1498157
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 152 lines (+76/-16)
2 files modified
snapcraft/repo.py (+35/-16)
snapcraft/tests/test_repo.py (+41/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1498157
Reviewer Review Type Date Requested Status
Oliver Grawert 2015-09-21 Approve on 2015-09-22
Review via email: mp+271872@code.launchpad.net

Commit Message

Enable ports for architectures that are not amd64 or i386

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

tested on the porter box, worked fine

Oliver Grawert (ogra) wrote :

looks good !

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/repo.py'
2--- snapcraft/repo.py 2015-09-21 15:21:15 +0000
3+++ snapcraft/repo.py 2015-09-21 20:46:22 +0000
4@@ -14,6 +14,7 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8+import apt
9 import glob
10 import itertools
11 import os
12@@ -22,18 +23,19 @@
13 import urllib
14 import urllib.request
15
16-import apt
17 from xml.etree import ElementTree
18
19-_DEFAULT_SOURCES = '''deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid main restricted
20-deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid-updates main restricted
21-deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid universe
22-deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid-updates universe
23-deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid multiverse
24-deb http://${mirror}archive.ubuntu.com/ubuntu/ vivid-updates multiverse
25-deb http://security.ubuntu.com/ubuntu vivid-security main restricted
26-deb http://security.ubuntu.com/ubuntu vivid-security universe
27-deb http://security.ubuntu.com/ubuntu vivid-security multiverse
28+import snapcraft.common
29+
30+_DEFAULT_SOURCES = '''deb http://${prefix}.ubuntu.com/${suffix}/ ${release} main restricted
31+deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates main restricted
32+deb http://${prefix}.ubuntu.com/${suffix}/ ${release} universe
33+deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates universe
34+deb http://${prefix}.ubuntu.com/${suffix}/ ${release} multiverse
35+deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates multiverse
36+deb http://${security}.ubuntu.com/${suffix} ${release}-security main restricted
37+deb http://${security}.ubuntu.com/${suffix} ${release}-security universe
38+deb http://${security}.ubuntu.com/${suffix} ${release}-security multiverse
39 '''
40 _GEOIP_SERVER = "http://geoip.ubuntu.com/lookup"
41
42@@ -114,7 +116,7 @@
43 return manifest_dep_names
44
45
46-def get_geoip_country_code_prefix():
47+def _get_geoip_country_code_prefix():
48 try:
49 with urllib.request.urlopen(_GEOIP_SERVER) as f:
50 xml_data = f.read()
51@@ -122,20 +124,37 @@
52 cc = et.find("CountryCode")
53 if cc is None:
54 return ""
55- return cc.text.lower() + "."
56+ return cc.text.lower()
57 except (ElementTree.ParseError, urllib.error.URLError):
58 pass
59 return ""
60
61
62+def _format_sources_list(sources, arch, release='vivid'):
63+ if arch in ('amd64', 'i386'):
64+ prefix = _get_geoip_country_code_prefix() + '.archive'
65+ suffix = 'ubuntu'
66+ security = 'security'
67+ else:
68+ prefix = 'ports'
69+ suffix = 'ubuntu-ports'
70+ security = 'ports'
71+
72+ return string.Template(sources).substitute({
73+ 'prefix': prefix,
74+ 'release': release,
75+ 'suffix': suffix,
76+ 'security': security,
77+ })
78+
79+
80 def _setup_apt_cache(rootdir, sources):
81 os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)
82 srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')
83+
84 with open(srcfile, 'w') as f:
85- mirror_prefix = get_geoip_country_code_prefix()
86- sources_list = string.Template(sources).substitute(
87- {"mirror": mirror_prefix})
88- f.write(sources_list)
89+ f.write(_format_sources_list(sources, snapcraft.common.get_arch()))
90+
91 progress = apt.progress.text.AcquireProgress()
92 apt_cache = apt.Cache(rootdir=rootdir, memonly=True)
93 apt_cache.update(fetch_progress=progress, sources_list=srcfile)
94
95=== modified file 'snapcraft/tests/test_repo.py'
96--- snapcraft/tests/test_repo.py 2015-09-21 15:14:29 +0000
97+++ snapcraft/tests/test_repo.py 2015-09-21 20:46:22 +0000
98@@ -16,6 +16,7 @@
99
100 import os
101 import tempfile
102+import unittest.mock
103
104 from snapcraft import repo
105 from snapcraft import tests
106@@ -23,6 +24,46 @@
107
108 class UbuntuTestCase(tests.TestCase):
109
110+ @unittest.mock.patch('snapcraft.repo._get_geoip_country_code_prefix')
111+ def test_sources_amd64_vivid(self, mock_cc):
112+ mock_cc.return_value = 'ar'
113+
114+ sources_list = repo._format_sources_list(
115+ repo._DEFAULT_SOURCES, 'amd64', 'vivid')
116+
117+ expected_sources_list = '''deb http://ar.archive.ubuntu.com/ubuntu/ vivid main restricted
118+deb http://ar.archive.ubuntu.com/ubuntu/ vivid-updates main restricted
119+deb http://ar.archive.ubuntu.com/ubuntu/ vivid universe
120+deb http://ar.archive.ubuntu.com/ubuntu/ vivid-updates universe
121+deb http://ar.archive.ubuntu.com/ubuntu/ vivid multiverse
122+deb http://ar.archive.ubuntu.com/ubuntu/ vivid-updates multiverse
123+deb http://security.ubuntu.com/ubuntu vivid-security main restricted
124+deb http://security.ubuntu.com/ubuntu vivid-security universe
125+deb http://security.ubuntu.com/ubuntu vivid-security multiverse
126+'''
127+ self.assertEqual(sources_list, expected_sources_list)
128+
129+ @unittest.mock.patch('snapcraft.repo._get_geoip_country_code_prefix')
130+ def test_sources_armhf_trusty(self, mock_cc):
131+ sources_list = repo._format_sources_list(
132+ repo._DEFAULT_SOURCES, 'armhf', 'trusty')
133+
134+ expected_sources_list = '''deb http://ports.ubuntu.com/ubuntu-ports/ trusty main restricted
135+deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main restricted
136+deb http://ports.ubuntu.com/ubuntu-ports/ trusty universe
137+deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates universe
138+deb http://ports.ubuntu.com/ubuntu-ports/ trusty multiverse
139+deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates multiverse
140+deb http://ports.ubuntu.com/ubuntu-ports trusty-security main restricted
141+deb http://ports.ubuntu.com/ubuntu-ports trusty-security universe
142+deb http://ports.ubuntu.com/ubuntu-ports trusty-security multiverse
143+'''
144+ self.assertEqual(sources_list, expected_sources_list)
145+ self.assertFalse(mock_cc.called)
146+
147+ print()
148+ print(sources_list)
149+
150 def test_fix_symlinks(self):
151 tempdirObj = tempfile.TemporaryDirectory()
152 self.addCleanup(tempdirObj.cleanup)

Subscribers

People subscribed via source and target branches