Merge lp:~townsend/libertine/more-refactoring into lp:libertine

Proposed by Christopher Townsend
Status: Merged
Approved by: Larry Price
Approved revision: 262
Merged at revision: 260
Proposed branch: lp:~townsend/libertine/more-refactoring
Merge into: lp:libertine
Diff against target: 580 lines (+130/-203)
9 files modified
debian/python3-libertine.install (+2/-0)
python/libertine/ChrootContainer.py (+26/-72)
python/libertine/ContainersConfig.py (+10/-0)
python/libertine/HostInfo.py (+71/-0)
python/libertine/Libertine.py (+8/-38)
python/libertine/LxcContainer.py (+3/-8)
python/libertine/utils.py (+1/-29)
tools/libertine-container-manager (+8/-53)
tools/libertine-launch (+1/-3)
To merge this branch: bzr merge lp:~townsend/libertine/more-refactoring
Reviewer Review Type Date Requested Status
Larry Price Approve
Libertine CI Bot continuous-integration Approve
Review via email: mp+298465@code.launchpad.net

Commit message

Refactor host information into a new HostInfo class.
Use ContainersConfig class for any places that access the ContainersConfig.json file.
Some other small cleanup.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:259
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/20/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/107
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/74
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/74
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/74
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/74
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/74
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/74
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/87/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/110
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/95
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/95
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/95
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/88/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/88/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/88/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/88/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/88/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/88
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/88/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/20/rebuild

review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

just the 1 inline

review: Needs Information
260. By Christopher Townsend

A bit more refactioring and fixes.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:260
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/22/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/110
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/76
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/76
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/76
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/76
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/76
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/76
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/89/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/113
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/98
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/98
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/98
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/91/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/91/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/91/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/91/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/91/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/91
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/91/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/22/rebuild

review: Approve (continuous-integration)
261. By Christopher Townsend

Remove redundant container_id check as the LibertineContainer.launch_application() mehtod already does that.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:261
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/23/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/111
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/77
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/77
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/77
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/77
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/77
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/77
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/90/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/114
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/99
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/99
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/99
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/92/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/92/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/92/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/92/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/92/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/92
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/92/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/23/rebuild

review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

i got a chroot creation failure when trying to do a simple create on yakkety. no errors in the output except for "Failed to create container".

review: Needs Information
262. By Christopher Townsend

Add missing word in comment.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:262
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/27/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/118
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/83
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/83
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/83
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/83
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/83
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/83
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/96/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/121
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/106
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/106
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/106
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/99/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/99/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/99/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/99/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/99/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/99
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/99/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/27/rebuild

review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

