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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Michael Vogt
Approved revision: 209
Merged at revision: 208
Proposed branch: lp:~sergiusens/snapcraft/sources_for_sources
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 75 lines (+27/-6)
1 file modified
snapcraft/repo.py (+27/-6)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/sources_for_sources
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Daniel Holbach (community) Approve
Colin Watson (community) Approve
Review via email: mp+272202@code.launchpad.net

Commit message

Allow using local sources through an env var (mostly useful for launchpad building)

Description of the change

In launchpad, geoip does not work so our code gets stuck. For now we will use whatever the builder is using. We need a longer plan strategy for this one.

This code does work on launchpad: https://code.dogfood.paddev.net/~sergiusens/+snap/irc

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Daniel Holbach (dholbach) wrote :

Good work, just two small comments.

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Michael Vogt (mvo) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'snapcraft/repo.py'
--- snapcraft/repo.py 2015-09-23 14:10:14 +0000
+++ snapcraft/repo.py 2015-09-24 04:07:23 +0000
@@ -63,11 +63,16 @@
63class Ubuntu:63class Ubuntu:
6464
65 def __init__(self, rootdir, recommends=False, sources=_DEFAULT_SOURCES):65 def __init__(self, rootdir, recommends=False, sources=_DEFAULT_SOURCES):
66 sources = sources or _DEFAULT_SOURCES
67 self.downloaddir = os.path.join(rootdir, 'download')66 self.downloaddir = os.path.join(rootdir, 'download')
68 self.rootdir = rootdir67 self.rootdir = rootdir
69 self.apt_cache = _setup_apt_cache(rootdir, sources)
70 self.recommends = recommends68 self.recommends = recommends
69 sources = sources or _DEFAULT_SOURCES
70 local = False
71 if 'SNAPCRAFT_LOCAL_SOURCES' in os.environ:
72 print('using local sources')
73 sources = _get_local_sources_list()
74 local = True
75 self.apt_cache = _setup_apt_cache(rootdir, sources, local)
7176
72 def get(self, package_names):77 def get(self, package_names):
73 os.makedirs(self.downloaddir, exist_ok=True)78 os.makedirs(self.downloaddir, exist_ok=True)
@@ -133,6 +138,18 @@
133 return manifest_dep_names138 return manifest_dep_names
134139
135140
141def _get_local_sources_list():
142 sources_list = glob.glob('/etc/apt/sources.list.d/*.list')
143 sources_list.append('/etc/apt/sources.list')
144
145 sources = ''
146 for source in sources_list:
147 with open(source) as f:
148 sources += f.read()
149
150 return sources
151
152
136def _get_geoip_country_code_prefix():153def _get_geoip_country_code_prefix():
137 try:154 try:
138 with urllib.request.urlopen(_GEOIP_SERVER) as f:155 with urllib.request.urlopen(_GEOIP_SERVER) as f:
@@ -144,12 +161,13 @@
144 return cc.text.lower()161 return cc.text.lower()
145 except (ElementTree.ParseError, urllib.error.URLError):162 except (ElementTree.ParseError, urllib.error.URLError):
146 pass163 pass
147 return ""164 return ''
148165
149166
150def _format_sources_list(sources, arch, release='vivid'):167def _format_sources_list(sources, arch, release='vivid'):
151 if arch in ('amd64', 'i386'):168 if arch in ('amd64', 'i386'):
152 prefix = _get_geoip_country_code_prefix() + '.archive'169 geoip_prefix = _get_geoip_country_code_prefix()
170 prefix = geoip_prefix + '.archive' if geoip_prefix else 'archive'
153 suffix = 'ubuntu'171 suffix = 'ubuntu'
154 security = 'security'172 security = 'security'
155 else:173 else:
@@ -165,12 +183,15 @@
165 })183 })
166184
167185
168def _setup_apt_cache(rootdir, sources):186def _setup_apt_cache(rootdir, sources, local=False):
169 os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)187 os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)
170 srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')188 srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')
171189
190 if not local:
191 sources = _format_sources_list(sources, snapcraft.common.get_arch())
192
172 with open(srcfile, 'w') as f:193 with open(srcfile, 'w') as f:
173 f.write(_format_sources_list(sources, snapcraft.common.get_arch()))194 f.write(sources)
174195
175 progress = apt.progress.text.AcquireProgress()196 progress = apt.progress.text.AcquireProgress()
176 apt_cache = apt.Cache(rootdir=rootdir, memonly=True)197 apt_cache = apt.Cache(rootdir=rootdir, memonly=True)

Subscribers

People subscribed via source and target branches