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
=== modified file 'debian/python3-libertine.install'
--- debian/python3-libertine.install 2015-12-15 15:46:58 +0000
+++ debian/python3-libertine.install 2016-06-28 18:52:06 +0000
@@ -1,4 +1,6 @@
1usr/lib/python*/*/libertine/AppDiscovery.py1usr/lib/python*/*/libertine/AppDiscovery.py
2usr/lib/python*/*/libertine/Libertine.py2usr/lib/python*/*/libertine/Libertine.py
3usr/lib/python*/*/libertine/ContainersConfig.py
4usr/lib/python*/*/libertine/HostInfo.py
3usr/lib/python*/*/libertine/utils.py5usr/lib/python*/*/libertine/utils.py
4usr/lib/python*/*/libertine/__init__.py6usr/lib/python*/*/libertine/__init__.py
57
=== modified file 'python/libertine/ChrootContainer.py'
--- python/libertine/ChrootContainer.py 2016-06-15 18:10:05 +0000
+++ python/libertine/ChrootContainer.py 2016-06-28 18:52:06 +0000
@@ -17,6 +17,7 @@
17import shlex17import shlex
18import shutil18import shutil
19import subprocess19import subprocess
20
20from .Libertine import BaseContainer21from .Libertine import BaseContainer
21from . import utils22from . import utils
2223
@@ -53,10 +54,7 @@
5354
54 def run_in_container(self, command_string):55 def run_in_container(self, command_string):
55 cmd_args = shlex.split(command_string)56 cmd_args = shlex.split(command_string)
56 if self.get_container_distro(self.container_id) == "trusty":57 command_prefix = "fakechroot fakeroot chroot " + self.root_path
57 command_prefix = self._build_privileged_proot_cmd()
58 else:
59 command_prefix = "fakechroot fakeroot chroot " + self.root_path
60 args = shlex.split(command_prefix + ' ' + command_string)58 args = shlex.split(command_prefix + ' ' + command_string)
61 cmd = subprocess.Popen(args)59 cmd = subprocess.Popen(args)
62 return cmd.wait()60 return cmd.wait()
@@ -66,15 +64,9 @@
66 shutil.rmtree(container_root)64 shutil.rmtree(container_root)
6765
68 def create_libertine_container(self, password=None, multiarch=False, verbosity=1):66 def create_libertine_container(self, password=None, multiarch=False, verbosity=1):
69 installed_release = self.get_container_distro(self.container_id)
70 architecture = utils.get_host_architecture()
71
72 # Create the actual chroot67 # Create the actual chroot
73 if installed_release == "trusty":68 command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format(
74 command_line = "debootstrap --verbose " + installed_release + " " + self.root_path69 self.installed_release, self.root_path)
75 else:
76 command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format(
77 installed_release, self.root_path)
78 args = shlex.split(command_line)70 args = shlex.split(command_line)
79 cmd = subprocess.Popen(args)71 cmd = subprocess.Popen(args)
80 cmd.wait()72 cmd.wait()
@@ -84,25 +76,24 @@
84 self.destroy_libertine_container()76 self.destroy_libertine_container()
85 return False77 return False
8678
87 # Remove symlinks as they can ill-behaved recursive behavior in the chroot79 # Remove symlinks as they can cause ill-behaved recursive behavior in the chroot
88 if installed_release != "trusty":80 print("Fixing chroot symlinks...")
89 print("Fixing chroot symlinks...")81 os.remove(os.path.join(self.root_path, 'dev'))
90 os.remove(os.path.join(self.root_path, 'dev'))82 os.remove(os.path.join(self.root_path, 'proc'))
91 os.remove(os.path.join(self.root_path, 'proc'))
9283
93 with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd:84 with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd:
94 fd.write("#!/bin/sh\n\n")85 fd.write("#!/bin/sh\n\n")
95 fd.write("while true; do\n")86 fd.write("while true; do\n")
96 fd.write("case \"$1\" in\n")87 fd.write("case \"$1\" in\n")
97 fd.write(" -*) shift ;;\n")88 fd.write(" -*) shift ;;\n")
98 fd.write(" makedev) exit 0;;\n")89 fd.write(" makedev) exit 0;;\n")
99 fd.write(" *) exit 101;;\n")90 fd.write(" *) exit 101;;\n")
100 fd.write("esac\n")91 fd.write("esac\n")
101 fd.write("done\n")92 fd.write("done\n")
102 os.fchmod(fd.fileno(), 0o755)93 os.fchmod(fd.fileno(), 0o755)
10394
104 # Add universe, multiverse, and -updates to the chroot's sources.list95 # Add universe, multiverse, and -updates to the chroot's sources.list
105 if (utils.get_host_architecture() == 'armhf'):96 if (self.architecture == 'armhf'):
106 archive = "deb http://ports.ubuntu.com/ubuntu-ports "97 archive = "deb http://ports.ubuntu.com/ubuntu-ports "
107 else:98 else:
108 archive = "deb http://archive.ubuntu.com/ubuntu "99 archive = "deb http://archive.ubuntu.com/ubuntu "
@@ -110,52 +101,15 @@
110 if verbosity == 1:101 if verbosity == 1:
111 print("Updating chroot's sources.list entries...")102 print("Updating chroot's sources.list entries...")
112 with open(os.path.join(self.root_path, 'etc', 'apt', 'sources.list'), 'a') as fd:103 with open(os.path.join(self.root_path, 'etc', 'apt', 'sources.list'), 'a') as fd:
113 fd.write(archive + installed_release + "-updates main\n")104 fd.write(archive + self.installed_release + "-updates main\n")
114 fd.write(archive + installed_release + " universe\n")105 fd.write(archive + self.installed_release + " universe\n")
115 fd.write(archive + installed_release + "-updates universe\n")106 fd.write(archive + self.installed_release + "-updates universe\n")
116 fd.write(archive + installed_release + " multiverse\n")107 fd.write(archive + self.installed_release + " multiverse\n")
117 fd.write(archive + installed_release + "-updates multiverse\n")108 fd.write(archive + self.installed_release + "-updates multiverse\n")
118109
119 utils.create_libertine_user_data_dir(self.container_id)110 utils.create_libertine_user_data_dir(self.container_id)
120111
121 if installed_release == "trusty":112 if multiarch and self.architecture == 'amd64':
122 print("Additional configuration for Trusty chroot...")
123
124 cmd_line_prefix = self._build_privileged_proot_cmd()
125
126 command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /etc/init.d/systemd-logind"
127 args = shlex.split(command_line)
128 cmd = subprocess.Popen(args).wait()
129
130 command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/initctl"
131 args = shlex.split(command_line)
132 cmd = subprocess.Popen(args).wait()
133
134 command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/udevd"
135 args = shlex.split(command_line)
136 cmd = subprocess.Popen(args).wait()
137
138 command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /usr/sbin/rsyslogd"
139 args = shlex.split(command_line)
140 cmd = subprocess.Popen(args).wait()
141
142 command_line = cmd_line_prefix + " ln -s /bin/true /etc/init.d/systemd-logind"
143 args = shlex.split(command_line)
144 cmd = subprocess.Popen(args).wait()
145
146 command_line = cmd_line_prefix + " ln -s /bin/true /sbin/initctl"
147 args = shlex.split(command_line)
148 cmd = subprocess.Popen(args).wait()
149
150 command_line = cmd_line_prefix + " ln -s /bin/true /sbin/udevd"
151 args = shlex.split(command_line)
152 cmd = subprocess.Popen(args).wait()
153
154 command_line = cmd_line_prefix + " ln -s /bin/true /usr/sbin/rsyslogd"
155 args = shlex.split(command_line)
156 cmd = subprocess.Popen(args).wait()
157
158 if multiarch and architecture == 'amd64':
159 if verbosity == 1:113 if verbosity == 1:
160 print("Adding i386 multiarch support...")114 print("Adding i386 multiarch support...")
161 self.run_in_container("dpkg --add-architecture i386")115 self.run_in_container("dpkg --add-architecture i386")
@@ -170,7 +124,7 @@
170 self.destroy_libertine_container()124 self.destroy_libertine_container()
171 return False125 return False
172126
173 if installed_release == "vivid":127 if self.installed_release == "vivid":
174 if verbosity == 1:128 if verbosity == 1:
175 print("Installing the Vivid Stable Overlay PPA...")129 print("Installing the Vivid Stable Overlay PPA...")
176 self.run_in_container("add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay -y")130 self.run_in_container("add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay -y")
177131
=== modified file 'python/libertine/ContainersConfig.py'
--- python/libertine/ContainersConfig.py 2016-06-27 17:58:57 +0000
+++ python/libertine/ContainersConfig.py 2016-06-28 18:52:06 +0000
@@ -297,3 +297,13 @@
297 def package_exists(self, container_id, package_name):297 def package_exists(self, container_id, package_name):
298 return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName',298 return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName',
299 package_name)299 package_name)
300
301 """
302 Fetcher functions for various configuration information.
303 """
304 def get_container_distro(self, container_id):
305 return self._get_value_by_key(container_id, 'distro')
306
307 def get_container_type(self, container_id):
308 return self._get_value_by_key(container_id, 'type')
309
300310
=== added file 'python/libertine/HostInfo.py'
--- python/libertine/HostInfo.py 1970-01-01 00:00:00 +0000
+++ python/libertine/HostInfo.py 2016-06-28 18:52:06 +0000
@@ -0,0 +1,71 @@
1# Copyright 2016 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify it
4# under the terms of the GNU General Public License version 3, as published
5# by the Free Software Foundation.
6#
7# This program is distributed in the hope that it will be useful, but
8# WITHOUT ANY WARRANTY; without even the implied warranties of
9# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
10# PURPOSE. See the GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License along
13# with this program. If not, see <http://www.gnu.org/licenses/>.
14
15import lsb_release
16import platform
17import subprocess
18
19from distro_info import UbuntuDistroInfo
20
21
22class HostInfo(object):
23
24 def select_container_type_by_kernel(self):
25 kernel_release = platform.release().split('.')
26
27 if int(kernel_release[0]) >= 4:
28 return "lxc"
29 elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13:
30 return "lxc"
31 else:
32 return "chroot"
33
34 def get_host_distro_release(self):
35 distinfo = lsb_release.get_distro_information()
36
37 return distinfo.get('CODENAME', 'n/a')
38
39 def is_distro_valid(self, distro, force):
40 if force:
41 return UbuntuDistroInfo().valid(distro)
42
43 if distro == self.get_host_distro_release():
44 return True
45
46 supported_distros = UbuntuDistroInfo().supported()
47
48 try:
49 supported_distros.index(distro)
50 except ValueError:
51 return False
52
53 return True
54
55 def get_distro_codename(self, distro):
56 ubuntu_distro_info = UbuntuDistroInfo()
57
58 for row in ubuntu_distro_info._rows:
59 if row['series'] == distro:
60 return row['codename']
61
62 return None
63
64 def get_host_architecture(self):
65 dpkg = subprocess.Popen(['dpkg', '--print-architecture'],
66 stdout=subprocess.PIPE,
67 universal_newlines=True)
68 if dpkg.wait() != 0:
69 parser.error("Failed to determine the local architecture.")
70
71 return dpkg.stdout.read().strip()
072
=== modified file 'python/libertine/Libertine.py'
--- python/libertine/Libertine.py 2016-06-14 20:05:24 +0000
+++ python/libertine/Libertine.py 2016-06-28 18:52:06 +0000
@@ -16,30 +16,12 @@
16from gi.repository import Libertine16from gi.repository import Libertine
17import abc17import abc
18import contextlib18import contextlib
19import json
20import libertine.utils19import libertine.utils
21import os20import os
22import shutil21import shutil
2322
2423from libertine.ContainersConfig import ContainersConfig
25def get_container_type(container_id):24from libertine.HostInfo import HostInfo
26 """
27 Retrieves the type of container for a given container ID.
28 :param container_id: The Container ID to search for.
29 """
30 try:
31 with open(libertine.utils.get_libertine_database_file_path()) as fd:
32 container_list = json.load(fd)
33
34 for container in container_list["containerList"]:
35 if container["id"] == container_id:
36 return container["type"]
37
38 except FileNotFoundError:
39 pass
40
41 # Return lxc as the default container type
42 return "lxc"
4325
4426
45def apt_args_for_verbosity_level(verbosity):27def apt_args_for_verbosity_level(verbosity):
@@ -207,21 +189,6 @@
207 elif command == 'delete-archive':189 elif command == 'delete-archive':
208 return self.run_in_container("add-apt-repository -y -r " + args[0])190 return self.run_in_container("add-apt-repository -y -r " + args[0])
209191
210 def get_container_distro(self, container_id):
211 """
212 Retrieves the distro code name for a given container ID.
213
214 :param container_id: The Container ID to search for.
215 """
216 with open(libertine.utils.get_libertine_database_file_path()) as fd:
217 container_list = json.load(fd)
218
219 for container in container_list["containerList"]:
220 if container["id"] == container_id:
221 return container["distro"]
222
223 return ""
224
225 @property192 @property
226 def name(self):193 def name(self):
227 """194 """
@@ -281,9 +248,9 @@
281 """248 """
282 super().__init__()249 super().__init__()
283250
284 container_type = get_container_type(container_id)251 container_type = ContainersConfig().get_container_type(container_id)
285252
286 if container_type == "lxc":253 if container_type == None or container_type == "lxc":
287 from libertine.LxcContainer import LibertineLXC254 from libertine.LxcContainer import LibertineLXC
288 self.container = LibertineLXC(container_id)255 self.container = LibertineLXC(container_id)
289 elif container_type == "chroot":256 elif container_type == "chroot":
@@ -320,6 +287,9 @@
320 """287 """
321 Creates the container.288 Creates the container.
322 """289 """
290 self.container.architecture = HostInfo().get_host_architecture()
291 self.container.installed_release = ContainersConfig().get_container_distro(self.container_id)
292
323 return self.container.create_libertine_container(password, multiarch, verbosity)293 return self.container.create_libertine_container(password, multiarch, verbosity)
324294
325 def update_libertine_container(self, verbosity=1):295 def update_libertine_container(self, verbosity=1):
@@ -380,7 +350,7 @@
380 :param app_exec_line: the application exec line as passed in by350 :param app_exec_line: the application exec line as passed in by
381 ubuntu-app-launch351 ubuntu-app-launch
382 """352 """
383 if libertine.utils.container_exists(self.container.container_id):353 if ContainersConfig().container_exists(self.container.container_id):
384 self.container.launch_application(app_exec_line)354 self.container.launch_application(app_exec_line)
385 else:355 else:
386 raise RuntimeError("Container with id %s does not exist." % self.container.container_id)356 raise RuntimeError("Container with id %s does not exist." % self.container.container_id)
387357
=== modified file 'python/libertine/LxcContainer.py'
--- python/libertine/LxcContainer.py 2016-06-24 18:04:31 +0000
+++ python/libertine/LxcContainer.py 2016-06-28 18:52:06 +0000
@@ -143,8 +143,6 @@
143 if password is None:143 if password is None:
144 return False144 return False
145145
146 installed_release = self.get_container_distro(self.container_id)
147
148 username = os.environ['USER']146 username = os.environ['USER']
149 user_id = os.getuid()147 user_id = os.getuid()
150 group_id = os.getgid()148 group_id = os.getgid()
@@ -173,13 +171,10 @@
173171
174 utils.create_libertine_user_data_dir(self.container_id)172 utils.create_libertine_user_data_dir(self.container_id)
175173
176 # Figure out the host architecture
177 architecture = utils.get_host_architecture()
178
179 if not self.container.create("download", 0,174 if not self.container.create("download", 0,
180 {"dist": "ubuntu",175 {"dist": "ubuntu",
181 "release": installed_release,176 "release": self.installed_release,
182 "arch": architecture}):177 "arch": self.architecture}):
183 print("Failed to create container")178 print("Failed to create container")
184 return False179 return False
185180
@@ -198,7 +193,7 @@
198 self.run_in_container("useradd -u {} -p {} -G sudo {}".format(193 self.run_in_container("useradd -u {} -p {} -G sudo {}".format(
199 str(user_id), crypt.crypt(password), str(username)))194 str(user_id), crypt.crypt(password), str(username)))
200195
201 if multiarch and architecture == 'amd64':196 if multiarch and self.architecture == 'amd64':
202 if verbosity == 1:197 if verbosity == 1:
203 print("Adding i386 multiarch support...")198 print("Adding i386 multiarch support...")
204 self.run_in_container("dpkg --add-architecture i386")199 self.run_in_container("dpkg --add-architecture i386")
205200
=== modified file 'python/libertine/utils.py'
--- python/libertine/utils.py 2016-06-23 13:27:26 +0000
+++ python/libertine/utils.py 2016-06-28 18:52:06 +0000
@@ -16,9 +16,7 @@
16# You should have received a copy of the GNU General Public License16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
19import json
20import os19import os
21import psutil
22import shlex20import shlex
23import subprocess21import subprocess
24import xdg.BaseDirectory as basedir22import xdg.BaseDirectory as basedir
@@ -28,22 +26,6 @@
28from gi.repository import Libertine26from gi.repository import Libertine
2927
3028
31def container_exists(container_id):
32 container_config_file_path = get_libertine_database_file_path()
33
34 if (os.path.exists(container_config_file_path) and
35 os.path.getsize(container_config_file_path) != 0):
36 with open(get_libertine_database_file_path()) as fd:
37 container_list = json.load(fd)
38
39 if container_list:
40 for container in container_list['containerList']:
41 if container['id'] == container_id:
42 return True
43
44 return False
45
46
47def get_libertine_container_rootfs_path(container_id):29def get_libertine_container_rootfs_path(container_id):
48 path = Libertine.container_path(container_id)30 path = Libertine.container_path(container_id)
4931
@@ -97,16 +79,6 @@
97 return os.path.join(get_user_runtime_dir(), 'libertine')79 return os.path.join(get_user_runtime_dir(), 'libertine')
9880
9981
100def get_host_architecture():
101 dpkg = subprocess.Popen(['dpkg', '--print-architecture'],
102 stdout=subprocess.PIPE,
103 universal_newlines=True)
104 if dpkg.wait() != 0:
105 parser.error("Failed to determine the local architecture.")
106
107 return dpkg.stdout.read().strip()
108
109
110def get_common_xdg_directories():82def get_common_xdg_directories():
111 return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads']83 return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads']
11284
@@ -167,4 +139,4 @@
167 gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" %139 gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" %
168 (scopes_object_path, invalidate_signal, libertine_scope_id))140 (scopes_object_path, invalidate_signal, libertine_scope_id))
169141
170 subprocess.Popen(shlex.split(gdbus_cmd))142 subprocess.Popen(shlex.split(gdbus_cmd), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
171143
=== modified file 'tools/libertine-container-manager'
--- tools/libertine-container-manager 2016-06-27 17:58:57 +0000
+++ tools/libertine-container-manager 2016-06-28 18:52:06 +0000
@@ -18,71 +18,26 @@
1818
19import argparse19import argparse
20import libertine.utils20import libertine.utils
21import lsb_release
22import getpass21import getpass
23import os22import os
24import platform
25import sys23import sys
2624
27from apt.debfile import DebPackage25from apt.debfile import DebPackage
28from distro_info import UbuntuDistroInfo
29from libertine import LibertineContainer26from libertine import LibertineContainer
30from libertine.ContainersConfig import ContainersConfig27from libertine.ContainersConfig import ContainersConfig
3128from libertine.HostInfo import HostInfo
32
33def select_container_type():
34 kernel_release = platform.release().split('.')
35
36 if int(kernel_release[0]) >= 4:
37 return "lxc"
38 elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13:
39 return "lxc"
40 else:
41 return "chroot"
42
43
44def get_host_distro_release():
45 distinfo = lsb_release.get_distro_information()
46
47 return distinfo.get('CODENAME', 'n/a')
48
49
50def is_distro_valid(distro, force):
51 if force:
52 return UbuntuDistroInfo().valid(distro)
53
54 if distro == get_host_distro_release():
55 return True
56
57 supported_distros = UbuntuDistroInfo().supported()
58
59 try:
60 supported_distros.index(distro)
61 except ValueError:
62 return False
63
64 return True
65
66
67def get_distro_codename(distro):
68 ubuntu_distro_info = UbuntuDistroInfo()
69
70 for row in ubuntu_distro_info._rows:
71 if row['series'] == distro:
72 return row['codename']
73
74 return None
7529
7630
77class LibertineContainerManager(object):31class LibertineContainerManager(object):
7832
79 def __init__(self):33 def __init__(self):
80 self.containers_config = ContainersConfig()34 self.containers_config = ContainersConfig()
35 self.host_info = HostInfo()
8136
82 def create(self, args):37 def create(self, args):
83 password = None38 password = None
8439
85 if args.distro and not is_distro_valid(args.distro, args.force):40 if args.distro and not self.host_info.is_distro_valid(args.distro, args.force):
86 print("Invalid distro %s" % args.distro, file=sys.stderr)41 print("Invalid distro %s" % args.distro, file=sys.stderr)
87 sys.exit(1)42 sys.exit(1)
8843
@@ -93,14 +48,14 @@
93 args.id = get_unique_container_id(distro)48 args.id = get_unique_container_id(distro)
9449
95 if not args.type:50 if not args.type:
96 container_type = select_container_type()51 container_type = self.host_info.select_container_type_by_kernel()
97 else:52 else:
98 container_type = args.type53 container_type = args.type
9954
100 if not args.distro:55 if not args.distro:
101 args.distro = get_host_distro_release()56 args.distro = self.host_info.get_host_distro_release()
102 elif container_type == "chroot":57 elif container_type == "chroot":
103 host_distro = get_host_distro_release()58 host_distro = self.host_info.get_host_distro_release()
10459
105 if args.distro != host_distro:60 if args.distro != host_distro:
106 print("The container distribution needs to match the host ditribution for chroot"61 print("The container distribution needs to match the host ditribution for chroot"
@@ -109,7 +64,7 @@
109 sys.exit(1)64 sys.exit(1)
11065
111 if not args.name:66 if not args.name:
112 args.name = "Ubuntu \'" + get_distro_codename(args.distro) + "\'"67 args.name = "Ubuntu \'" + self.host_info.get_distro_codename(args.distro) + "\'"
11368
114 if container_type == "lxc":69 if container_type == "lxc":
115 if args.password:70 if args.password:
@@ -259,7 +214,7 @@
259214
260 container = LibertineContainer(container_id)215 container = LibertineContainer(container_id)
261216
262 if args.multiarch and libertine.utils.get_host_architecture() == 'amd64':217 if args.multiarch and self.host_info.get_host_architecture() == 'amd64':
263 multiarch = 'disabled'218 multiarch = 'disabled'
264 if args.multiarch == 'enable':219 if args.multiarch == 'enable':
265 multiarch = 'enabled'220 multiarch = 'enabled'
266221
=== modified file 'tools/libertine-launch'
--- tools/libertine-launch 2016-06-24 20:08:12 +0000
+++ tools/libertine-launch 2016-06-28 18:52:06 +0000
@@ -24,6 +24,7 @@
24import psutil24import psutil
25import shlex25import shlex
26import time26import time
27
27from libertine import LibertineContainer28from libertine import LibertineContainer
2829
2930
@@ -86,9 +87,6 @@
86 help='exec line')87 help='exec line')
87 args = arg_parser.parse_args()88 args = arg_parser.parse_args()
8889
89 if not libertine.utils.container_exists(args.container_id):
90 raise RuntimeError("Container ID %s does not exist." % args.container_id)
91
92 # remove problematic environment variables90 # remove problematic environment variables
93 for e in ['QT_QPA_PLATFORM', 'LD_LIBRARY_PATH', 'FAKECHROOT_BASE', 'FAKECHROOT_CMD_SUBST']:91 for e in ['QT_QPA_PLATFORM', 'LD_LIBRARY_PATH', 'FAKECHROOT_BASE', 'FAKECHROOT_CMD_SUBST']:
94 if e in os.environ:92 if e in os.environ:

Subscribers

People subscribed via source and target branches