issue with yakkety chroot occurs in archives

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/python3-libertine.install'
2--- debian/python3-libertine.install 2015-12-15 15:46:58 +0000
3+++ debian/python3-libertine.install 2016-06-28 18:52:06 +0000
4@@ -1,4 +1,6 @@
5 usr/lib/python*/*/libertine/AppDiscovery.py
6 usr/lib/python*/*/libertine/Libertine.py
7+usr/lib/python*/*/libertine/ContainersConfig.py
8+usr/lib/python*/*/libertine/HostInfo.py
9 usr/lib/python*/*/libertine/utils.py
10 usr/lib/python*/*/libertine/__init__.py
11
12=== modified file 'python/libertine/ChrootContainer.py'
13--- python/libertine/ChrootContainer.py 2016-06-15 18:10:05 +0000
14+++ python/libertine/ChrootContainer.py 2016-06-28 18:52:06 +0000
15@@ -17,6 +17,7 @@
16 import shlex
17 import shutil
18 import subprocess
19+
20 from .Libertine import BaseContainer
21 from . import utils
22
23@@ -53,10 +54,7 @@
24
25 def run_in_container(self, command_string):
26 cmd_args = shlex.split(command_string)
27- if self.get_container_distro(self.container_id) == "trusty":
28- command_prefix = self._build_privileged_proot_cmd()
29- else:
30- command_prefix = "fakechroot fakeroot chroot " + self.root_path
31+ command_prefix = "fakechroot fakeroot chroot " + self.root_path
32 args = shlex.split(command_prefix + ' ' + command_string)
33 cmd = subprocess.Popen(args)
34 return cmd.wait()
35@@ -66,15 +64,9 @@
36 shutil.rmtree(container_root)
37
38 def create_libertine_container(self, password=None, multiarch=False, verbosity=1):
39- installed_release = self.get_container_distro(self.container_id)
40- architecture = utils.get_host_architecture()
41-
42 # Create the actual chroot
43- if installed_release == "trusty":
44- command_line = "debootstrap --verbose " + installed_release + " " + self.root_path
45- else:
46- command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format(
47- installed_release, self.root_path)
48+ command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format(
49+ self.installed_release, self.root_path)
50 args = shlex.split(command_line)
51 cmd = subprocess.Popen(args)
52 cmd.wait()
53@@ -84,25 +76,24 @@
54 self.destroy_libertine_container()
55 return False
56
57- # Remove symlinks as they can ill-behaved recursive behavior in the chroot
58- if installed_release != "trusty":
59- print("Fixing chroot symlinks...")
60- os.remove(os.path.join(self.root_path, 'dev'))
61- os.remove(os.path.join(self.root_path, 'proc'))
62+ # Remove symlinks as they can cause ill-behaved recursive behavior in the chroot
63+ print("Fixing chroot symlinks...")
64+ os.remove(os.path.join(self.root_path, 'dev'))
65+ os.remove(os.path.join(self.root_path, 'proc'))
66
67- with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd:
68- fd.write("#!/bin/sh\n\n")
69- fd.write("while true; do\n")
70- fd.write("case \"$1\" in\n")
71- fd.write(" -*) shift ;;\n")
72- fd.write(" makedev) exit 0;;\n")
73- fd.write(" *) exit 101;;\n")
74- fd.write("esac\n")
75- fd.write("done\n")
76- os.fchmod(fd.fileno(), 0o755)
77+ with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd:
78+ fd.write("#!/bin/sh\n\n")
79+ fd.write("while true; do\n")
80+ fd.write("case \"$1\" in\n")
81+ fd.write(" -*) shift ;;\n")
82+ fd.write(" makedev) exit 0;;\n")
83+ fd.write(" *) exit 101;;\n")
84+ fd.write("esac\n")
85+ fd.write("done\n")
86+ os.fchmod(fd.fileno(), 0o755)
87
88 # Add universe, multiverse, and -updates to the chroot's sources.list
89- if (utils.get_host_architecture() == 'armhf'):
90+ if (self.architecture == 'armhf'):
91 archive = "deb http://ports.ubuntu.com/ubuntu-ports "
92 else:
93 archive = "deb http://archive.ubuntu.com/ubuntu "
94@@ -110,52 +101,15 @@
95 if verbosity == 1:
96 print("Updating chroot's sources.list entries...")
97 with open(os.path.join(self.root_path, 'etc', 'apt', 'sources.list'), 'a') as fd:
98- fd.write(archive + installed_release + "-updates main\n")
99- fd.write(archive + installed_release + " universe\n")
100- fd.write(archive + installed_release + "-updates universe\n")
101- fd.write(archive + installed_release + " multiverse\n")
102- fd.write(archive + installed_release + "-updates multiverse\n")
103+ fd.write(archive + self.installed_release + "-updates main\n")
104+ fd.write(archive + self.installed_release + " universe\n")
105+ fd.write(archive + self.installed_release + "-updates universe\n")
106+ fd.write(archive + self.installed_release + " multiverse\n")
107+ fd.write(archive + self.installed_release + "-updates multiverse\n")
108
109 utils.create_libertine_user_data_dir(self.container_id)
110
111- if installed_release == "trusty":
112- print("Additional configuration for Trusty chroot...")
113-
114- cmd_line_prefix = self._build_privileged_proot_cmd()
115-
116- command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /etc/init.d/systemd-logind"
117- args = shlex.split(command_line)
118- cmd = subprocess.Popen(args).wait()
119-
120- command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/initctl"
121- args = shlex.split(command_line)
122- cmd = subprocess.Popen(args).wait()
123-
124- command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/udevd"
125- args = shlex.split(command_line)
126- cmd = subprocess.Popen(args).wait()
127-
128- command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /usr/sbin/rsyslogd"
129- args = shlex.split(command_line)
130- cmd = subprocess.Popen(args).wait()
131-
132- command_line = cmd_line_prefix + " ln -s /bin/true /etc/init.d/systemd-logind"
133- args = shlex.split(command_line)
134- cmd = subprocess.Popen(args).wait()
135-
136- command_line = cmd_line_prefix + " ln -s /bin/true /sbin/initctl"
137- args = shlex.split(command_line)
138- cmd = subprocess.Popen(args).wait()
139-
140- command_line = cmd_line_prefix + " ln -s /bin/true /sbin/udevd"
141- args = shlex.split(command_line)
142- cmd = subprocess.Popen(args).wait()
143-
144- command_line = cmd_line_prefix + " ln -s /bin/true /usr/sbin/rsyslogd"
145- args = shlex.split(command_line)
146- cmd = subprocess.Popen(args).wait()
147-
148- if multiarch and architecture == 'amd64':
149+ if multiarch and self.architecture == 'amd64':
150 if verbosity == 1:
151 print("Adding i386 multiarch support...")
152 self.run_in_container("dpkg --add-architecture i386")
153@@ -170,7 +124,7 @@
154 self.destroy_libertine_container()
155 return False
156
157- if installed_release == "vivid":
158+ if self.installed_release == "vivid":
159 if verbosity == 1:
160 print("Installing the Vivid Stable Overlay PPA...")
161 self.run_in_container("add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay -y")
162
163=== modified file 'python/libertine/ContainersConfig.py'
164--- python/libertine/ContainersConfig.py 2016-06-27 17:58:57 +0000
165+++ python/libertine/ContainersConfig.py 2016-06-28 18:52:06 +0000
166@@ -297,3 +297,13 @@
167 def package_exists(self, container_id, package_name):
168 return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName',
169 package_name)
170+
171+ """
172+ Fetcher functions for various configuration information.
173+ """
174+ def get_container_distro(self, container_id):
175+ return self._get_value_by_key(container_id, 'distro')
176+
177+ def get_container_type(self, container_id):
178+ return self._get_value_by_key(container_id, 'type')
179+
180
181=== added file 'python/libertine/HostInfo.py'
182--- python/libertine/HostInfo.py 1970-01-01 00:00:00 +0000
183+++ python/libertine/HostInfo.py 2016-06-28 18:52:06 +0000
184@@ -0,0 +1,71 @@
185+# Copyright 2016 Canonical Ltd.
186+#
187+# This program is free software: you can redistribute it and/or modify it
188+# under the terms of the GNU General Public License version 3, as published
189+# by the Free Software Foundation.
190+#
191+# This program is distributed in the hope that it will be useful, but
192+# WITHOUT ANY WARRANTY; without even the implied warranties of
193+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
194+# PURPOSE. See the GNU General Public License for more details.
195+#
196+# You should have received a copy of the GNU General Public License along
197+# with this program. If not, see <http://www.gnu.org/licenses/>.
198+
199+import lsb_release
200+import platform
201+import subprocess
202+
203+from distro_info import UbuntuDistroInfo
204+
205+
206+class HostInfo(object):
207+
208+ def select_container_type_by_kernel(self):
209+ kernel_release = platform.release().split('.')
210+
211+ if int(kernel_release[0]) >= 4:
212+ return "lxc"
213+ elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13:
214+ return "lxc"
215+ else:
216+ return "chroot"
217+
218+ def get_host_distro_release(self):
219+ distinfo = lsb_release.get_distro_information()
220+
221+ return distinfo.get('CODENAME', 'n/a')
222+
223+ def is_distro_valid(self, distro, force):
224+ if force:
225+ return UbuntuDistroInfo().valid(distro)
226+
227+ if distro == self.get_host_distro_release():
228+ return True
229+
230+ supported_distros = UbuntuDistroInfo().supported()
231+
232+ try:
233+ supported_distros.index(distro)
234+ except ValueError:
235+ return False
236+
237+ return True
238+
239+ def get_distro_codename(self, distro):
240+ ubuntu_distro_info = UbuntuDistroInfo()
241+
242+ for row in ubuntu_distro_info._rows:
243+ if row['series'] == distro:
244+ return row['codename']
245+
246+ return None
247+
248+ def get_host_architecture(self):
249+ dpkg = subprocess.Popen(['dpkg', '--print-architecture'],
250+ stdout=subprocess.PIPE,
251+ universal_newlines=True)
252+ if dpkg.wait() != 0:
253+ parser.error("Failed to determine the local architecture.")
254+
255+ return dpkg.stdout.read().strip()
256
257=== modified file 'python/libertine/Libertine.py'
258--- python/libertine/Libertine.py 2016-06-14 20:05:24 +0000
259+++ python/libertine/Libertine.py 2016-06-28 18:52:06 +0000
260@@ -16,30 +16,12 @@
261 from gi.repository import Libertine
262 import abc
263 import contextlib
264-import json
265 import libertine.utils
266 import os
267 import shutil
268
269-
270-def get_container_type(container_id):
271- """
272- Retrieves the type of container for a given container ID.
273- :param container_id: The Container ID to search for.
274- """
275- try:
276- with open(libertine.utils.get_libertine_database_file_path()) as fd:
277- container_list = json.load(fd)
278-
279- for container in container_list["containerList"]:
280- if container["id"] == container_id:
281- return container["type"]
282-
283- except FileNotFoundError:
284- pass
285-
286- # Return lxc as the default container type
287- return "lxc"
288+from libertine.ContainersConfig import ContainersConfig
289+from libertine.HostInfo import HostInfo
290
291
292 def apt_args_for_verbosity_level(verbosity):
293@@ -207,21 +189,6 @@
294 elif command == 'delete-archive':
295 return self.run_in_container("add-apt-repository -y -r " + args[0])
296
297- def get_container_distro(self, container_id):
298- """
299- Retrieves the distro code name for a given container ID.
300-
301- :param container_id: The Container ID to search for.
302- """
303- with open(libertine.utils.get_libertine_database_file_path()) as fd:
304- container_list = json.load(fd)
305-
306- for container in container_list["containerList"]:
307- if container["id"] == container_id:
308- return container["distro"]
309-
310- return ""
311-
312 @property
313 def name(self):
314 """
315@@ -281,9 +248,9 @@
316 """
317 super().__init__()
318
319- container_type = get_container_type(container_id)
320+ container_type = ContainersConfig().get_container_type(container_id)
321
322- if container_type == "lxc":
323+ if container_type == None or container_type == "lxc":
324 from libertine.LxcContainer import LibertineLXC
325 self.container = LibertineLXC(container_id)
326 elif container_type == "chroot":
327@@ -320,6 +287,9 @@
328 """
329 Creates the container.
330 """
331+ self.container.architecture = HostInfo().get_host_architecture()
332+ self.container.installed_release = ContainersConfig().get_container_distro(self.container_id)
333+
334 return self.container.create_libertine_container(password, multiarch, verbosity)
335
336 def update_libertine_container(self, verbosity=1):
337@@ -380,7 +350,7 @@
338 :param app_exec_line: the application exec line as passed in by
339 ubuntu-app-launch
340 """
341- if libertine.utils.container_exists(self.container.container_id):
342+ if ContainersConfig().container_exists(self.container.container_id):
343 self.container.launch_application(app_exec_line)
344 else:
345 raise RuntimeError("Container with id %s does not exist." % self.container.container_id)
346
347=== modified file 'python/libertine/LxcContainer.py'
348--- python/libertine/LxcContainer.py 2016-06-24 18:04:31 +0000
349+++ python/libertine/LxcContainer.py 2016-06-28 18:52:06 +0000
350@@ -143,8 +143,6 @@
351 if password is None:
352 return False
353
354- installed_release = self.get_container_distro(self.container_id)
355-
356 username = os.environ['USER']
357 user_id = os.getuid()
358 group_id = os.getgid()
359@@ -173,13 +171,10 @@
360
361 utils.create_libertine_user_data_dir(self.container_id)
362
363- # Figure out the host architecture
364- architecture = utils.get_host_architecture()
365-
366 if not self.container.create("download", 0,
367 {"dist": "ubuntu",
368- "release": installed_release,
369- "arch": architecture}):
370+ "release": self.installed_release,
371+ "arch": self.architecture}):
372 print("Failed to create container")
373 return False
374
375@@ -198,7 +193,7 @@
376 self.run_in_container("useradd -u {} -p {} -G sudo {}".format(
377 str(user_id), crypt.crypt(password), str(username)))
378
379- if multiarch and architecture == 'amd64':
380+ if multiarch and self.architecture == 'amd64':
381 if verbosity == 1:
382 print("Adding i386 multiarch support...")
383 self.run_in_container("dpkg --add-architecture i386")
384
385=== modified file 'python/libertine/utils.py'
386--- python/libertine/utils.py 2016-06-23 13:27:26 +0000
387+++ python/libertine/utils.py 2016-06-28 18:52:06 +0000
388@@ -16,9 +16,7 @@
389 # You should have received a copy of the GNU General Public License
390 # along with this program. If not, see <http://www.gnu.org/licenses/>.
391
392-import json
393 import os
394-import psutil
395 import shlex
396 import subprocess
397 import xdg.BaseDirectory as basedir
398@@ -28,22 +26,6 @@
399 from gi.repository import Libertine
400
401
402-def container_exists(container_id):
403- container_config_file_path = get_libertine_database_file_path()
404-
405- if (os.path.exists(container_config_file_path) and
406- os.path.getsize(container_config_file_path) != 0):
407- with open(get_libertine_database_file_path()) as fd:
408- container_list = json.load(fd)
409-
410- if container_list:
411- for container in container_list['containerList']:
412- if container['id'] == container_id:
413- return True
414-
415- return False
416-
417-
418 def get_libertine_container_rootfs_path(container_id):
419 path = Libertine.container_path(container_id)
420
421@@ -97,16 +79,6 @@
422 return os.path.join(get_user_runtime_dir(), 'libertine')
423
424
425-def get_host_architecture():
426- dpkg = subprocess.Popen(['dpkg', '--print-architecture'],
427- stdout=subprocess.PIPE,
428- universal_newlines=True)
429- if dpkg.wait() != 0:
430- parser.error("Failed to determine the local architecture.")
431-
432- return dpkg.stdout.read().strip()
433-
434-
435 def get_common_xdg_directories():
436 return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads']
437
438@@ -167,4 +139,4 @@
439 gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" %
440 (scopes_object_path, invalidate_signal, libertine_scope_id))
441
442- subprocess.Popen(shlex.split(gdbus_cmd))
443+ subprocess.Popen(shlex.split(gdbus_cmd), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
444
445=== modified file 'tools/libertine-container-manager'
446--- tools/libertine-container-manager 2016-06-27 17:58:57 +0000
447+++ tools/libertine-container-manager 2016-06-28 18:52:06 +0000
448@@ -18,71 +18,26 @@
449
450 import argparse
451 import libertine.utils
452-import lsb_release
453 import getpass
454 import os
455-import platform
456 import sys
457
458 from apt.debfile import DebPackage
459-from distro_info import UbuntuDistroInfo
460 from libertine import LibertineContainer
461 from libertine.ContainersConfig import ContainersConfig
462-
463-
464-def select_container_type():
465- kernel_release = platform.release().split('.')
466-
467- if int(kernel_release[0]) >= 4:
468- return "lxc"
469- elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13:
470- return "lxc"
471- else:
472- return "chroot"
473-
474-
475-def get_host_distro_release():
476- distinfo = lsb_release.get_distro_information()
477-
478- return distinfo.get('CODENAME', 'n/a')
479-
480-
481-def is_distro_valid(distro, force):
482- if force:
483- return UbuntuDistroInfo().valid(distro)
484-
485- if distro == get_host_distro_release():
486- return True
487-
488- supported_distros = UbuntuDistroInfo().supported()
489-
490- try:
491- supported_distros.index(distro)
492- except ValueError:
493- return False
494-
495- return True
496-
497-
498-def get_distro_codename(distro):
499- ubuntu_distro_info = UbuntuDistroInfo()
500-
501- for row in ubuntu_distro_info._rows:
502- if row['series'] == distro:
503- return row['codename']
504-
505- return None
506+from libertine.HostInfo import HostInfo
507
508
509 class LibertineContainerManager(object):
510
511 def __init__(self):
512 self.containers_config = ContainersConfig()
513+ self.host_info = HostInfo()
514
515 def create(self, args):
516 password = None
517
518- if args.distro and not is_distro_valid(args.distro, args.force):
519+ if args.distro and not self.host_info.is_distro_valid(args.distro, args.force):
520 print("Invalid distro %s" % args.distro, file=sys.stderr)
521 sys.exit(1)
522
523@@ -93,14 +48,14 @@
524 args.id = get_unique_container_id(distro)
525
526 if not args.type:
527- container_type = select_container_type()
528+ container_type = self.host_info.select_container_type_by_kernel()
529 else:
530 container_type = args.type
531
532 if not args.distro:
533- args.distro = get_host_distro_release()
534+ args.distro = self.host_info.get_host_distro_release()
535 elif container_type == "chroot":
536- host_distro = get_host_distro_release()
537+ host_distro = self.host_info.get_host_distro_release()
538
539 if args.distro != host_distro:
540 print("The container distribution needs to match the host ditribution for chroot"
541@@ -109,7 +64,7 @@
542 sys.exit(1)
543
544 if not args.name:
545- args.name = "Ubuntu \'" + get_distro_codename(args.distro) + "\'"
546+ args.name = "Ubuntu \'" + self.host_info.get_distro_codename(args.distro) + "\'"
547
548 if container_type == "lxc":
549 if args.password:
550@@ -259,7 +214,7 @@
551
552 container = LibertineContainer(container_id)
553
554- if args.multiarch and libertine.utils.get_host_architecture() == 'amd64':
555+ if args.multiarch and self.host_info.get_host_architecture() == 'amd64':
556 multiarch = 'disabled'
557 if args.multiarch == 'enable':
558 multiarch = 'enabled'
559
560=== modified file 'tools/libertine-launch'
561--- tools/libertine-launch 2016-06-24 20:08:12 +0000
562+++ tools/libertine-launch 2016-06-28 18:52:06 +0000
563@@ -24,6 +24,7 @@
564 import psutil
565 import shlex
566 import time
567+
568 from libertine import LibertineContainer
569
570
571@@ -86,9 +87,6 @@
572 help='exec line')
573 args = arg_parser.parse_args()
574
575- if not libertine.utils.container_exists(args.container_id):
576- raise RuntimeError("Container ID %s does not exist." % args.container_id)
577-
578 # remove problematic environment variables
579 for e in ['QT_QPA_PLATFORM', 'LD_LIBRARY_PATH', 'FAKECHROOT_BASE', 'FAKECHROOT_CMD_SUBST']:
580 if e in os.environ:

Subscribers

People subscribed via source and target branches