Merge lp:~bzoltan/click/vivid-transition_mirrors into lp:ubuntu/vivid-proposed/click

Proposed by Zoltan Balogh
Status: Merged
Merge reported by: Michael Vogt
Merged at revision: not available
Proposed branch: lp:~bzoltan/click/vivid-transition_mirrors
Merge into: lp:ubuntu/vivid-proposed/click
Diff against target: 100 lines (+28/-5)
2 files modified
click/chroot.py (+26/-3)
debian/control (+2/-2)
To merge this branch: bzr merge lp:~bzoltan/click/vivid-transition_mirrors
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+246913@code.launchpad.net

Commit message

Transition of locally used mirror servers to the chroots.

Description of the change

Transition of locally used mirror servers to the chroots.

To post a comment you must log in.
Revision history for this message
Zoltan Balogh (bzoltan) wrote :

Some explanation on the MR:

I have chosen to use the local ports and archive mirror because other options seems to be less optimal:

a) There is a way to measure bandwidth to/from the apt's mirror support, but that give a geographically close mirror and not a mirror with a fast access

b) Measuring the bandwidth to mirrors and trying to find the most optimal would need way much more code and would be too complex for a fairly simple problem

I decided to use a strict and limited expression to find the locally used mirror. I accept only the /XX.archive.ubuntu.com $series main/ source line. In case I do not find the mirror the code falls back to the central archive what is a safe choice.

All in all, the job here is to make the Chinese app developer's life easy. I am sure that we can make a more generic and smarter solution to support Ubuntu mirrors, but this one I believe is safe and good enough for now. Also I think it is legit idea to use the same mirror in the chroots what is used on the SDK's host environment.

Revision history for this message
Rex Tsai (chihchun) wrote :

Feedback and summing-up of irc discussion

Ubuntu users are suggested to use [countrycode].archive.ubuntu.com, but most users will select a random mirror server from the software center config (software-properties) or intstaller. http://i.imgur.com/2EvQIrv.png It ends up the user will not have xx.archive.ubuntu.com in /etc/apt/sources.list as reference.

It would make more sense that user can pick a mirror server during the new `click root` setup
1. A dialogue for user to pick which mirror to use. [countrycode].[ports|archive].ubuntu.com
2. The dialogue should suggest the default or preferred mirror server for the user. software-properties use user's locale to guess where is the most close mirror site.

Please note only [countrycode].[ports|archive].ubuntu.com are guarantee up-to-date, the other mirror can delay for few weeks. So we only use [countrycode].[ports|archive].ubuntu.com for phone developer.

66. By Zoltan Balogh

Use the local archive mirror and figure out the ports mirror with geoip lookup

67. By Zoltan Balogh

remove redundant imports

68. By Zoltan Balogh

Use the official archive mirror

69. By Zoltan Balogh

Make it flake8 friendly

70. By Zoltan Balogh

remove unused local_mirror_server

71. By Zoltan Balogh

