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
1=== modified file 'snapcraft/repo.py'
2--- snapcraft/repo.py 2015-09-23 14:10:14 +0000
3+++ snapcraft/repo.py 2015-09-24 04:07:23 +0000
4@@ -63,11 +63,16 @@
5 class Ubuntu:
6
7 def __init__(self, rootdir, recommends=False, sources=_DEFAULT_SOURCES):
8- sources = sources or _DEFAULT_SOURCES
9 self.downloaddir = os.path.join(rootdir, 'download')
10 self.rootdir = rootdir
11- self.apt_cache = _setup_apt_cache(rootdir, sources)
12 self.recommends = recommends
13+ sources = sources or _DEFAULT_SOURCES
14+ local = False
15+ if 'SNAPCRAFT_LOCAL_SOURCES' in os.environ:
16+ print('using local sources')
17+ sources = _get_local_sources_list()
18+ local = True
19+ self.apt_cache = _setup_apt_cache(rootdir, sources, local)
20
21 def get(self, package_names):
22 os.makedirs(self.downloaddir, exist_ok=True)
23@@ -133,6 +138,18 @@
24 return manifest_dep_names
25
26
27+def _get_local_sources_list():
28+ sources_list = glob.glob('/etc/apt/sources.list.d/*.list')
29+ sources_list.append('/etc/apt/sources.list')
30+
31+ sources = ''
32+ for source in sources_list:
33+ with open(source) as f:
34+ sources += f.read()
35+
36+ return sources
37+
38+
39 def _get_geoip_country_code_prefix():
40 try:
41 with urllib.request.urlopen(_GEOIP_SERVER) as f:
42@@ -144,12 +161,13 @@
43 return cc.text.lower()
44 except (ElementTree.ParseError, urllib.error.URLError):
45 pass
46- return ""
47+ return ''
48
49
50 def _format_sources_list(sources, arch, release='vivid'):
51 if arch in ('amd64', 'i386'):
52- prefix = _get_geoip_country_code_prefix() + '.archive'
53+ geoip_prefix = _get_geoip_country_code_prefix()
54+ prefix = geoip_prefix + '.archive' if geoip_prefix else 'archive'
55 suffix = 'ubuntu'
56 security = 'security'
57 else:
58@@ -165,12 +183,15 @@
59 })
60
61
62-def _setup_apt_cache(rootdir, sources):
63+def _setup_apt_cache(rootdir, sources, local=False):
64 os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)
65 srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')
66
67+ if not local:
68+ sources = _format_sources_list(sources, snapcraft.common.get_arch())
69+
70 with open(srcfile, 'w') as f:
71- f.write(_format_sources_list(sources, snapcraft.common.get_arch()))
72+ f.write(sources)
73
74 progress = apt.progress.text.AcquireProgress()
75 apt_cache = apt.Cache(rootdir=rootdir, memonly=True)

Subscribers

People subscribed via source and target branches