Handle exception when chroot is created without network and add dependecies

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/chroot.py'
2--- click/chroot.py 2014-11-14 12:29:14 +0000
3+++ click/chroot.py 2015-01-23 16:18:15 +0000
4@@ -26,6 +26,8 @@
5 "ClickChrootDoesNotExistException",
6 ]
7
8+import urllib
9+import urllib.request
10 import os
11 import pwd
12 import re
13@@ -34,6 +36,7 @@
14 import subprocess
15 import sys
16 from textwrap import dedent
17+from xml.etree import ElementTree
18
19
20 framework_base = {
21@@ -215,6 +218,21 @@
22 pass
23
24
25+def get_geoip_country_code_prefix():
26+ GEOIP_SERVER = "http://geoip.ubuntu.com/lookup"
27+ try:
28+ with urllib.request.urlopen(GEOIP_SERVER) as f:
29+ xml_data = f.read()
30+ try:
31+ et = ElementTree.fromstring(xml_data)
32+ return et.find("CountryCode").text.lower()+"."
33+ except ElementTree.ParseError:
34+ pass
35+ except:
36+ pass
37+ return ""
38+
39+
40 class ClickChroot:
41
42 DAEMON_POLICY = dedent("""\
43@@ -247,11 +265,14 @@
44 if chroots_dir is None:
45 chroots_dir = "/var/lib/schroot/chroots"
46 self.chroots_dir = chroots_dir
47+
48+ self.country_code = get_geoip_country_code_prefix()
49 # this doesn't work because we are running this under sudo
50 if 'DEBOOTSTRAP_MIRROR' in os.environ:
51 self.archive = os.environ['DEBOOTSTRAP_MIRROR']
52 else:
53- self.archive = "http://archive.ubuntu.com/ubuntu"
54+ self.archive = "http://%sarchive.ubuntu.com/ubuntu" \
55+ % self.country_code
56 if "SUDO_USER" in os.environ:
57 self.user = os.environ["SUDO_USER"]
58 elif "PKEXEC_UID" in os.environ:
59@@ -331,7 +352,8 @@
60 mount=mount))
61
62 def _generate_sources(self, series, native_arch, target_arch, components):
63- ports_mirror = "http://ports.ubuntu.com/ubuntu-ports"
64+ ports_mirror = "http://%sports.ubuntu.com/ubuntu-ports" \
65+ % self.country_code
66 pockets = ['%s' % series]
67 for pocket in ['updates', 'security']:
68 pockets.append('%s-%s' % (series, pocket))
69@@ -467,7 +489,8 @@
70 proxy = os.environ["http_proxy"]
71 if not proxy:
72 proxy = subprocess.check_output(
73- 'unset x; eval "$(apt-config shell x Acquire::HTTP::Proxy)"; echo "$x"',
74+ 'unset x; eval "$(apt-config shell x Acquire::HTTP::Proxy)"; \
75+ echo "$x"',
76 shell=True, universal_newlines=True).strip()
77 build_pkgs = [
78 "build-essential", "fakeroot",
79
80=== modified file 'debian/control'
81--- debian/control 2014-11-03 12:49:25 +0000
82+++ debian/control 2015-01-23 16:18:15 +0000
83@@ -3,7 +3,7 @@
84 Priority: optional
85 Maintainer: Colin Watson <cjwatson@ubuntu.com>
86 Standards-Version: 3.9.5
87-Build-Depends: debhelper (>= 9~), dh-autoreconf, intltool, python3:any (>= 3.2), python3-all:any, python3-setuptools, python3-apt, python3-debian, python3-gi, python3:any (>= 3.3) | python3-mock, pep8, python3-pep8, pyflakes, python3-sphinx, pkg-config, valac, gobject-introspection (>= 0.6.7), libgirepository1.0-dev (>= 0.6.7), libglib2.0-dev (>= 2.34), gir1.2-glib-2.0, libjson-glib-dev (>= 0.10), libgee-0.8-dev, libpackagekit-glib2-dev (>= 0.7.2), python3-coverage, python3-six, dh-systemd (>= 1.3)
88+Build-Depends: debhelper (>= 9~), dh-autoreconf, intltool, python3:any (>= 3.2), python3-all:any, python3-setuptools, python3-apt, python3-debian, python3-gi, python3:any (>= 3.3) | python3-mock, pep8, python3-pep8, pyflakes, python3-sphinx, pkg-config, valac, gobject-introspection (>= 0.6.7), libgirepository1.0-dev (>= 0.6.7), libglib2.0-dev (>= 2.34), gir1.2-glib-2.0, libjson-glib-dev (>= 0.10), libgee-0.8-dev, libpackagekit-glib2-dev (>= 0.7.2), python3-coverage, python3-six, python3-urllib3, dh-systemd (>= 1.3)
89 Vcs-Bzr: https://code.launchpad.net/~ubuntu-managed-branches/click/click
90 Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-managed-branches/click/click/files
91 X-Auto-Uploader: no-rewrite-version
92@@ -40,7 +40,7 @@
93 Package: python3-click
94 Section: python
95 Architecture: any
96-Depends: ${misc:Depends}, ${python3:Depends}, gir1.2-click-0.4 (= ${binary:Version}), gir1.2-glib-2.0, python3-apt, python3-debian, python3-gi
97+Depends: ${misc:Depends}, ${python3:Depends}, gir1.2-click-0.4 (= ${binary:Version}), gir1.2-glib-2.0, python3-apt, python3-debian, python3-gi, python3-urllib3
98 Conflicts: python3-click-package
99 Replaces: python3-click-package
100 Provides: python3-click-package

Subscribers

People subscribed via source and target branches

to all changes: