Merge lp:~townsend/libertine/release-1.2.2 into lp:libertine/trunk
- release-1.2.2
- Merge into trunk
Status: | Merged | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Larry Price | ||||||||||||||||||||||||||||
Approved revision: | 139 | ||||||||||||||||||||||||||||
Merged at revision: | 138 | ||||||||||||||||||||||||||||
Proposed branch: | lp:~townsend/libertine/release-1.2.2 | ||||||||||||||||||||||||||||
Merge into: | lp:libertine/trunk | ||||||||||||||||||||||||||||
Diff against target: |
2202 lines (+838/-865) 17 files modified
debian/changelog (+30/-0) debian/python3-libertine.install (+2/-0) debian/rules (+3/-0) libertine/qml/ExtraArchivesView.qml (+3/-6) libertine/qml/GenericErrorDialog.qml (+17/-3) libertine/qml/HomeView.qml (+51/-43) po/CMakeLists.txt (+0/-3) python/libertine/ChrootContainer.py (+26/-72) python/libertine/ContainersConfig.py (+309/-0) python/libertine/HostInfo.py (+71/-0) python/libertine/Libertine.py (+17/-44) python/libertine/LxcContainer.py (+19/-16) python/libertine/utils.py (+1/-29) tests/unit/CMakeLists.txt (+11/-7) tools/libertine-container-manager (+269/-634) tools/libertine-launch (+8/-8) tools/libertine-session-bridge (+1/-0) |
||||||||||||||||||||||||||||
To merge this branch: | bzr merge lp:~townsend/libertine/release-1.2.2 | ||||||||||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Larry Price | Approve | ||
Review via email: mp+299464@code.launchpad.net |
Commit message
* If we fail to find the host path remove the session path since it would have been created with the socket.
* Only set the LXC log file when the container is about to start. (LP: #1596020)
* Add a new ContainersConfig Python class for managing all things ContainersConfi
* Refactor host information into a new HostInfo class.
* Check if the LXC container is defined before trying to start it.
* Remove dependency on DISPLAY variable and use random string to generate session socket path.
* Prevent showing multiple error dialogs when adding archive fails. (LP: #1594957)
* Only generate translations when manually running `make translations`.
* Ensure /usr/games is in PATH before launching applications. (LP: #1598227)
* Make error details selectable and add clipboard button. (LP: #1598786)
* Use dialog instead of ActionSelection
* Verify host kernel has lxc support. (LP: #1599193)
* Set DEBIAN_FRONTEND directly in environment for chroot containers. (LP: #1599246)
Description of the change
- 139. By Christopher Townsend
-
Merged hot fix from lp:libertine.
Fix typo in debian/changelog.
Larry Price (larryprice) wrote : | # |
Alright - lgtm!
Preview Diff
1 | === modified file 'debian/changelog' | |||
2 | --- debian/changelog 2016-06-23 14:01:47 +0000 | |||
3 | +++ debian/changelog 2016-07-07 20:14:07 +0000 | |||
4 | @@ -1,3 +1,33 @@ | |||
5 | 1 | libertine (1.2.2-0ubuntu1) UNRELEASED; urgency=medium | ||
6 | 2 | |||
7 | 3 | [ Brandon Schaefer ] | ||
8 | 4 | * If we fail to find the host path remove the session path since it would | ||
9 | 5 | have been created with the socket. | ||
10 | 6 | |||
11 | 7 | [ Chris Townsend ] | ||
12 | 8 | * Only set the LXC log file when the container is about to start. | ||
13 | 9 | (LP: #1596020) | ||
14 | 10 | * Add a new ContainersConfig Python class for managing all things | ||
15 | 11 | ContainersConfig.json. | ||
16 | 12 | * Refactor host information into a new HostInfo class. | ||
17 | 13 | * Check if the LXC container is defined before trying to start it. | ||
18 | 14 | |||
19 | 15 | [ Larry Price ] | ||
20 | 16 | * Remove dependency on DISPLAY variable and use random string to generate | ||
21 | 17 | session socket path. | ||
22 | 18 | * Prevent showing multiple error dialogs when adding archive fails. | ||
23 | 19 | (LP: #1594957) | ||
24 | 20 | * Only generate translations when manually running `make translations`. | ||
25 | 21 | * Ensure /usr/games is in PATH before launching applications. (LP: #1598227) | ||
26 | 22 | * Make error details selectable and add clipboard button. (LP: #1598786) | ||
27 | 23 | * Use dialog instead of ActionSelectionPopover to address focusing issues | ||
28 | 24 | when installing packages. | ||
29 | 25 | * Verify host kernel has lxc support. (LP: #1599193) | ||
30 | 26 | * Set DEBIAN_FRONTEND directly in environment for chroot containers. | ||
31 | 27 | (LP: #1599246) | ||
32 | 28 | |||
33 | 29 | -- Chris Townsend <christopher.townsend@canonical.com> Thu, 07 Jul 2016 15:08:59 -0400 | ||
34 | 30 | |||
35 | 1 | libertine (1.2.1+16.10.20160623-0ubuntu1) yakkety; urgency=medium | 31 | libertine (1.2.1+16.10.20160623-0ubuntu1) yakkety; urgency=medium |
36 | 2 | 32 | ||
37 | 3 | [ Chris Townsend ] | 33 | [ Chris Townsend ] |
38 | 4 | 34 | ||
39 | === modified file 'debian/python3-libertine.install' | |||
40 | --- debian/python3-libertine.install 2015-12-15 15:46:58 +0000 | |||
41 | +++ debian/python3-libertine.install 2016-07-07 20:14:07 +0000 | |||
42 | @@ -1,4 +1,6 @@ | |||
43 | 1 | usr/lib/python*/*/libertine/AppDiscovery.py | 1 | usr/lib/python*/*/libertine/AppDiscovery.py |
44 | 2 | usr/lib/python*/*/libertine/Libertine.py | 2 | usr/lib/python*/*/libertine/Libertine.py |
45 | 3 | usr/lib/python*/*/libertine/ContainersConfig.py | ||
46 | 4 | usr/lib/python*/*/libertine/HostInfo.py | ||
47 | 3 | usr/lib/python*/*/libertine/utils.py | 5 | usr/lib/python*/*/libertine/utils.py |
48 | 4 | usr/lib/python*/*/libertine/__init__.py | 6 | usr/lib/python*/*/libertine/__init__.py |
49 | 5 | 7 | ||
50 | === modified file 'debian/rules' | |||
51 | --- debian/rules 2016-06-22 19:52:24 +0000 | |||
52 | +++ debian/rules 2016-07-07 20:14:07 +0000 | |||
53 | @@ -2,3 +2,6 @@ | |||
54 | 2 | 2 | ||
55 | 3 | %: | 3 | %: |
56 | 4 | dh $@ --with python3,gir,click | 4 | dh $@ --with python3,gir,click |
57 | 5 | |||
58 | 6 | override_dh_auto_build: | ||
59 | 7 | dh_auto_build -- all translations | ||
60 | 5 | 8 | ||
61 | === modified file 'libertine/qml/ExtraArchivesView.qml' | |||
62 | --- libertine/qml/ExtraArchivesView.qml 2016-05-19 17:56:43 +0000 | |||
63 | +++ libertine/qml/ExtraArchivesView.qml 2016-07-07 20:14:07 +0000 | |||
64 | @@ -126,25 +126,22 @@ | |||
65 | 126 | } | 126 | } |
66 | 127 | 127 | ||
67 | 128 | function addArchive(archive) { | 128 | function addArchive(archive) { |
70 | 129 | var comp = Qt.createComponent("ContainerManager.qml") | 129 | var worker = Qt.createComponent("ContainerManager.qml").createObject(mainView) |
69 | 130 | worker = comp.createObject(mainView) | ||
71 | 131 | worker.finishedConfigure.connect(finishedConfigure) | 130 | worker.finishedConfigure.connect(finishedConfigure) |
72 | 132 | worker.error.connect(sendAddError) | 131 | worker.error.connect(sendAddError) |
73 | 133 | error.connect(mainView.error) | ||
74 | 134 | worker.configureContainer(mainView.currentContainer, containerConfigList.getContainerName(mainView.currentContainer), ["--add-archive", archive]) | 132 | worker.configureContainer(mainView.currentContainer, containerConfigList.getContainerName(mainView.currentContainer), ["--add-archive", archive]) |
75 | 135 | } | 133 | } |
76 | 136 | 134 | ||
77 | 137 | function deleteArchive(archive) { | 135 | function deleteArchive(archive) { |
80 | 138 | var comp = Qt.createComponent("ContainerManager.qml") | 136 | var worker = Qt.createComponent("ContainerManager.qml").createObject(mainView) |
79 | 139 | worker = comp.createObject(mainView) | ||
81 | 140 | worker.finishedConfigure.connect(finishedConfigure) | 137 | worker.finishedConfigure.connect(finishedConfigure) |
82 | 141 | worker.error.connect(sendDeleteError) | 138 | worker.error.connect(sendDeleteError) |
83 | 142 | error.connect(mainView.error) | ||
84 | 143 | worker.configureContainer(mainView.currentContainer, containerConfigList.getContainerName(mainView.currentContainer), ["--delete-archive", archive]) | 139 | worker.configureContainer(mainView.currentContainer, containerConfigList.getContainerName(mainView.currentContainer), ["--delete-archive", archive]) |
85 | 144 | } | 140 | } |
86 | 145 | 141 | ||
87 | 146 | Component.onCompleted: { | 142 | Component.onCompleted: { |
88 | 147 | containerConfigList.configChanged.connect(reloadArchives) | 143 | containerConfigList.configChanged.connect(reloadArchives) |
89 | 144 | error.connect(mainView.error) | ||
90 | 148 | } | 145 | } |
91 | 149 | 146 | ||
92 | 150 | Component.onDestruction: { | 147 | Component.onDestruction: { |
93 | 151 | 148 | ||
94 | === modified file 'libertine/qml/GenericErrorDialog.qml' | |||
95 | --- libertine/qml/GenericErrorDialog.qml 2016-05-10 14:55:15 +0000 | |||
96 | +++ libertine/qml/GenericErrorDialog.qml 2016-07-07 20:14:07 +0000 | |||
97 | @@ -22,11 +22,25 @@ | |||
98 | 22 | 22 | ||
99 | 23 | Dialog { | 23 | Dialog { |
100 | 24 | id: genericErrorDialog | 24 | id: genericErrorDialog |
103 | 25 | property var short_description: null | 25 | property string short_description: "" |
104 | 26 | property var details: null | 26 | property string details: "" |
105 | 27 | 27 | ||
106 | 28 | title: short_description | 28 | title: short_description |
108 | 29 | text: details | 29 | |
109 | 30 | TextEdit { | ||
110 | 31 | color: UbuntuColors.darkGrey | ||
111 | 32 | text: details | ||
112 | 33 | readOnly: true | ||
113 | 34 | selectByMouse: true | ||
114 | 35 | wrapMode: TextEdit.WordWrap | ||
115 | 36 | } | ||
116 | 37 | |||
117 | 38 | Button { | ||
118 | 39 | text: i18n.tr("Copy to Clipboard") | ||
119 | 40 | onClicked: { | ||
120 | 41 | Clipboard.push(details) | ||
121 | 42 | } | ||
122 | 43 | } | ||
123 | 30 | 44 | ||
124 | 31 | Button { | 45 | Button { |
125 | 32 | text: i18n.tr("Dismiss") | 46 | text: i18n.tr("Dismiss") |
126 | 33 | 47 | ||
127 | === modified file 'libertine/qml/HomeView.qml' | |||
128 | --- libertine/qml/HomeView.qml 2016-06-08 21:36:14 +0000 | |||
129 | +++ libertine/qml/HomeView.qml 2016-07-07 20:14:07 +0000 | |||
130 | @@ -31,11 +31,11 @@ | |||
131 | 31 | Action { | 31 | Action { |
132 | 32 | id: settingsButton | 32 | id: settingsButton |
133 | 33 | iconName: "settings" | 33 | iconName: "settings" |
135 | 34 | onTriggered: PopupUtils.open(settingsMenu, homeView) | 34 | onTriggered: PopupUtils.open(settingsMenu) |
136 | 35 | }, | 35 | }, |
137 | 36 | Action { | 36 | Action { |
138 | 37 | iconName: "add" | 37 | iconName: "add" |
140 | 38 | onTriggered: PopupUtils.open(addAppsMenu, homeView) | 38 | onTriggered: PopupUtils.open(addAppsMenu) |
141 | 39 | } | 39 | } |
142 | 40 | ] | 40 | ] |
143 | 41 | } | 41 | } |
144 | @@ -98,26 +98,28 @@ | |||
145 | 98 | 98 | ||
146 | 99 | Component { | 99 | Component { |
147 | 100 | id: settingsMenu | 100 | id: settingsMenu |
168 | 101 | ActionSelectionPopover { | 101 | Dialog { |
169 | 102 | actions: ActionList { | 102 | id: settingsDialog |
170 | 103 | Action { | 103 | __closeOnDismissAreaPress: true |
171 | 104 | text: i18n.tr("Manage Container") | 104 | Button { |
172 | 105 | onTriggered: { | 105 | text: i18n.tr("Manage Container") |
173 | 106 | pageStack.push(Qt.resolvedUrl("ManageContainer.qml"), {currentContainer: currentContainer}) | 106 | onTriggered: { |
174 | 107 | } | 107 | PopupUtils.close(settingsDialog) |
175 | 108 | } | 108 | pageStack.push(Qt.resolvedUrl("ManageContainer.qml"), {currentContainer: currentContainer}) |
176 | 109 | Action { | 109 | } |
177 | 110 | text: i18n.tr("Container Information") | 110 | } |
178 | 111 | onTriggered: { | 111 | Button { |
179 | 112 | pageStack.push(Qt.resolvedUrl("ContainerInfoView.qml"), {currentContainer: currentContainer}) | 112 | text: i18n.tr("Container Information") |
180 | 113 | } | 113 | onTriggered: { |
181 | 114 | } | 114 | PopupUtils.close(settingsDialog) |
182 | 115 | Action { | 115 | pageStack.push(Qt.resolvedUrl("ContainerInfoView.qml"), {currentContainer: currentContainer}) |
183 | 116 | text: i18n.tr("Switch Container") | 116 | } |
184 | 117 | onTriggered: { | 117 | } |
185 | 118 | pageStack.pop() | 118 | Button { |
186 | 119 | pageStack.push(Qt.resolvedUrl("ContainersView.qml")) | 119 | text: i18n.tr("Switch Container") |
187 | 120 | } | 120 | onTriggered: { |
188 | 121 | PopupUtils.close(settingsDialog) | ||
189 | 122 | pageStack.pop() | ||
190 | 121 | } | 123 | } |
191 | 122 | } | 124 | } |
192 | 123 | } | 125 | } |
193 | @@ -125,27 +127,33 @@ | |||
194 | 125 | 127 | ||
195 | 126 | Component { | 128 | Component { |
196 | 127 | id: addAppsMenu | 129 | id: addAppsMenu |
218 | 128 | ActionSelectionPopover { | 130 | Dialog { |
219 | 129 | id: addAppsActions | 131 | id: addAppsDialog |
220 | 130 | actions: ActionList { | 132 | __closeOnDismissAreaPress: true |
221 | 131 | Action { | 133 | |
222 | 132 | text: i18n.tr("Enter package name or Debian file") | 134 | Button { |
223 | 133 | onTriggered: { | 135 | text: i18n.tr("Enter package name or Debian file") |
224 | 134 | PopupUtils.open(enterPackagePopup) | 136 | width: parent.width |
225 | 135 | } | 137 | onClicked: { |
226 | 136 | } | 138 | PopupUtils.close(addAppsDialog) |
227 | 137 | Action { | 139 | PopupUtils.open(enterPackagePopup) |
228 | 138 | text: i18n.tr("Choose Debian package to install") | 140 | } |
229 | 139 | onTriggered: { | 141 | } |
230 | 140 | var packages = containerConfigList.getDebianPackageFiles() | 142 | Button { |
231 | 141 | pageStack.push(Qt.resolvedUrl("DebianPackagePicker.qml"), {packageList: packages}) | 143 | text: i18n.tr("Choose Debian package to install") |
232 | 142 | } | 144 | width: parent.width |
233 | 143 | } | 145 | onClicked: { |
234 | 144 | Action { | 146 | PopupUtils.close(addAppsDialog) |
235 | 145 | text: i18n.tr("Search archives for a package") | 147 | var packages = containerConfigList.getDebianPackageFiles() |
236 | 146 | onTriggered: { | 148 | pageStack.push(Qt.resolvedUrl("DebianPackagePicker.qml"), {packageList: packages}) |
237 | 147 | PopupUtils.open(Qt.resolvedUrl("SearchPackagesDialog.qml")) | 149 | } |
238 | 148 | } | 150 | } |
239 | 151 | Button { | ||
240 | 152 | text: i18n.tr("Search archives for a package") | ||
241 | 153 | width: parent.width | ||
242 | 154 | onClicked: { | ||
243 | 155 | PopupUtils.close(addAppsDialog) | ||
244 | 156 | PopupUtils.open(Qt.resolvedUrl("SearchPackagesDialog.qml")) | ||
245 | 149 | } | 157 | } |
246 | 150 | } | 158 | } |
247 | 151 | } | 159 | } |
248 | 152 | 160 | ||
249 | === modified file 'po/CMakeLists.txt' | |||
250 | --- po/CMakeLists.txt 2016-02-29 18:07:02 +0000 | |||
251 | +++ po/CMakeLists.txt 2016-07-07 20:14:07 +0000 | |||
252 | @@ -1,7 +1,6 @@ | |||
253 | 1 | set (GETTEXT_PACKAGE "libertine") | 1 | set (GETTEXT_PACKAGE "libertine") |
254 | 2 | 2 | ||
255 | 3 | intltool_update_potfile( | 3 | intltool_update_potfile( |
256 | 4 | ALL | ||
257 | 5 | UBUNTU_SDK_DEFAULTS | 4 | UBUNTU_SDK_DEFAULTS |
258 | 6 | POTFILES_TEMPLATE POTFILES.in.in | 5 | POTFILES_TEMPLATE POTFILES.in.in |
259 | 7 | COPYRIGHT_HOLDER "Canonical Ltd." | 6 | COPYRIGHT_HOLDER "Canonical Ltd." |
260 | @@ -9,14 +8,12 @@ | |||
261 | 9 | ) | 8 | ) |
262 | 10 | 9 | ||
263 | 11 | intltool_install_translations( | 10 | intltool_install_translations( |
264 | 12 | ALL | ||
265 | 13 | GETTEXT_PACKAGE ${GETTEXT_PACKAGE} | 11 | GETTEXT_PACKAGE ${GETTEXT_PACKAGE} |
266 | 14 | ) | 12 | ) |
267 | 15 | 13 | ||
268 | 16 | file(GLOB_RECURSE ALL_POFILES "*.po") | 14 | file(GLOB_RECURSE ALL_POFILES "*.po") |
269 | 17 | 15 | ||
270 | 18 | add_custom_target(potfiles | 16 | add_custom_target(potfiles |
271 | 19 | ALL | ||
272 | 20 | SOURCES | 17 | SOURCES |
273 | 21 | POTFILES.in.in | 18 | POTFILES.in.in |
274 | 22 | ${GETTEXT_PACKAGE}.pot | 19 | ${GETTEXT_PACKAGE}.pot |
275 | 23 | 20 | ||
276 | === modified file 'python/libertine/ChrootContainer.py' | |||
277 | --- python/libertine/ChrootContainer.py 2016-06-15 18:10:05 +0000 | |||
278 | +++ python/libertine/ChrootContainer.py 2016-07-07 20:14:07 +0000 | |||
279 | @@ -17,6 +17,7 @@ | |||
280 | 17 | import shlex | 17 | import shlex |
281 | 18 | import shutil | 18 | import shutil |
282 | 19 | import subprocess | 19 | import subprocess |
283 | 20 | |||
284 | 20 | from .Libertine import BaseContainer | 21 | from .Libertine import BaseContainer |
285 | 21 | from . import utils | 22 | from . import utils |
286 | 22 | 23 | ||
287 | @@ -53,10 +54,7 @@ | |||
288 | 53 | 54 | ||
289 | 54 | def run_in_container(self, command_string): | 55 | def run_in_container(self, command_string): |
290 | 55 | cmd_args = shlex.split(command_string) | 56 | cmd_args = shlex.split(command_string) |
295 | 56 | if self.get_container_distro(self.container_id) == "trusty": | 57 | command_prefix = "fakechroot fakeroot chroot " + self.root_path |
292 | 57 | command_prefix = self._build_privileged_proot_cmd() | ||
293 | 58 | else: | ||
294 | 59 | command_prefix = "fakechroot fakeroot chroot " + self.root_path | ||
296 | 60 | args = shlex.split(command_prefix + ' ' + command_string) | 58 | args = shlex.split(command_prefix + ' ' + command_string) |
297 | 61 | cmd = subprocess.Popen(args) | 59 | cmd = subprocess.Popen(args) |
298 | 62 | return cmd.wait() | 60 | return cmd.wait() |
299 | @@ -66,15 +64,9 @@ | |||
300 | 66 | shutil.rmtree(container_root) | 64 | shutil.rmtree(container_root) |
301 | 67 | 65 | ||
302 | 68 | def create_libertine_container(self, password=None, multiarch=False, verbosity=1): | 66 | def create_libertine_container(self, password=None, multiarch=False, verbosity=1): |
303 | 69 | installed_release = self.get_container_distro(self.container_id) | ||
304 | 70 | architecture = utils.get_host_architecture() | ||
305 | 71 | |||
306 | 72 | # Create the actual chroot | 67 | # Create the actual chroot |
312 | 73 | if installed_release == "trusty": | 68 | command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format( |
313 | 74 | command_line = "debootstrap --verbose " + installed_release + " " + self.root_path | 69 | self.installed_release, self.root_path) |
309 | 75 | else: | ||
310 | 76 | command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format( | ||
311 | 77 | installed_release, self.root_path) | ||
314 | 78 | args = shlex.split(command_line) | 70 | args = shlex.split(command_line) |
315 | 79 | cmd = subprocess.Popen(args) | 71 | cmd = subprocess.Popen(args) |
316 | 80 | cmd.wait() | 72 | cmd.wait() |
317 | @@ -84,25 +76,24 @@ | |||
318 | 84 | self.destroy_libertine_container() | 76 | self.destroy_libertine_container() |
319 | 85 | return False | 77 | return False |
320 | 86 | 78 | ||
326 | 87 | # Remove symlinks as they can ill-behaved recursive behavior in the chroot | 79 | # Remove symlinks as they can cause ill-behaved recursive behavior in the chroot |
327 | 88 | if installed_release != "trusty": | 80 | print("Fixing chroot symlinks...") |
328 | 89 | print("Fixing chroot symlinks...") | 81 | os.remove(os.path.join(self.root_path, 'dev')) |
329 | 90 | os.remove(os.path.join(self.root_path, 'dev')) | 82 | os.remove(os.path.join(self.root_path, 'proc')) |
325 | 91 | os.remove(os.path.join(self.root_path, 'proc')) | ||
330 | 92 | 83 | ||
341 | 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: |
342 | 94 | fd.write("#!/bin/sh\n\n") | 85 | fd.write("#!/bin/sh\n\n") |
343 | 95 | fd.write("while true; do\n") | 86 | fd.write("while true; do\n") |
344 | 96 | fd.write("case \"$1\" in\n") | 87 | fd.write("case \"$1\" in\n") |
345 | 97 | fd.write(" -*) shift ;;\n") | 88 | fd.write(" -*) shift ;;\n") |
346 | 98 | fd.write(" makedev) exit 0;;\n") | 89 | fd.write(" makedev) exit 0;;\n") |
347 | 99 | fd.write(" *) exit 101;;\n") | 90 | fd.write(" *) exit 101;;\n") |
348 | 100 | fd.write("esac\n") | 91 | fd.write("esac\n") |
349 | 101 | fd.write("done\n") | 92 | fd.write("done\n") |
350 | 102 | os.fchmod(fd.fileno(), 0o755) | 93 | os.fchmod(fd.fileno(), 0o755) |
351 | 103 | 94 | ||
352 | 104 | # Add universe, multiverse, and -updates to the chroot's sources.list | 95 | # Add universe, multiverse, and -updates to the chroot's sources.list |
354 | 105 | if (utils.get_host_architecture() == 'armhf'): | 96 | if (self.architecture == 'armhf'): |
355 | 106 | archive = "deb http://ports.ubuntu.com/ubuntu-ports " | 97 | archive = "deb http://ports.ubuntu.com/ubuntu-ports " |
356 | 107 | else: | 98 | else: |
357 | 108 | archive = "deb http://archive.ubuntu.com/ubuntu " | 99 | archive = "deb http://archive.ubuntu.com/ubuntu " |
358 | @@ -110,52 +101,15 @@ | |||
359 | 110 | if verbosity == 1: | 101 | if verbosity == 1: |
360 | 111 | print("Updating chroot's sources.list entries...") | 102 | print("Updating chroot's sources.list entries...") |
361 | 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: |
367 | 113 | fd.write(archive + installed_release + "-updates main\n") | 104 | fd.write(archive + self.installed_release + "-updates main\n") |
368 | 114 | fd.write(archive + installed_release + " universe\n") | 105 | fd.write(archive + self.installed_release + " universe\n") |
369 | 115 | fd.write(archive + installed_release + "-updates universe\n") | 106 | fd.write(archive + self.installed_release + "-updates universe\n") |
370 | 116 | fd.write(archive + installed_release + " multiverse\n") | 107 | fd.write(archive + self.installed_release + " multiverse\n") |
371 | 117 | fd.write(archive + installed_release + "-updates multiverse\n") | 108 | fd.write(archive + self.installed_release + "-updates multiverse\n") |
372 | 118 | 109 | ||
373 | 119 | utils.create_libertine_user_data_dir(self.container_id) | 110 | utils.create_libertine_user_data_dir(self.container_id) |
374 | 120 | 111 | ||
413 | 121 | if installed_release == "trusty": | 112 | if multiarch and self.architecture == 'amd64': |
376 | 122 | print("Additional configuration for Trusty chroot...") | ||
377 | 123 | |||
378 | 124 | cmd_line_prefix = self._build_privileged_proot_cmd() | ||
379 | 125 | |||
380 | 126 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /etc/init.d/systemd-logind" | ||
381 | 127 | args = shlex.split(command_line) | ||
382 | 128 | cmd = subprocess.Popen(args).wait() | ||
383 | 129 | |||
384 | 130 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/initctl" | ||
385 | 131 | args = shlex.split(command_line) | ||
386 | 132 | cmd = subprocess.Popen(args).wait() | ||
387 | 133 | |||
388 | 134 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/udevd" | ||
389 | 135 | args = shlex.split(command_line) | ||
390 | 136 | cmd = subprocess.Popen(args).wait() | ||
391 | 137 | |||
392 | 138 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /usr/sbin/rsyslogd" | ||
393 | 139 | args = shlex.split(command_line) | ||
394 | 140 | cmd = subprocess.Popen(args).wait() | ||
395 | 141 | |||
396 | 142 | command_line = cmd_line_prefix + " ln -s /bin/true /etc/init.d/systemd-logind" | ||
397 | 143 | args = shlex.split(command_line) | ||
398 | 144 | cmd = subprocess.Popen(args).wait() | ||
399 | 145 | |||
400 | 146 | command_line = cmd_line_prefix + " ln -s /bin/true /sbin/initctl" | ||
401 | 147 | args = shlex.split(command_line) | ||
402 | 148 | cmd = subprocess.Popen(args).wait() | ||
403 | 149 | |||
404 | 150 | command_line = cmd_line_prefix + " ln -s /bin/true /sbin/udevd" | ||
405 | 151 | args = shlex.split(command_line) | ||
406 | 152 | cmd = subprocess.Popen(args).wait() | ||
407 | 153 | |||
408 | 154 | command_line = cmd_line_prefix + " ln -s /bin/true /usr/sbin/rsyslogd" | ||
409 | 155 | args = shlex.split(command_line) | ||
410 | 156 | cmd = subprocess.Popen(args).wait() | ||
411 | 157 | |||
412 | 158 | if multiarch and architecture == 'amd64': | ||
414 | 159 | if verbosity == 1: | 113 | if verbosity == 1: |
415 | 160 | print("Adding i386 multiarch support...") | 114 | print("Adding i386 multiarch support...") |
416 | 161 | self.run_in_container("dpkg --add-architecture i386") | 115 | self.run_in_container("dpkg --add-architecture i386") |
417 | @@ -170,7 +124,7 @@ | |||
418 | 170 | self.destroy_libertine_container() | 124 | self.destroy_libertine_container() |
419 | 171 | return False | 125 | return False |
420 | 172 | 126 | ||
422 | 173 | if installed_release == "vivid": | 127 | if self.installed_release == "vivid": |
423 | 174 | if verbosity == 1: | 128 | if verbosity == 1: |
424 | 175 | print("Installing the Vivid Stable Overlay PPA...") | 129 | print("Installing the Vivid Stable Overlay PPA...") |
425 | 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") |
426 | 177 | 131 | ||
427 | === added file 'python/libertine/ContainersConfig.py' | |||
428 | --- python/libertine/ContainersConfig.py 1970-01-01 00:00:00 +0000 | |||
429 | +++ python/libertine/ContainersConfig.py 2016-07-07 20:14:07 +0000 | |||
430 | @@ -0,0 +1,309 @@ | |||
431 | 1 | # Copyright 2016 Canonical Ltd. | ||
432 | 2 | # | ||
433 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
434 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
435 | 5 | # by the Free Software Foundation. | ||
436 | 6 | # | ||
437 | 7 | # This program is distributed in the hope that it will be useful, but | ||
438 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
439 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
440 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
441 | 11 | # | ||
442 | 12 | # You should have received a copy of the GNU General Public License along | ||
443 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
444 | 14 | |||
445 | 15 | import fcntl | ||
446 | 16 | import json | ||
447 | 17 | import libertine.utils | ||
448 | 18 | import os | ||
449 | 19 | import sys | ||
450 | 20 | |||
451 | 21 | |||
452 | 22 | def read_container_config_file(): | ||
453 | 23 | container_list = {} | ||
454 | 24 | container_config_file = libertine.utils.get_libertine_database_file_path() | ||
455 | 25 | |||
456 | 26 | if (os.path.exists(container_config_file) and | ||
457 | 27 | os.path.getsize(container_config_file) != 0): | ||
458 | 28 | with open(container_config_file, 'r') as fd: | ||
459 | 29 | container_list = json.load(fd) | ||
460 | 30 | |||
461 | 31 | return container_list | ||
462 | 32 | |||
463 | 33 | |||
464 | 34 | def write_container_config_file(container_list): | ||
465 | 35 | container_config_file = libertine.utils.get_libertine_database_file_path() | ||
466 | 36 | |||
467 | 37 | with open(container_config_file, 'w') as fd: | ||
468 | 38 | fcntl.lockf(fd, fcntl.LOCK_EX) | ||
469 | 39 | json.dump(container_list, fd, sort_keys=True, indent=4) | ||
470 | 40 | fd.write('\n') | ||
471 | 41 | fcntl.lockf(fd, fcntl.LOCK_UN) | ||
472 | 42 | |||
473 | 43 | |||
474 | 44 | class ContainersConfig(object): | ||
475 | 45 | |||
476 | 46 | def __init__(self): | ||
477 | 47 | self.container_list = read_container_config_file() | ||
478 | 48 | |||
479 | 49 | if "defaultContainer" in self.container_list: | ||
480 | 50 | self.default_container_id = self.container_list['defaultContainer'] | ||
481 | 51 | else: | ||
482 | 52 | self.default_container_id = None | ||
483 | 53 | |||
484 | 54 | """ | ||
485 | 55 | Private helper methods | ||
486 | 56 | """ | ||
487 | 57 | def _get_container_entry(self, container_id): | ||
488 | 58 | if not self.container_list: | ||
489 | 59 | return None | ||
490 | 60 | |||
491 | 61 | for container in self.container_list['containerList']: | ||
492 | 62 | if container['id'] == container_id: | ||
493 | 63 | return container | ||
494 | 64 | |||
495 | 65 | return None | ||
496 | 66 | |||
497 | 67 | def _get_value_by_key(self, container_id, key): | ||
498 | 68 | container = self._get_container_entry(container_id) | ||
499 | 69 | |||
500 | 70 | if not container or key not in container: | ||
501 | 71 | return None | ||
502 | 72 | else: | ||
503 | 73 | return container[key] | ||
504 | 74 | |||
505 | 75 | def _get_array_object_value_by_key(self, container_id, array_key, object_key, matcher, key): | ||
506 | 76 | for item in self._get_value_by_key(container_id, array_key): | ||
507 | 77 | if item[object_key] == matcher: | ||
508 | 78 | return item[key] | ||
509 | 79 | |||
510 | 80 | def _set_value_by_key(self, container_id, key, value): | ||
511 | 81 | container = self._get_container_entry(container_id) | ||
512 | 82 | |||
513 | 83 | if not container: | ||
514 | 84 | return | ||
515 | 85 | |||
516 | 86 | if type(value) is str: | ||
517 | 87 | container[key] = value | ||
518 | 88 | elif type(value) is dict: | ||
519 | 89 | if key not in container: | ||
520 | 90 | container[key] = [value] | ||
521 | 91 | else: | ||
522 | 92 | container[key].append(value) | ||
523 | 93 | |||
524 | 94 | write_container_config_file(self.container_list) | ||
525 | 95 | |||
526 | 96 | def _set_array_object_value_by_key(self, container_id, array_key, object_key, matcher, key, value): | ||
527 | 97 | container = self._get_container_entry(container_id) | ||
528 | 98 | |||
529 | 99 | if not container: | ||
530 | 100 | return | ||
531 | 101 | |||
532 | 102 | for item in container[array_key]: | ||
533 | 103 | if item[object_key] == matcher: | ||
534 | 104 | item[key] = value | ||
535 | 105 | write_container_config_file(self.container_list) | ||
536 | 106 | return | ||
537 | 107 | |||
538 | 108 | def _delete_array_object_by_key_value(self, container_id, array_key, object_key, value): | ||
539 | 109 | container = self._get_container_entry(container_id) | ||
540 | 110 | |||
541 | 111 | if not container: | ||
542 | 112 | return | ||
543 | 113 | |||
544 | 114 | for item in container[array_key]: | ||
545 | 115 | if item[object_key] == value: | ||
546 | 116 | container[array_key].remove(item) | ||
547 | 117 | write_container_config_file(self.container_list) | ||
548 | 118 | return | ||
549 | 119 | |||
550 | 120 | def _test_key_value_exists(self, container_id, key, value=None): | ||
551 | 121 | key_value = self._get_value_by_key(container_id, key) | ||
552 | 122 | |||
553 | 123 | if not key_value: | ||
554 | 124 | return False | ||
555 | 125 | elif key == 'id': | ||
556 | 126 | return True | ||
557 | 127 | elif key_value == value: | ||
558 | 128 | return True | ||
559 | 129 | else: | ||
560 | 130 | return False | ||
561 | 131 | |||
562 | 132 | def _test_array_object_key_value_exists(self, container_id, array_key, object_key, value): | ||
563 | 133 | array = self._get_value_by_key(container_id, array_key) | ||
564 | 134 | |||
565 | 135 | if not array: | ||
566 | 136 | return False | ||
567 | 137 | |||
568 | 138 | for item in array: | ||
569 | 139 | if item[object_key] == value: | ||
570 | 140 | return True | ||
571 | 141 | |||
572 | 142 | return False | ||
573 | 143 | |||
574 | 144 | """ | ||
575 | 145 | Miscellaneous ContainersConfig.json operations | ||
576 | 146 | """ | ||
577 | 147 | def _find_duplicate_container_entry(self, container_list, container_id): | ||
578 | 148 | for container in container_list['containerList']: | ||
579 | 149 | if container['id'] == container_id: | ||
580 | 150 | return container | ||
581 | 151 | |||
582 | 152 | return None | ||
583 | 153 | |||
584 | 154 | def merge_container_config_files(self, filepath): | ||
585 | 155 | merged_json = [] | ||
586 | 156 | |||
587 | 157 | with open(filepath, 'r') as fd: | ||
588 | 158 | merge_source = json.load(fd) | ||
589 | 159 | |||
590 | 160 | if "containerList" in self.container_list: | ||
591 | 161 | # Finds any duplicate entries and assumes we want to update the main config | ||
592 | 162 | # with entries from the merge source. | ||
593 | 163 | for i, container in enumerate(self.container_list['containerList']): | ||
594 | 164 | merge_container = self._find_duplicate_container_entry(merge_source, container['id']) | ||
595 | 165 | if merge_container: | ||
596 | 166 | self.container_list['containerList'][i] = merge_container | ||
597 | 167 | merge_source['containerList'].remove(merge_container) | ||
598 | 168 | |||
599 | 169 | # Merges in any remaining non-duplicate entries. | ||
600 | 170 | for container in merge_source['containerList']: | ||
601 | 171 | self.container_list['containerList'].append(container) | ||
602 | 172 | |||
603 | 173 | else: | ||
604 | 174 | self.container_list = merge_source | ||
605 | 175 | |||
606 | 176 | write_container_config_file(self.container_list) | ||
607 | 177 | |||
608 | 178 | def check_container_id(self, container_id): | ||
609 | 179 | if container_id and not self.container_exists(container_id): | ||
610 | 180 | print("Container id \'%s\' does not exist." % container_id, file=sys.stderr) | ||
611 | 181 | sys.exit(1) | ||
612 | 182 | elif not container_id: | ||
613 | 183 | return self.get_default_container_id() | ||
614 | 184 | |||
615 | 185 | return container_id | ||
616 | 186 | |||
617 | 187 | def get_default_container_id(self): | ||
618 | 188 | return self.default_container_id | ||
619 | 189 | |||
620 | 190 | def set_default_container_id(self, container_id, write_json=False): | ||
621 | 191 | self.default_container_id = container_id | ||
622 | 192 | self.container_list['defaultContainer'] = container_id | ||
623 | 193 | |||
624 | 194 | if write_json: | ||
625 | 195 | write_container_config_file(self.container_list) | ||
626 | 196 | |||
627 | 197 | def clear_default_container_id(self, write_json=False): | ||
628 | 198 | self.default_container_id = None | ||
629 | 199 | self.container_list.pop('defaultContainer', None) | ||
630 | 200 | |||
631 | 201 | if write_json: | ||
632 | 202 | write_container_config_file(self.container_list) | ||
633 | 203 | |||
634 | 204 | """ | ||
635 | 205 | Operations for the container itself. | ||
636 | 206 | """ | ||
637 | 207 | def add_new_container(self, container_id, container_name, container_type, container_distro): | ||
638 | 208 | container_obj = {'id': container_id, 'installStatus': 'new', 'type': container_type, | ||
639 | 209 | 'distro': container_distro, 'name': container_name, 'installedApps': []} | ||
640 | 210 | |||
641 | 211 | if "defaultContainer" not in self.container_list: | ||
642 | 212 | self.set_default_container_id(container_id) | ||
643 | 213 | |||
644 | 214 | if "containerList" not in self.container_list: | ||
645 | 215 | self.container_list['containerList'] = [container_obj] | ||
646 | 216 | else: | ||
647 | 217 | self.container_list['containerList'].append(container_obj) | ||
648 | 218 | |||
649 | 219 | write_container_config_file(self.container_list) | ||
650 | 220 | |||
651 | 221 | def delete_container(self, container_id): | ||
652 | 222 | if not self.container_list: | ||
653 | 223 | print("Unable to delete container. No containers defined.") | ||
654 | 224 | sys.exit(1) | ||
655 | 225 | |||
656 | 226 | container = self._get_container_entry(container_id) | ||
657 | 227 | |||
658 | 228 | self.container_list['containerList'].remove(container) | ||
659 | 229 | |||
660 | 230 | # Set a new defaultContainer if the current default is being deleted. | ||
661 | 231 | if self.container_list['defaultContainer'] == container_id and self.container_list['containerList']: | ||
662 | 232 | self.set_default_container_id(self.container_list['containerList'][0]['id']) | ||
663 | 233 | # Remove the defaultContainer if there are no more containers left. | ||
664 | 234 | elif not self.container_list['containerList']: | ||
665 | 235 | self.clear_default_container_id() | ||
666 | 236 | |||
667 | 237 | write_container_config_file(self.container_list) | ||
668 | 238 | |||
669 | 239 | def update_container_install_status(self, container_id, new_status): | ||
670 | 240 | self._set_value_by_key(container_id, 'installStatus', new_status) | ||
671 | 241 | |||
672 | 242 | def container_exists(self, container_id): | ||
673 | 243 | return self._test_key_value_exists(container_id, 'id') | ||
674 | 244 | |||
675 | 245 | def update_container_multiarch_support(self, container_id, multiarch): | ||
676 | 246 | if multiarch == 'enabled' and libertine.utils.get_host_architecture() == 'i386': | ||
677 | 247 | multiarch = 'disabled' | ||
678 | 248 | |||
679 | 249 | self._set_value_by_key(container_id, 'multiarch', multiarch) | ||
680 | 250 | |||
681 | 251 | def get_container_multiarch_support(self, container_id): | ||
682 | 252 | multiarch_support = self._get_value_by_key(container_id, 'multiarch') | ||
683 | 253 | |||
684 | 254 | if multiarch_support == None: | ||
685 | 255 | return 'disabled' | ||
686 | 256 | else: | ||
687 | 257 | return multiarch_support | ||
688 | 258 | |||
689 | 259 | """ | ||
690 | 260 | Operations for archive (PPA) maintenance in a Libertine container. | ||
691 | 261 | """ | ||
692 | 262 | def add_container_archive(self, container_id, archive_name): | ||
693 | 263 | archive_obj = {'archiveName': archive_name, 'archiveStatus': 'new'} | ||
694 | 264 | self._set_value_by_key(container_id, 'extraArchives', archive_obj) | ||
695 | 265 | |||
696 | 266 | def delete_container_archive(self, container_id, archive_name): | ||
697 | 267 | self._delete_array_object_by_key_value(container_id, 'extraArchives', | ||
698 | 268 | 'archiveName', archive_name) | ||
699 | 269 | |||
700 | 270 | def update_archive_install_status(self, container_id, archive_name, new_status): | ||
701 | 271 | self._set_array_object_value_by_key(container_id, 'extraArchives', 'archiveName', | ||
702 | 272 | archive_name, 'archiveStatus', new_status) | ||
703 | 273 | |||
704 | 274 | def archive_exists(self, container_id, archive_name): | ||
705 | 275 | return self._test_array_object_key_value_exists(container_id, 'extraArchives', 'archiveName', | ||
706 | 276 | archive_name) | ||
707 | 277 | |||
708 | 278 | """ | ||
709 | 279 | Operations for package maintenance in a Libertine container. | ||
710 | 280 | """ | ||
711 | 281 | def add_new_package(self, container_id, package_name): | ||
712 | 282 | package_obj = {'packageName': package_name, 'appStatus': 'new'} | ||
713 | 283 | self._set_value_by_key(container_id, 'installedApps', package_obj) | ||
714 | 284 | |||
715 | 285 | def delete_package(self, container_id, package_name): | ||
716 | 286 | self._delete_array_object_by_key_value(container_id, 'installedApps', | ||
717 | 287 | 'packageName', package_name) | ||
718 | 288 | |||
719 | 289 | def update_package_install_status(self, container_id, package_name, new_status): | ||
720 | 290 | self._set_array_object_value_by_key(container_id, 'installedApps', 'packageName', | ||
721 | 291 | package_name, 'appStatus', new_status) | ||
722 | 292 | |||
723 | 293 | def get_package_install_status(self, container_id, package_name): | ||
724 | 294 | return self._get_array_object_value_by_key(container_id, 'installedApps', 'packageName', | ||
725 | 295 | package_name, 'appStatus') | ||
726 | 296 | |||
727 | 297 | def package_exists(self, container_id, package_name): | ||
728 | 298 | return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName', | ||
729 | 299 | package_name) | ||
730 | 300 | |||
731 | 301 | """ | ||
732 | 302 | Fetcher functions for various configuration information. | ||
733 | 303 | """ | ||
734 | 304 | def get_container_distro(self, container_id): | ||
735 | 305 | return self._get_value_by_key(container_id, 'distro') | ||
736 | 306 | |||
737 | 307 | def get_container_type(self, container_id): | ||
738 | 308 | return self._get_value_by_key(container_id, 'type') | ||
739 | 309 | |||
740 | 0 | 310 | ||
741 | === added file 'python/libertine/HostInfo.py' | |||
742 | --- python/libertine/HostInfo.py 1970-01-01 00:00:00 +0000 | |||
743 | +++ python/libertine/HostInfo.py 2016-07-07 20:14:07 +0000 | |||
744 | @@ -0,0 +1,71 @@ | |||
745 | 1 | # Copyright 2016 Canonical Ltd. | ||
746 | 2 | # | ||
747 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
748 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
749 | 5 | # by the Free Software Foundation. | ||
750 | 6 | # | ||
751 | 7 | # This program is distributed in the hope that it will be useful, but | ||
752 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
753 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
754 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
755 | 11 | # | ||
756 | 12 | # You should have received a copy of the GNU General Public License along | ||
757 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
758 | 14 | |||
759 | 15 | import lsb_release | ||
760 | 16 | import platform | ||
761 | 17 | import subprocess | ||
762 | 18 | |||
763 | 19 | from distro_info import UbuntuDistroInfo | ||
764 | 20 | |||
765 | 21 | |||
766 | 22 | class HostInfo(object): | ||
767 | 23 | |||
768 | 24 | def select_container_type_by_kernel(self): | ||
769 | 25 | if self.has_lxc_support(): | ||
770 | 26 | return "lxc" | ||
771 | 27 | else: | ||
772 | 28 | return "chroot" | ||
773 | 29 | |||
774 | 30 | def has_lxc_support(self): | ||
775 | 31 | kernel_release = platform.release().split('.') | ||
776 | 32 | return int(kernel_release[0]) >= 4 or (int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13) | ||
777 | 33 | |||
778 | 34 | def get_host_distro_release(self): | ||
779 | 35 | distinfo = lsb_release.get_distro_information() | ||
780 | 36 | |||
781 | 37 | return distinfo.get('CODENAME', 'n/a') | ||
782 | 38 | |||
783 | 39 | def is_distro_valid(self, distro, force): | ||
784 | 40 | if force: | ||
785 | 41 | return UbuntuDistroInfo().valid(distro) | ||
786 | 42 | |||
787 | 43 | if distro == self.get_host_distro_release(): | ||
788 | 44 | return True | ||
789 | 45 | |||
790 | 46 | supported_distros = UbuntuDistroInfo().supported() | ||
791 | 47 | |||
792 | 48 | try: | ||
793 | 49 | supported_distros.index(distro) | ||
794 | 50 | except ValueError: | ||
795 | 51 | return False | ||
796 | 52 | |||
797 | 53 | return True | ||
798 | 54 | |||
799 | 55 | def get_distro_codename(self, distro): | ||
800 | 56 | ubuntu_distro_info = UbuntuDistroInfo() | ||
801 | 57 | |||
802 | 58 | for row in ubuntu_distro_info._rows: | ||
803 | 59 | if row['series'] == distro: | ||
804 | 60 | return row['codename'] | ||
805 | 61 | |||
806 | 62 | return None | ||
807 | 63 | |||
808 | 64 | def get_host_architecture(self): | ||
809 | 65 | dpkg = subprocess.Popen(['dpkg', '--print-architecture'], | ||
810 | 66 | stdout=subprocess.PIPE, | ||
811 | 67 | universal_newlines=True) | ||
812 | 68 | if dpkg.wait() != 0: | ||
813 | 69 | parser.error("Failed to determine the local architecture.") | ||
814 | 70 | |||
815 | 71 | return dpkg.stdout.read().strip() | ||
816 | 0 | 72 | ||
817 | === modified file 'python/libertine/Libertine.py' | |||
818 | --- python/libertine/Libertine.py 2016-06-14 20:05:24 +0000 | |||
819 | +++ python/libertine/Libertine.py 2016-07-07 20:14:07 +0000 | |||
820 | @@ -16,30 +16,12 @@ | |||
821 | 16 | from gi.repository import Libertine | 16 | from gi.repository import Libertine |
822 | 17 | import abc | 17 | import abc |
823 | 18 | import contextlib | 18 | import contextlib |
824 | 19 | import json | ||
825 | 20 | import libertine.utils | 19 | import libertine.utils |
826 | 21 | import os | 20 | import os |
827 | 22 | import shutil | 21 | import shutil |
828 | 23 | 22 | ||
848 | 24 | 23 | from libertine.ContainersConfig import ContainersConfig | |
849 | 25 | def get_container_type(container_id): | 24 | from libertine.HostInfo import HostInfo |
831 | 26 | """ | ||
832 | 27 | Retrieves the type of container for a given container ID. | ||
833 | 28 | :param container_id: The Container ID to search for. | ||
834 | 29 | """ | ||
835 | 30 | try: | ||
836 | 31 | with open(libertine.utils.get_libertine_database_file_path()) as fd: | ||
837 | 32 | container_list = json.load(fd) | ||
838 | 33 | |||
839 | 34 | for container in container_list["containerList"]: | ||
840 | 35 | if container["id"] == container_id: | ||
841 | 36 | return container["type"] | ||
842 | 37 | |||
843 | 38 | except FileNotFoundError: | ||
844 | 39 | pass | ||
845 | 40 | |||
846 | 41 | # Return lxc as the default container type | ||
847 | 42 | return "lxc" | ||
850 | 43 | 25 | ||
851 | 44 | 26 | ||
852 | 45 | def apt_args_for_verbosity_level(verbosity): | 27 | def apt_args_for_verbosity_level(verbosity): |
853 | @@ -175,10 +157,9 @@ | |||
854 | 175 | 157 | ||
855 | 176 | return ret | 158 | return ret |
856 | 177 | else: | 159 | else: |
857 | 178 | cmd = apt_command_prefix(verbosity) + " install '" + package_name + "'" | ||
858 | 179 | if readline: | 160 | if readline: |
861 | 180 | cmd = "env DEBIAN_FRONTEND=readline " + cmd | 161 | os.environ['DEBIAN_FRONTEND'] = 'readline' |
862 | 181 | return self.run_in_container(cmd) == 0 | 162 | return self.run_in_container(apt_command_prefix(verbosity) + " install '" + package_name + "'") == 0 |
863 | 182 | 163 | ||
864 | 183 | def configure_command(self, command, *args, verbosity=1): | 164 | def configure_command(self, command, *args, verbosity=1): |
865 | 184 | """ | 165 | """ |
866 | @@ -207,21 +188,6 @@ | |||
867 | 207 | elif command == 'delete-archive': | 188 | elif command == 'delete-archive': |
868 | 208 | return self.run_in_container("add-apt-repository -y -r " + args[0]) | 189 | return self.run_in_container("add-apt-repository -y -r " + args[0]) |
869 | 209 | 190 | ||
870 | 210 | def get_container_distro(self, container_id): | ||
871 | 211 | """ | ||
872 | 212 | Retrieves the distro code name for a given container ID. | ||
873 | 213 | |||
874 | 214 | :param container_id: The Container ID to search for. | ||
875 | 215 | """ | ||
876 | 216 | with open(libertine.utils.get_libertine_database_file_path()) as fd: | ||
877 | 217 | container_list = json.load(fd) | ||
878 | 218 | |||
879 | 219 | for container in container_list["containerList"]: | ||
880 | 220 | if container["id"] == container_id: | ||
881 | 221 | return container["distro"] | ||
882 | 222 | |||
883 | 223 | return "" | ||
884 | 224 | |||
885 | 225 | @property | 191 | @property |
886 | 226 | def name(self): | 192 | def name(self): |
887 | 227 | """ | 193 | """ |
888 | @@ -281,9 +247,9 @@ | |||
889 | 281 | """ | 247 | """ |
890 | 282 | super().__init__() | 248 | super().__init__() |
891 | 283 | 249 | ||
893 | 284 | container_type = get_container_type(container_id) | 250 | container_type = ContainersConfig().get_container_type(container_id) |
894 | 285 | 251 | ||
896 | 286 | if container_type == "lxc": | 252 | if container_type == None or container_type == "lxc": |
897 | 287 | from libertine.LxcContainer import LibertineLXC | 253 | from libertine.LxcContainer import LibertineLXC |
898 | 288 | self.container = LibertineLXC(container_id) | 254 | self.container = LibertineLXC(container_id) |
899 | 289 | elif container_type == "chroot": | 255 | elif container_type == "chroot": |
900 | @@ -320,6 +286,9 @@ | |||
901 | 320 | """ | 286 | """ |
902 | 321 | Creates the container. | 287 | Creates the container. |
903 | 322 | """ | 288 | """ |
904 | 289 | self.container.architecture = HostInfo().get_host_architecture() | ||
905 | 290 | self.container.installed_release = ContainersConfig().get_container_distro(self.container_id) | ||
906 | 291 | |||
907 | 323 | return self.container.create_libertine_container(password, multiarch, verbosity) | 292 | return self.container.create_libertine_container(password, multiarch, verbosity) |
908 | 324 | 293 | ||
909 | 325 | def update_libertine_container(self, verbosity=1): | 294 | def update_libertine_container(self, verbosity=1): |
910 | @@ -351,10 +320,10 @@ | |||
911 | 351 | """ | 320 | """ |
912 | 352 | try: | 321 | try: |
913 | 353 | with ContainerRunning(self.container): | 322 | with ContainerRunning(self.container): |
914 | 354 | cmd = apt_command_prefix(verbosity) + " purge '" + package_name + "'" | ||
915 | 355 | if readline: | 323 | if readline: |
918 | 356 | cmd = "env DEBIAN_FRONTEND=readline " + cmd | 324 | os.environ['DEBIAN_FRONTEND'] = 'readline' |
919 | 357 | if self.container.run_in_container(cmd) != 0: | 325 | |
920 | 326 | if self.container.run_in_container(apt_command_prefix(verbosity) + " purge '" + package_name + "'") != 0: | ||
921 | 358 | return False | 327 | return False |
922 | 359 | return self.container.run_in_container(apt_command_prefix(verbosity) + "autoremove --purge") == 0 | 328 | return self.container.run_in_container(apt_command_prefix(verbosity) + "autoremove --purge") == 0 |
923 | 360 | except RuntimeError as e: | 329 | except RuntimeError as e: |
924 | @@ -380,7 +349,11 @@ | |||
925 | 380 | :param app_exec_line: the application exec line as passed in by | 349 | :param app_exec_line: the application exec line as passed in by |
926 | 381 | ubuntu-app-launch | 350 | ubuntu-app-launch |
927 | 382 | """ | 351 | """ |
929 | 383 | if libertine.utils.container_exists(self.container.container_id): | 352 | if ContainersConfig().container_exists(self.container.container_id): |
930 | 353 | # Update $PATH as necessary | ||
931 | 354 | if '/usr/games' not in os.environ['PATH']: | ||
932 | 355 | os.environ['PATH'] = os.environ['PATH'] + ":/usr/games" | ||
933 | 356 | |||
934 | 384 | self.container.launch_application(app_exec_line) | 357 | self.container.launch_application(app_exec_line) |
935 | 385 | else: | 358 | else: |
936 | 386 | raise RuntimeError("Container with id %s does not exist." % self.container.container_id) | 359 | raise RuntimeError("Container with id %s does not exist." % self.container.container_id) |
937 | 387 | 360 | ||
938 | === modified file 'python/libertine/LxcContainer.py' | |||
939 | --- python/libertine/LxcContainer.py 2016-06-22 16:26:15 +0000 | |||
940 | +++ python/libertine/LxcContainer.py 2016-07-07 20:14:07 +0000 | |||
941 | @@ -18,6 +18,7 @@ | |||
942 | 18 | import psutil | 18 | import psutil |
943 | 19 | import shlex | 19 | import shlex |
944 | 20 | import subprocess | 20 | import subprocess |
945 | 21 | import sys | ||
946 | 21 | import tempfile | 22 | import tempfile |
947 | 22 | 23 | ||
948 | 23 | from .Libertine import BaseContainer | 24 | from .Libertine import BaseContainer |
949 | @@ -85,11 +86,6 @@ | |||
950 | 85 | self.container_type = "lxc" | 86 | self.container_type = "lxc" |
951 | 86 | self.container = lxc_container(container_id) | 87 | self.container = lxc_container(container_id) |
952 | 87 | 88 | ||
953 | 88 | if self.container.defined: | ||
954 | 89 | self.lxc_log_file = os.path.join(tempfile.mkdtemp(), 'lxc-start.log') | ||
955 | 90 | self.container.append_config_item("lxc.logfile", self.lxc_log_file) | ||
956 | 91 | self.container.append_config_item("lxc.logpriority", "3") | ||
957 | 92 | |||
958 | 93 | def is_running(self): | 89 | def is_running(self): |
959 | 94 | return self.container.running | 90 | return self.container.running |
960 | 95 | 91 | ||
961 | @@ -105,7 +101,11 @@ | |||
962 | 105 | return True | 101 | return True |
963 | 106 | 102 | ||
964 | 107 | def start_container(self): | 103 | def start_container(self): |
965 | 104 | if not self.container.defined: | ||
966 | 105 | raise RuntimeError("Container %s is not valid" % self.container_id) | ||
967 | 106 | |||
968 | 108 | if not self.container.running: | 107 | if not self.container.running: |
969 | 108 | self._set_lxc_log() | ||
970 | 109 | if not self.container.start(): | 109 | if not self.container.start(): |
971 | 110 | self._dump_lxc_log() | 110 | self._dump_lxc_log() |
972 | 111 | raise RuntimeError("Container failed to start") | 111 | raise RuntimeError("Container failed to start") |
973 | @@ -147,8 +147,6 @@ | |||
974 | 147 | if password is None: | 147 | if password is None: |
975 | 148 | return False | 148 | return False |
976 | 149 | 149 | ||
977 | 150 | installed_release = self.get_container_distro(self.container_id) | ||
978 | 151 | |||
979 | 152 | username = os.environ['USER'] | 150 | username = os.environ['USER'] |
980 | 153 | user_id = os.getuid() | 151 | user_id = os.getuid() |
981 | 154 | group_id = os.getgid() | 152 | group_id = os.getgid() |
982 | @@ -177,13 +175,10 @@ | |||
983 | 177 | 175 | ||
984 | 178 | utils.create_libertine_user_data_dir(self.container_id) | 176 | utils.create_libertine_user_data_dir(self.container_id) |
985 | 179 | 177 | ||
986 | 180 | # Figure out the host architecture | ||
987 | 181 | architecture = utils.get_host_architecture() | ||
988 | 182 | |||
989 | 183 | if not self.container.create("download", 0, | 178 | if not self.container.create("download", 0, |
990 | 184 | {"dist": "ubuntu", | 179 | {"dist": "ubuntu", |
993 | 185 | "release": installed_release, | 180 | "release": self.installed_release, |
994 | 186 | "arch": architecture}): | 181 | "arch": self.architecture}): |
995 | 187 | print("Failed to create container") | 182 | print("Failed to create container") |
996 | 188 | return False | 183 | return False |
997 | 189 | 184 | ||
998 | @@ -202,7 +197,7 @@ | |||
999 | 202 | self.run_in_container("useradd -u {} -p {} -G sudo {}".format( | 197 | self.run_in_container("useradd -u {} -p {} -G sudo {}".format( |
1000 | 203 | str(user_id), crypt.crypt(password), str(username))) | 198 | str(user_id), crypt.crypt(password), str(username))) |
1001 | 204 | 199 | ||
1003 | 205 | if multiarch and architecture == 'amd64': | 200 | if multiarch and self.architecture == 'amd64': |
1004 | 206 | if verbosity == 1: | 201 | if verbosity == 1: |
1005 | 207 | print("Adding i386 multiarch support...") | 202 | print("Adding i386 multiarch support...") |
1006 | 208 | self.run_in_container("dpkg --add-architecture i386") | 203 | self.run_in_container("dpkg --add-architecture i386") |
1007 | @@ -308,7 +303,15 @@ | |||
1008 | 308 | data = libertine_lxc_mgr_sock.recv(1024) | 303 | data = libertine_lxc_mgr_sock.recv(1024) |
1009 | 309 | libertine_lxc_mgr_sock.close() | 304 | libertine_lxc_mgr_sock.close() |
1010 | 310 | 305 | ||
1011 | 306 | def _set_lxc_log(self): | ||
1012 | 307 | self.lxc_log_file = os.path.join(tempfile.mkdtemp(), 'lxc-start.log') | ||
1013 | 308 | self.container.append_config_item("lxc.logfile", self.lxc_log_file) | ||
1014 | 309 | self.container.append_config_item("lxc.logpriority", "3") | ||
1015 | 310 | |||
1016 | 311 | def _dump_lxc_log(self): | 311 | def _dump_lxc_log(self): |
1020 | 312 | with open(self.lxc_log_file, 'r') as fd: | 312 | try: |
1021 | 313 | for line in fd: | 313 | with open(self.lxc_log_file, 'r') as fd: |
1022 | 314 | print(line.lstrip()) | 314 | for line in fd: |
1023 | 315 | print(line.lstrip()) | ||
1024 | 316 | except Exception as ex: | ||
1025 | 317 | print("Could not open LXC log file: %s" % ex, file=sys.stderr) | ||
1026 | 315 | 318 | ||
1027 | === modified file 'python/libertine/utils.py' | |||
1028 | --- python/libertine/utils.py 2016-06-23 13:27:26 +0000 | |||
1029 | +++ python/libertine/utils.py 2016-07-07 20:14:07 +0000 | |||
1030 | @@ -16,9 +16,7 @@ | |||
1031 | 16 | # You should have received a copy of the GNU General Public License | 16 | # You should have received a copy of the GNU General Public License |
1032 | 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/>. |
1033 | 18 | 18 | ||
1034 | 19 | import json | ||
1035 | 20 | import os | 19 | import os |
1036 | 21 | import psutil | ||
1037 | 22 | import shlex | 20 | import shlex |
1038 | 23 | import subprocess | 21 | import subprocess |
1039 | 24 | import xdg.BaseDirectory as basedir | 22 | import xdg.BaseDirectory as basedir |
1040 | @@ -28,22 +26,6 @@ | |||
1041 | 28 | from gi.repository import Libertine | 26 | from gi.repository import Libertine |
1042 | 29 | 27 | ||
1043 | 30 | 28 | ||
1044 | 31 | def container_exists(container_id): | ||
1045 | 32 | container_config_file_path = get_libertine_database_file_path() | ||
1046 | 33 | |||
1047 | 34 | if (os.path.exists(container_config_file_path) and | ||
1048 | 35 | os.path.getsize(container_config_file_path) != 0): | ||
1049 | 36 | with open(get_libertine_database_file_path()) as fd: | ||
1050 | 37 | container_list = json.load(fd) | ||
1051 | 38 | |||
1052 | 39 | if container_list: | ||
1053 | 40 | for container in container_list['containerList']: | ||
1054 | 41 | if container['id'] == container_id: | ||
1055 | 42 | return True | ||
1056 | 43 | |||
1057 | 44 | return False | ||
1058 | 45 | |||
1059 | 46 | |||
1060 | 47 | def get_libertine_container_rootfs_path(container_id): | 29 | def get_libertine_container_rootfs_path(container_id): |
1061 | 48 | path = Libertine.container_path(container_id) | 30 | path = Libertine.container_path(container_id) |
1062 | 49 | 31 | ||
1063 | @@ -97,16 +79,6 @@ | |||
1064 | 97 | return os.path.join(get_user_runtime_dir(), 'libertine') | 79 | return os.path.join(get_user_runtime_dir(), 'libertine') |
1065 | 98 | 80 | ||
1066 | 99 | 81 | ||
1067 | 100 | def get_host_architecture(): | ||
1068 | 101 | dpkg = subprocess.Popen(['dpkg', '--print-architecture'], | ||
1069 | 102 | stdout=subprocess.PIPE, | ||
1070 | 103 | universal_newlines=True) | ||
1071 | 104 | if dpkg.wait() != 0: | ||
1072 | 105 | parser.error("Failed to determine the local architecture.") | ||
1073 | 106 | |||
1074 | 107 | return dpkg.stdout.read().strip() | ||
1075 | 108 | |||
1076 | 109 | |||
1077 | 110 | def get_common_xdg_directories(): | 82 | def get_common_xdg_directories(): |
1078 | 111 | return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads'] | 83 | return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads'] |
1079 | 112 | 84 | ||
1080 | @@ -167,4 +139,4 @@ | |||
1081 | 167 | gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" % | 139 | gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" % |
1082 | 168 | (scopes_object_path, invalidate_signal, libertine_scope_id)) | 140 | (scopes_object_path, invalidate_signal, libertine_scope_id)) |
1083 | 169 | 141 | ||
1085 | 170 | subprocess.Popen(shlex.split(gdbus_cmd)) | 142 | subprocess.Popen(shlex.split(gdbus_cmd), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
1086 | 171 | 143 | ||
1087 | === modified file 'tests/unit/CMakeLists.txt' | |||
1088 | --- tests/unit/CMakeLists.txt 2015-12-21 21:02:33 +0000 | |||
1089 | +++ tests/unit/CMakeLists.txt 2016-07-07 20:14:07 +0000 | |||
1090 | @@ -44,10 +44,14 @@ | |||
1091 | 44 | ENVIRONMENT | 44 | ENVIRONMENT |
1092 | 45 | "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") | 45 | "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") |
1093 | 46 | 46 | ||
1101 | 47 | add_test(test_libertine_launch | 47 | set(DISABLED 1) |
1102 | 48 | "/usr/bin/python3" "-m" "testtools.run" "libertine_launch_tests" | 48 | |
1103 | 49 | ) | 49 | if (NOT DISABLED) |
1104 | 50 | set_tests_properties(test_libertine_launch | 50 | add_test(test_libertine_launch |
1105 | 51 | PROPERTIES | 51 | "/usr/bin/python3" "-m" "testtools.run" "libertine_launch_tests" |
1106 | 52 | ENVIRONMENT | 52 | ) |
1107 | 53 | "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") | 53 | set_tests_properties(test_libertine_launch |
1108 | 54 | PROPERTIES | ||
1109 | 55 | ENVIRONMENT | ||
1110 | 56 | "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") | ||
1111 | 57 | endif() | ||
1112 | 54 | 58 | ||
1113 | === modified file 'tools/libertine-container-manager' | |||
1114 | --- tools/libertine-container-manager 2016-06-20 15:15:38 +0000 | |||
1115 | +++ tools/libertine-container-manager 2016-07-07 20:14:07 +0000 | |||
1116 | @@ -17,637 +17,270 @@ | |||
1117 | 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/>. |
1118 | 18 | 18 | ||
1119 | 19 | import argparse | 19 | import argparse |
1120 | 20 | import fcntl | ||
1121 | 21 | import json | ||
1122 | 22 | import libertine.utils | 20 | import libertine.utils |
1123 | 23 | import lsb_release | ||
1124 | 24 | import getpass | 21 | import getpass |
1125 | 25 | import os | 22 | import os |
1126 | 26 | import platform | ||
1127 | 27 | import sys | 23 | import sys |
1128 | 28 | 24 | ||
1129 | 29 | from apt.debfile import DebPackage | 25 | from apt.debfile import DebPackage |
1130 | 30 | from distro_info import UbuntuDistroInfo, DistroDataOutdated | ||
1131 | 31 | from libertine import LibertineContainer | 26 | from libertine import LibertineContainer |
1681 | 32 | 27 | from libertine.ContainersConfig import ContainersConfig | |
1682 | 33 | 28 | from libertine.HostInfo import HostInfo | |
1683 | 34 | def find_duplicate_container_entry(container_list, container_id): | 29 | |
1684 | 35 | for container in container_list['containerList']: | 30 | |
1685 | 36 | if container['id'] == container_id: | 31 | class LibertineContainerManager(object): |
1686 | 37 | return container | 32 | |
1687 | 38 | 33 | def __init__(self): | |
1688 | 39 | return None | 34 | self.containers_config = ContainersConfig() |
1689 | 40 | 35 | self.host_info = HostInfo() | |
1690 | 41 | 36 | ||
1691 | 42 | def merge_container_config_files(filepath): | 37 | def create(self, args): |
1692 | 43 | merged_json = [] | 38 | password = None |
1693 | 44 | main_config = read_container_config_file() | 39 | |
1694 | 45 | 40 | if args.distro and not self.host_info.is_distro_valid(args.distro, args.force): | |
1695 | 46 | with open(filepath, 'r') as fd: | 41 | print("Invalid distro %s" % args.distro, file=sys.stderr) |
1696 | 47 | merge_source = json.load(fd) | 42 | sys.exit(1) |
1697 | 48 | 43 | ||
1698 | 49 | if "containerList" in main_config: | 44 | if args.id and self.containers_config.container_exists(args.id): |
1699 | 50 | # Finds any duplicate entries and assumes we want to update the main config | 45 | print("Container id \'%s\' is already used." % args.id, file=sys.stderr) |
1700 | 51 | # with entries from the merge source. | 46 | sys.exit(1) |
1701 | 52 | for i, container in enumerate(main_config['containerList']): | 47 | elif not args.id: |
1702 | 53 | merge_container = find_duplicate_container_entry(merge_source, container['id']) | 48 | args.id = get_unique_container_id(distro) |
1703 | 54 | if merge_container: | 49 | |
1704 | 55 | main_config['containerList'][i] = merge_container | 50 | if not args.type: |
1705 | 56 | merge_source['containerList'].remove(merge_container) | 51 | container_type = self.host_info.select_container_type_by_kernel() |
1706 | 57 | 52 | else: | |
1707 | 58 | # Merges in any remaining non-duplicate entries. | 53 | if args.type == 'lxc' and not self.host_info.has_lxc_support(): |
1708 | 59 | for container in merge_source['containerList']: | 54 | print("System kernel does not support lxc type containers. " |
1709 | 60 | main_config['containerList'].append(container) | 55 | "Please either use chroot or omit the -t option.") |
1710 | 61 | 56 | sys.exit(1) | |
1711 | 62 | else: | 57 | container_type = args.type |
1712 | 63 | main_config = merge_source | 58 | |
1713 | 64 | 59 | if not args.distro: | |
1714 | 65 | write_container_config_file(main_config) | 60 | args.distro = self.host_info.get_host_distro_release() |
1715 | 66 | 61 | elif container_type == "chroot": | |
1716 | 67 | 62 | host_distro = self.host_info.get_host_distro_release() | |
1717 | 68 | def read_container_config_file(): | 63 | |
1718 | 69 | container_list = {} | 64 | if args.distro != host_distro: |
1719 | 70 | container_config_file = libertine.utils.get_libertine_database_file_path() | 65 | print("The container distribution needs to match the host ditribution for chroot" |
1720 | 71 | 66 | " based containers. Please either use \'%s\' or omit the -d/--distro option." | |
1721 | 72 | if (os.path.exists(container_config_file) and | 67 | % host_distro) |
1722 | 73 | os.path.getsize(container_config_file) != 0): | 68 | sys.exit(1) |
1723 | 74 | with open(container_config_file, 'r') as fd: | 69 | |
1724 | 75 | container_list = json.load(fd) | 70 | if not args.name: |
1725 | 76 | 71 | args.name = "Ubuntu \'" + self.host_info.get_distro_codename(args.distro) + "\'" | |
1726 | 77 | return container_list | 72 | |
1727 | 78 | 73 | if container_type == "lxc": | |
1728 | 79 | 74 | if args.password: | |
1729 | 80 | def write_container_config_file(container_list): | 75 | password = args.password |
1730 | 81 | container_config_file = libertine.utils.get_libertine_database_file_path() | 76 | elif sys.stdin.isatty(): |
1731 | 82 | 77 | print("Your user password is required for creating a Libertine container.") | |
1732 | 83 | with open(container_config_file, 'w') as fd: | 78 | password = getpass.getpass() |
1733 | 84 | fcntl.lockf(fd, fcntl.LOCK_EX) | 79 | else: |
1734 | 85 | json.dump(container_list, fd, sort_keys=True, indent=4) | 80 | password = sys.stdin.readline().rstrip() |
1735 | 86 | fd.write('\n') | 81 | |
1736 | 87 | fcntl.lockf(fd, fcntl.LOCK_UN) | 82 | self.containers_config.add_new_container(args.id, args.name, container_type, args.distro) |
1737 | 88 | 83 | ||
1189 | 89 | |||
1190 | 90 | def get_default_container_id(): | ||
1191 | 91 | default_container_id = None | ||
1192 | 92 | |||
1193 | 93 | container_list = read_container_config_file() | ||
1194 | 94 | |||
1195 | 95 | if "defaultContainer" in container_list: | ||
1196 | 96 | default_container_id = container_list['defaultContainer'] | ||
1197 | 97 | |||
1198 | 98 | return default_container_id | ||
1199 | 99 | |||
1200 | 100 | |||
1201 | 101 | def select_container_type(): | ||
1202 | 102 | kernel_release = platform.release().split('.') | ||
1203 | 103 | |||
1204 | 104 | if int(kernel_release[0]) >= 4: | ||
1205 | 105 | return "lxc" | ||
1206 | 106 | elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13: | ||
1207 | 107 | return "lxc" | ||
1208 | 108 | else: | ||
1209 | 109 | return "chroot" | ||
1210 | 110 | |||
1211 | 111 | |||
1212 | 112 | def get_host_distro_release(): | ||
1213 | 113 | distinfo = lsb_release.get_distro_information() | ||
1214 | 114 | |||
1215 | 115 | return distinfo.get('CODENAME', 'n/a') | ||
1216 | 116 | |||
1217 | 117 | |||
1218 | 118 | def is_distro_valid(distro, force): | ||
1219 | 119 | if force: | ||
1220 | 120 | return UbuntuDistroInfo().valid(distro) | ||
1221 | 121 | |||
1222 | 122 | if distro == get_host_distro_release(): | ||
1223 | 123 | return True | ||
1224 | 124 | |||
1225 | 125 | supported_distros = UbuntuDistroInfo().supported() | ||
1226 | 126 | |||
1227 | 127 | try: | ||
1228 | 128 | supported_distros.index(distro) | ||
1229 | 129 | except ValueError: | ||
1230 | 130 | return False | ||
1231 | 131 | |||
1232 | 132 | return True | ||
1233 | 133 | |||
1234 | 134 | |||
1235 | 135 | def get_distro_codename(distro): | ||
1236 | 136 | ubuntu_distro_info = UbuntuDistroInfo() | ||
1237 | 137 | |||
1238 | 138 | for row in ubuntu_distro_info._rows: | ||
1239 | 139 | if row['series'] == distro: | ||
1240 | 140 | return row['codename'] | ||
1241 | 141 | |||
1242 | 142 | return None | ||
1243 | 143 | |||
1244 | 144 | |||
1245 | 145 | def update_container_install_status(container_id, new_status): | ||
1246 | 146 | container_list = read_container_config_file() | ||
1247 | 147 | |||
1248 | 148 | for container in container_list['containerList']: | ||
1249 | 149 | if container['id'] == container_id: | ||
1250 | 150 | container['installStatus'] = new_status | ||
1251 | 151 | |||
1252 | 152 | write_container_config_file(container_list) | ||
1253 | 153 | break | ||
1254 | 154 | |||
1255 | 155 | |||
1256 | 156 | def update_container_multiarch_support(container_id, multiarch): | ||
1257 | 157 | container_list = read_container_config_file() | ||
1258 | 158 | |||
1259 | 159 | if multiarch == 'enabled' and libertine.utils.get_host_architecture() == 'i386': | ||
1260 | 160 | multiarch = 'disabled' | ||
1261 | 161 | |||
1262 | 162 | for container in container_list['containerList']: | ||
1263 | 163 | if container['id'] == container_id: | ||
1264 | 164 | container['multiarch'] = multiarch | ||
1265 | 165 | |||
1266 | 166 | write_container_config_file(container_list) | ||
1267 | 167 | break | ||
1268 | 168 | |||
1269 | 169 | |||
1270 | 170 | def get_container_multiarch_support(container_id): | ||
1271 | 171 | container_list = read_container_config_file() | ||
1272 | 172 | |||
1273 | 173 | for container in container_list['containerList']: | ||
1274 | 174 | if container['id'] == container_id: | ||
1275 | 175 | if not 'multiarch' in container: | ||
1276 | 176 | return 'disabled' | ||
1277 | 177 | else: | ||
1278 | 178 | return container['multiarch'] | ||
1279 | 179 | |||
1280 | 180 | |||
1281 | 181 | def update_archive_install_status(container_id, archive_name, new_status): | ||
1282 | 182 | container_list = read_container_config_file() | ||
1283 | 183 | |||
1284 | 184 | for container in container_list['containerList']: | ||
1285 | 185 | if container['id'] == container_id: | ||
1286 | 186 | for archive in container['extraArchives']: | ||
1287 | 187 | if archive['archiveName'] == archive_name: | ||
1288 | 188 | archive['archiveStatus'] = new_status | ||
1289 | 189 | write_container_config_file(container_list) | ||
1290 | 190 | return | ||
1291 | 191 | |||
1292 | 192 | |||
1293 | 193 | def add_container_archive(container_id, archive_name): | ||
1294 | 194 | container_list = read_container_config_file() | ||
1295 | 195 | |||
1296 | 196 | for container in container_list['containerList']: | ||
1297 | 197 | if container['id'] == container_id: | ||
1298 | 198 | archive_obj = {'archiveName': archive_name, 'archiveStatus': 'new'} | ||
1299 | 199 | |||
1300 | 200 | if 'extraArchives' not in container: | ||
1301 | 201 | container['extraArchives'] = [archive_obj] | ||
1302 | 202 | else: | ||
1303 | 203 | container['extraArchives'].append(archive_obj) | ||
1304 | 204 | |||
1305 | 205 | write_container_config_file(container_list) | ||
1306 | 206 | break | ||
1307 | 207 | |||
1308 | 208 | |||
1309 | 209 | def delete_container_archive(container_id, archive_name): | ||
1310 | 210 | container_list = read_container_config_file() | ||
1311 | 211 | |||
1312 | 212 | for container in container_list['containerList']: | ||
1313 | 213 | if container['id'] == container_id: | ||
1314 | 214 | for archive in container['extraArchives']: | ||
1315 | 215 | if archive['archiveName'] == archive_name: | ||
1316 | 216 | container['extraArchives'].remove(archive) | ||
1317 | 217 | write_container_config_file(container_list) | ||
1318 | 218 | return | ||
1319 | 219 | |||
1320 | 220 | print("%s does not exist." % archive_name) | ||
1321 | 221 | sys.exit(1) | ||
1322 | 222 | |||
1323 | 223 | |||
1324 | 224 | def archive_exists(container_id, archive_name): | ||
1325 | 225 | container_list = read_container_config_file() | ||
1326 | 226 | |||
1327 | 227 | for container in container_list['containerList']: | ||
1328 | 228 | if container['id'] == container_id: | ||
1329 | 229 | if 'extraArchives' not in container: | ||
1330 | 230 | return False | ||
1331 | 231 | else: | ||
1332 | 232 | for archive in container['extraArchives']: | ||
1333 | 233 | if archive['archiveName'] == archive_name: | ||
1334 | 234 | return True | ||
1335 | 235 | |||
1336 | 236 | return False | ||
1337 | 237 | |||
1338 | 238 | |||
1339 | 239 | def add_new_container(id, name, type, distro): | ||
1340 | 240 | if not os.path.exists(libertine.utils.get_libertine_database_dir_path()): | ||
1341 | 241 | os.makedirs(libertine.utils.get_libertine_database_dir_path()) | ||
1342 | 242 | |||
1343 | 243 | container_list = read_container_config_file() | ||
1344 | 244 | |||
1345 | 245 | container_obj = {'id': id, 'installStatus': 'new', 'type': type, | ||
1346 | 246 | 'distro': distro, 'name': name, 'installedApps': []} | ||
1347 | 247 | |||
1348 | 248 | if "defaultContainer" not in container_list: | ||
1349 | 249 | container_list['defaultContainer'] = id | ||
1350 | 250 | |||
1351 | 251 | if "containerList" not in container_list: | ||
1352 | 252 | container_list['containerList'] = [container_obj] | ||
1353 | 253 | else: | ||
1354 | 254 | container_list['containerList'].append(container_obj) | ||
1355 | 255 | |||
1356 | 256 | write_container_config_file(container_list) | ||
1357 | 257 | |||
1358 | 258 | |||
1359 | 259 | def delete_container(container_id): | ||
1360 | 260 | container_list = read_container_config_file() | ||
1361 | 261 | |||
1362 | 262 | if not container_list: | ||
1363 | 263 | print("Unable to delete container. No containers defined.") | ||
1364 | 264 | sys.exit(1) | ||
1365 | 265 | |||
1366 | 266 | for container in container_list['containerList']: | ||
1367 | 267 | if container['id'] == container_id: | ||
1368 | 268 | container_list['containerList'].remove(container) | ||
1369 | 269 | |||
1370 | 270 | # Set a new defaultContainer if the current default is being deleted. | ||
1371 | 271 | if container_list['defaultContainer'] == container_id and container_list['containerList']: | ||
1372 | 272 | container_list['defaultContainer'] = container_list['containerList'][0]['id'] | ||
1373 | 273 | # Remove the defaultContainer if there are no more containers left. | ||
1374 | 274 | elif not container_list['containerList']: | ||
1375 | 275 | del container_list['defaultContainer'] | ||
1376 | 276 | |||
1377 | 277 | write_container_config_file(container_list) | ||
1378 | 278 | break | ||
1379 | 279 | |||
1380 | 280 | |||
1381 | 281 | def package_exists(container_id, package_name): | ||
1382 | 282 | container_list = read_container_config_file() | ||
1383 | 283 | |||
1384 | 284 | if not container_list: | ||
1385 | 285 | return False | ||
1386 | 286 | |||
1387 | 287 | for container in container_list['containerList']: | ||
1388 | 288 | if container['id'] == container_id: | ||
1389 | 289 | for package in container['installedApps']: | ||
1390 | 290 | if package['packageName'] == package_name: | ||
1391 | 291 | return True | ||
1392 | 292 | |||
1393 | 293 | return False | ||
1394 | 294 | |||
1395 | 295 | |||
1396 | 296 | def update_package_install_status(container_id, package_name, new_status): | ||
1397 | 297 | container_list = read_container_config_file() | ||
1398 | 298 | |||
1399 | 299 | for container in container_list['containerList']: | ||
1400 | 300 | if container['id'] == container_id: | ||
1401 | 301 | for package in container['installedApps']: | ||
1402 | 302 | if package['packageName'] == package_name: | ||
1403 | 303 | package['appStatus'] = new_status | ||
1404 | 304 | write_container_config_file(container_list) | ||
1405 | 305 | return | ||
1406 | 306 | |||
1407 | 307 | |||
1408 | 308 | def get_package_install_status(container_id, package_name): | ||
1409 | 309 | container_list = read_container_config_file() | ||
1410 | 310 | |||
1411 | 311 | for container in container_list['containerList']: | ||
1412 | 312 | if container['id'] == container_id: | ||
1413 | 313 | for package in container['installedApps']: | ||
1414 | 314 | if package['packageName'] == package_name: | ||
1415 | 315 | return package['appStatus'] | ||
1416 | 316 | |||
1417 | 317 | |||
1418 | 318 | def add_new_package(container_id, package_name): | ||
1419 | 319 | container_list = read_container_config_file() | ||
1420 | 320 | |||
1421 | 321 | if not container_list: | ||
1422 | 322 | print("No containers defined. Please create a new container before installing a package.") | ||
1423 | 323 | sys.exit(1) | ||
1424 | 324 | |||
1425 | 325 | for container in container_list['containerList']: | ||
1426 | 326 | if container['id'] == container_id: | ||
1427 | 327 | package_obj = {'packageName': package_name, 'appStatus': 'new'} | ||
1428 | 328 | |||
1429 | 329 | if not container['installedApps']: | ||
1430 | 330 | container['installedApps'] = [package_obj] | ||
1431 | 331 | else: | ||
1432 | 332 | container['installedApps'].append(package_obj) | ||
1433 | 333 | |||
1434 | 334 | write_container_config_file(container_list) | ||
1435 | 335 | break | ||
1436 | 336 | |||
1437 | 337 | |||
1438 | 338 | def delete_package(container_id, package_name): | ||
1439 | 339 | container_list = read_container_config_file() | ||
1440 | 340 | |||
1441 | 341 | if not container_list: | ||
1442 | 342 | print("No containers defined. Please create a new container before installing a package.") | ||
1443 | 343 | sys.exit(1) | ||
1444 | 344 | |||
1445 | 345 | for container in container_list['containerList']: | ||
1446 | 346 | if container['id'] == container_id: | ||
1447 | 347 | for package in container['installedApps']: | ||
1448 | 348 | if package['packageName'] == package_name: | ||
1449 | 349 | container['installedApps'].remove(package) | ||
1450 | 350 | write_container_config_file(container_list) | ||
1451 | 351 | return | ||
1452 | 352 | |||
1453 | 353 | print("Package \'%s\' does not exist." % package_name) | ||
1454 | 354 | sys.exit(1) | ||
1455 | 355 | |||
1456 | 356 | |||
1457 | 357 | def create(args): | ||
1458 | 358 | password = None | ||
1459 | 359 | |||
1460 | 360 | if args.distro and not is_distro_valid(args.distro, args.force): | ||
1461 | 361 | print("Invalid distro %s" % args.distro, file=sys.stderr) | ||
1462 | 362 | sys.exit(1) | ||
1463 | 363 | |||
1464 | 364 | if args.id and libertine.utils.container_exists(args.id): | ||
1465 | 365 | print("Container id \'%s\' is already used." % args.id, file=sys.stderr) | ||
1466 | 366 | sys.exit(1) | ||
1467 | 367 | elif not args.id: | ||
1468 | 368 | args.id = get_unique_container_id(distro) | ||
1469 | 369 | |||
1470 | 370 | if not args.type: | ||
1471 | 371 | container_type = select_container_type() | ||
1472 | 372 | else: | ||
1473 | 373 | container_type = args.type | ||
1474 | 374 | |||
1475 | 375 | if not args.distro: | ||
1476 | 376 | args.distro = get_host_distro_release() | ||
1477 | 377 | elif container_type == "chroot": | ||
1478 | 378 | host_distro = get_host_distro_release() | ||
1479 | 379 | |||
1480 | 380 | if args.distro != host_distro: | ||
1481 | 381 | print("The container distribution needs to match the host ditribution for chroot" | ||
1482 | 382 | " based containers. Please either use \'%s\' or omit the -d/--distro option." | ||
1483 | 383 | % host_distro) | ||
1484 | 384 | sys.exit(1) | ||
1485 | 385 | |||
1486 | 386 | if not args.name: | ||
1487 | 387 | args.name = "Ubuntu \'" + get_distro_codename(args.distro) + "\'" | ||
1488 | 388 | |||
1489 | 389 | if container_type == "lxc": | ||
1490 | 390 | if args.password: | ||
1491 | 391 | password = args.password | ||
1492 | 392 | elif sys.stdin.isatty(): | ||
1493 | 393 | print("Your user password is required for creating a Libertine container.") | ||
1494 | 394 | password = getpass.getpass() | ||
1495 | 395 | else: | ||
1496 | 396 | password = sys.stdin.readline().rstrip() | ||
1497 | 397 | |||
1498 | 398 | add_new_container(args.id, args.name, container_type, args.distro) | ||
1499 | 399 | |||
1500 | 400 | multiarch = 'disabled' | ||
1501 | 401 | if args.multiarch: | ||
1502 | 402 | multiarch = 'enabled' | ||
1503 | 403 | update_container_multiarch_support(args.id, multiarch) | ||
1504 | 404 | |||
1505 | 405 | container = LibertineContainer(args.id) | ||
1506 | 406 | update_container_install_status(args.id, "installing") | ||
1507 | 407 | if not container.create_libertine_container(password, args.multiarch, args.verbosity): | ||
1508 | 408 | delete_container(args.id) | ||
1509 | 409 | sys.exit(1) | ||
1510 | 410 | update_container_install_status(args.id, "ready") | ||
1511 | 411 | |||
1512 | 412 | libertine.utils.refresh_libertine_scope() | ||
1513 | 413 | |||
1514 | 414 | |||
1515 | 415 | def destroy_container_by_id(id): | ||
1516 | 416 | container = LibertineContainer(id) | ||
1517 | 417 | update_container_install_status(id, "removing") | ||
1518 | 418 | container.destroy_libertine_container() | ||
1519 | 419 | update_container_install_status(id, "removed") | ||
1520 | 420 | delete_container(id) | ||
1521 | 421 | |||
1522 | 422 | |||
1523 | 423 | def destroy(args): | ||
1524 | 424 | if args.id and not libertine.utils.container_exists(args.id): | ||
1525 | 425 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1526 | 426 | sys.exit(1) | ||
1527 | 427 | elif not args.id: | ||
1528 | 428 | args.id = get_default_container_id() | ||
1529 | 429 | |||
1530 | 430 | destroy_container_by_id(args.id) | ||
1531 | 431 | |||
1532 | 432 | libertine.utils.refresh_libertine_scope() | ||
1533 | 433 | |||
1534 | 434 | |||
1535 | 435 | def install_package(args): | ||
1536 | 436 | if args.id and not libertine.utils.container_exists(args.id): | ||
1537 | 437 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1538 | 438 | sys.exit(1) | ||
1539 | 439 | elif not args.id: | ||
1540 | 440 | args.id = get_default_container_id() | ||
1541 | 441 | |||
1542 | 442 | is_debian_package = args.package.endswith('.deb') | ||
1543 | 443 | |||
1544 | 444 | if is_debian_package: | ||
1545 | 445 | if os.path.exists(args.package): | ||
1546 | 446 | package = DebPackage(args.package).pkgname | ||
1547 | 447 | else: | ||
1548 | 448 | print("%s does not exist." % args.package) | ||
1549 | 449 | sys.exit(1) | ||
1550 | 450 | else: | ||
1551 | 451 | package = args.package | ||
1552 | 452 | |||
1553 | 453 | if package_exists(args.id, package): | ||
1554 | 454 | if not is_debian_package: | ||
1555 | 455 | print("Package \'%s\' is already installed." % package) | ||
1556 | 456 | sys.exit(1) | ||
1557 | 457 | else: | ||
1558 | 458 | add_new_package(args.id, package) | ||
1559 | 459 | |||
1560 | 460 | container = LibertineContainer(args.id) | ||
1561 | 461 | |||
1562 | 462 | update_package_install_status(args.id, package, "installing") | ||
1563 | 463 | if not container.install_package(args.package, args.verbosity, args.readline): | ||
1564 | 464 | delete_package(args.id, package) | ||
1565 | 465 | sys.exit(1) | ||
1566 | 466 | |||
1567 | 467 | update_package_install_status(args.id, package, "installed") | ||
1568 | 468 | |||
1569 | 469 | libertine.utils.refresh_libertine_scope() | ||
1570 | 470 | |||
1571 | 471 | |||
1572 | 472 | def remove_package_by_name(container_id, package_name, verbosity=1, readline=False): | ||
1573 | 473 | fallback_status = get_package_install_status(container_id, package_name) | ||
1574 | 474 | update_package_install_status(container_id, package_name, "removing") | ||
1575 | 475 | |||
1576 | 476 | container = LibertineContainer(container_id) | ||
1577 | 477 | if not container.remove_package(package_name, verbosity, readline): | ||
1578 | 478 | update_package_install_status(container_id, package_name, fallback_status) | ||
1579 | 479 | return False | ||
1580 | 480 | |||
1581 | 481 | update_package_install_status(container_id, package_name, "removed") | ||
1582 | 482 | delete_package(container_id, package_name) | ||
1583 | 483 | |||
1584 | 484 | return True | ||
1585 | 485 | |||
1586 | 486 | |||
1587 | 487 | def remove_package(args): | ||
1588 | 488 | if args.id and not libertine.utils.container_exists(args.id): | ||
1589 | 489 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1590 | 490 | sys.exit(1) | ||
1591 | 491 | elif not args.id: | ||
1592 | 492 | args.id = get_default_container_id() | ||
1593 | 493 | |||
1594 | 494 | if get_package_install_status(args.id, args.package) != 'installed': | ||
1595 | 495 | print("Package \'%s\' is not installed." % args.package) | ||
1596 | 496 | sys.exit(1) | ||
1597 | 497 | |||
1598 | 498 | if not remove_package_by_name(args.id, args.package, args.verbosity, args.readline): | ||
1599 | 499 | sys.exit(1) | ||
1600 | 500 | |||
1601 | 501 | libertine.utils.refresh_libertine_scope() | ||
1602 | 502 | |||
1603 | 503 | |||
1604 | 504 | def search_cache(args): | ||
1605 | 505 | if args.id and not libertine.utils.container_exists(args.id): | ||
1606 | 506 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1607 | 507 | sys.exit(1) | ||
1608 | 508 | elif not args.id: | ||
1609 | 509 | args.id = get_default_container_id() | ||
1610 | 510 | |||
1611 | 511 | container = LibertineContainer(args.id) | ||
1612 | 512 | if container.search_package_cache(args.search_string) is not 0: | ||
1613 | 513 | sys.exit(1) | ||
1614 | 514 | |||
1615 | 515 | |||
1616 | 516 | def update(args): | ||
1617 | 517 | if args.id and not libertine.utils.container_exists(args.id): | ||
1618 | 518 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1619 | 519 | sys.exit(1) | ||
1620 | 520 | elif not args.id: | ||
1621 | 521 | args.id = get_default_container_id() | ||
1622 | 522 | |||
1623 | 523 | container = LibertineContainer(args.id) | ||
1624 | 524 | |||
1625 | 525 | update_container_install_status(args.id, "updating") | ||
1626 | 526 | if container.update_libertine_container(args.verbosity) is not 0: | ||
1627 | 527 | update_container_install_status(args.id, "ready") | ||
1628 | 528 | sys.exit(1) | ||
1629 | 529 | |||
1630 | 530 | update_container_install_status(args.id, "ready") | ||
1631 | 531 | |||
1632 | 532 | |||
1633 | 533 | def list(args): | ||
1634 | 534 | containers = libertine.utils.Libertine.list_containers() | ||
1635 | 535 | for container in containers: | ||
1636 | 536 | print("%s" % container) | ||
1637 | 537 | |||
1638 | 538 | |||
1639 | 539 | def list_apps(args): | ||
1640 | 540 | if args.id and not libertine.utils.container_exists(args.id): | ||
1641 | 541 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1642 | 542 | sys.exit(1) | ||
1643 | 543 | elif not args.id: | ||
1644 | 544 | args.id = get_default_container_id() | ||
1645 | 545 | |||
1646 | 546 | container = LibertineContainer(args.id) | ||
1647 | 547 | print(container.list_app_launchers(use_json=args.json)) | ||
1648 | 548 | |||
1649 | 549 | |||
1650 | 550 | def exec(args): | ||
1651 | 551 | if args.id and not libertine.utils.container_exists(args.id): | ||
1652 | 552 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1653 | 553 | sys.exit(1) | ||
1654 | 554 | elif not args.id: | ||
1655 | 555 | args.id = get_default_container_id() | ||
1656 | 556 | |||
1657 | 557 | container = LibertineContainer(args.id) | ||
1658 | 558 | |||
1659 | 559 | if not container.exec_command(args.command): | ||
1660 | 560 | sys.exit(1) | ||
1661 | 561 | |||
1662 | 562 | |||
1663 | 563 | def delete_archive_by_name(container_id, archive_name): | ||
1664 | 564 | update_archive_install_status(container_id, archive_name, 'removing') | ||
1665 | 565 | if LibertineContainer(container_id).configure_command('delete-archive', archive_name) is not 0: | ||
1666 | 566 | return False | ||
1667 | 567 | delete_container_archive(container_id, archive_name) | ||
1668 | 568 | return True | ||
1669 | 569 | |||
1670 | 570 | |||
1671 | 571 | def configure(args): | ||
1672 | 572 | if args.id and not libertine.utils.container_exists(args.id): | ||
1673 | 573 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | ||
1674 | 574 | sys.exit(1) | ||
1675 | 575 | elif not args.id: | ||
1676 | 576 | args.id = get_default_container_id() | ||
1677 | 577 | |||
1678 | 578 | container = LibertineContainer(args.id) | ||
1679 | 579 | |||
1680 | 580 | if args.multiarch and libertine.utils.get_host_architecture() == 'amd64': | ||
1738 | 581 | multiarch = 'disabled' | 84 | multiarch = 'disabled' |
1739 | 582 | if args.multiarch == 'enable': | 85 | if args.multiarch == 'enable': |
1740 | 583 | multiarch = 'enabled' | 86 | multiarch = 'enabled' |
1808 | 584 | 87 | self.containers_config.update_container_multiarch_support(args.id, multiarch) | |
1809 | 585 | current_multiarch = get_container_multiarch_support(args.id) | 88 | |
1810 | 586 | if current_multiarch == multiarch: | 89 | container = LibertineContainer(args.id) |
1811 | 587 | print("i386 multiarch support is already %s" % multiarch) | 90 | self.containers_config.update_container_install_status(args.id, "installing") |
1812 | 588 | sys.exit(1) | 91 | if not container.create_libertine_container(password, args.multiarch, args.verbosity): |
1813 | 589 | 92 | self.containers_config.delete_container(args.id) | |
1814 | 590 | if container.configure_command('multiarch', args.multiarch) is not 0: | 93 | sys.exit(1) |
1815 | 591 | sys.exit(1) | 94 | self.containers_config.update_container_install_status(args.id, "ready") |
1816 | 592 | 95 | ||
1817 | 593 | update_container_multiarch_support(args.id, multiarch) | 96 | libertine.utils.refresh_libertine_scope() |
1818 | 594 | 97 | ||
1819 | 595 | elif args.add_archive: | 98 | def destroy_container_by_id(self, id): |
1820 | 596 | if archive_exists(args.id, args.add_archive): | 99 | container = LibertineContainer(id) |
1821 | 597 | print("%s already added in container." % args.add_archive) | 100 | |
1822 | 598 | sys.exit(1) | 101 | self.containers_config.update_container_install_status(id, "removing") |
1823 | 599 | 102 | container.destroy_libertine_container() | |
1824 | 600 | add_container_archive(args.id, args.add_archive) | 103 | self.containers_config.update_container_install_status(id, "removed") |
1825 | 601 | update_archive_install_status(args.id, args.add_archive, 'installing') | 104 | self.containers_config.delete_container(id) |
1826 | 602 | if container.configure_command('add-archive', args.add_archive) is not 0: | 105 | |
1827 | 603 | delete_container_archive(args.id, args.add_archive) | 106 | def destroy(self, args): |
1828 | 604 | sys.exit(1) | 107 | args.id = self.containers_config.check_container_id(args.id) |
1829 | 605 | 108 | ||
1830 | 606 | update_archive_install_status(args.id, args.add_archive, 'installed') | 109 | self.destroy_container_by_id(args.id) |
1831 | 607 | 110 | ||
1832 | 608 | elif args.delete_archive: | 111 | libertine.utils.refresh_libertine_scope() |
1833 | 609 | if not archive_exists(args.id, args.delete_archive): | 112 | |
1834 | 610 | print("%s is not added in container." % args.delete_archive) | 113 | def install_package(self, args): |
1835 | 611 | sys.exit(1) | 114 | container_id = self.containers_config.check_container_id(args.id) |
1836 | 612 | 115 | ||
1837 | 613 | if not delete_archive_by_name(args.id, args.delete_archive): | 116 | is_debian_package = args.package.endswith('.deb') |
1838 | 614 | sys.exit(1) | 117 | |
1839 | 615 | 118 | if is_debian_package: | |
1840 | 616 | 119 | if os.path.exists(args.package): | |
1841 | 617 | def merge(args): | 120 | package = DebPackage(args.package).pkgname |
1842 | 618 | merge_container_config_files(args.file) | 121 | else: |
1843 | 619 | 122 | print("%s does not exist." % args.package) | |
1844 | 620 | 123 | sys.exit(1) | |
1845 | 621 | def fix_integrity(args): | 124 | else: |
1846 | 622 | for container in read_container_config_file()['containerList']: | 125 | package = args.package |
1847 | 623 | if container['installStatus'] != 'ready': | 126 | |
1848 | 624 | destroy_container_by_id(container['id']) | 127 | if self.containers_config.package_exists(container_id, package): |
1849 | 625 | continue | 128 | if not is_debian_package: |
1850 | 626 | LibertineContainer(container['id']).exec_command('dpkg --configure -a') | 129 | print("Package \'%s\' is already installed." % package) |
1851 | 627 | 130 | sys.exit(1) | |
1852 | 628 | for package in container['installedApps']: | 131 | else: |
1853 | 629 | if package['appStatus'] != 'installed': | 132 | self.containers_config.add_new_package(container_id, package) |
1854 | 630 | remove_package_by_name(container['id'], package['packageName']) | 133 | |
1855 | 631 | if 'extraArchives' in container: | 134 | container = LibertineContainer(container_id) |
1856 | 632 | for archive in container['extraArchives']: | 135 | |
1857 | 633 | if archive['archiveStatus'] != 'installed': | 136 | self.containers_config.update_package_install_status(container_id, package, "installing") |
1858 | 634 | delete_archive_by_name(container['id'], archive['archiveName']) | 137 | if not container.install_package(args.package, args.verbosity, args.readline): |
1859 | 635 | 138 | self.containers_config.delete_package(container_id, package) | |
1860 | 636 | 139 | sys.exit(1) | |
1861 | 637 | def set_default(args): | 140 | |
1862 | 638 | if args.clear: | 141 | self.containers_config.update_package_install_status(container_id, package, "installed") |
1863 | 639 | container_list = read_container_config_file() | 142 | |
1864 | 640 | container_list.pop('defaultContainer', None) | 143 | libertine.utils.refresh_libertine_scope() |
1865 | 641 | write_container_config_file(container_list) | 144 | |
1866 | 642 | sys.exit(0) | 145 | def remove_package_by_name(self, container_id, package_name, verbosity=1, readline=False): |
1867 | 643 | 146 | fallback_status = self.containers_config.get_package_install_status(container_id, package_name) | |
1868 | 644 | if not libertine.utils.container_exists(args.id): | 147 | self.containers_config.update_package_install_status(container_id, package_name, "removing") |
1869 | 645 | print("Container id \'%s\' does not exist." % args.id, file=sys.stderr) | 148 | |
1870 | 646 | sys.exit(1) | 149 | container = LibertineContainer(container_id) |
1871 | 647 | 150 | if not container.remove_package(package_name, verbosity, readline) and fallback_status == 'installed': | |
1872 | 648 | container_list = read_container_config_file() | 151 | self.containers_config.update_package_install_status(container_id, package_name, fallback_status) |
1873 | 649 | container_list['defaultContainer'] = args.id | 152 | return False |
1874 | 650 | write_container_config_file(container_list) | 153 | |
1875 | 154 | self.containers_config.update_package_install_status(container_id, package_name, "removed") | ||
1876 | 155 | self.containers_config.delete_package(container_id, package_name) | ||
1877 | 156 | |||
1878 | 157 | return True | ||
1879 | 158 | |||
1880 | 159 | def remove_package(self, args): | ||
1881 | 160 | container_id = self.containers_config.check_container_id(args.id) | ||
1882 | 161 | |||
1883 | 162 | if self.containers_config.get_package_install_status(container_id, args.package) != 'installed': | ||
1884 | 163 | print("Package \'%s\' is not installed." % args.package) | ||
1885 | 164 | sys.exit(1) | ||
1886 | 165 | |||
1887 | 166 | if not self.remove_package_by_name(container_id, args.package, args.verbosity, args.readline): | ||
1888 | 167 | sys.exit(1) | ||
1889 | 168 | |||
1890 | 169 | libertine.utils.refresh_libertine_scope() | ||
1891 | 170 | |||
1892 | 171 | def search_cache(self, args): | ||
1893 | 172 | container_id = self.containers_config.check_container_id(args.id) | ||
1894 | 173 | |||
1895 | 174 | container = LibertineContainer(container_id) | ||
1896 | 175 | if container.search_package_cache(args.search_string) is not 0: | ||
1897 | 176 | sys.exit(1) | ||
1898 | 177 | |||
1899 | 178 | def update(self, args): | ||
1900 | 179 | container_id = self.containers_config.check_container_id(args.id) | ||
1901 | 180 | |||
1902 | 181 | container = LibertineContainer(container_id) | ||
1903 | 182 | |||
1904 | 183 | self.containers_config.update_container_install_status(container_id, "updating") | ||
1905 | 184 | if container.update_libertine_container(args.verbosity) is not 0: | ||
1906 | 185 | self.containers_config.update_container_install_status(container_id, "ready") | ||
1907 | 186 | sys.exit(1) | ||
1908 | 187 | |||
1909 | 188 | self.containers_config.update_container_install_status(container_id, "ready") | ||
1910 | 189 | |||
1911 | 190 | def list(self, args): | ||
1912 | 191 | containers = libertine.utils.Libertine.list_containers() | ||
1913 | 192 | for container in containers: | ||
1914 | 193 | print("%s" % container) | ||
1915 | 194 | |||
1916 | 195 | def list_apps(self, args): | ||
1917 | 196 | container_id = self.containers_config.check_container_id(args.id) | ||
1918 | 197 | |||
1919 | 198 | container = LibertineContainer(container_id) | ||
1920 | 199 | print(container.list_app_launchers(use_json=args.json)) | ||
1921 | 200 | |||
1922 | 201 | def exec(self, args): | ||
1923 | 202 | container_id = self.containers_config.check_container_id(args.id) | ||
1924 | 203 | |||
1925 | 204 | container = LibertineContainer(container_id) | ||
1926 | 205 | |||
1927 | 206 | if not container.exec_command(args.command): | ||
1928 | 207 | sys.exit(1) | ||
1929 | 208 | |||
1930 | 209 | def delete_archive_by_name(self, container_id, archive_name): | ||
1931 | 210 | self.containers_config.update_archive_install_status(container_id, archive_name, 'removing') | ||
1932 | 211 | if LibertineContainer(container_id).configure_command('delete-archive', archive_name) is not 0: | ||
1933 | 212 | return False | ||
1934 | 213 | self.containers_config.delete_container_archive(container_id, archive_name) | ||
1935 | 214 | return True | ||
1936 | 215 | |||
1937 | 216 | def configure(self, args): | ||
1938 | 217 | container_id = self.containers_config.check_container_id(args.id) | ||
1939 | 218 | |||
1940 | 219 | container = LibertineContainer(container_id) | ||
1941 | 220 | |||
1942 | 221 | if args.multiarch and self.host_info.get_host_architecture() == 'amd64': | ||
1943 | 222 | multiarch = 'disabled' | ||
1944 | 223 | if args.multiarch == 'enable': | ||
1945 | 224 | multiarch = 'enabled' | ||
1946 | 225 | |||
1947 | 226 | current_multiarch = self.containers_config.get_container_multiarch_support(container_id) | ||
1948 | 227 | if current_multiarch == multiarch: | ||
1949 | 228 | print("i386 multiarch support is already %s" % multiarch) | ||
1950 | 229 | sys.exit(1) | ||
1951 | 230 | |||
1952 | 231 | if container.configure_command('multiarch', args.multiarch) is not 0: | ||
1953 | 232 | sys.exit(1) | ||
1954 | 233 | |||
1955 | 234 | self.containers_config.update_container_multiarch_support(container_id, multiarch) | ||
1956 | 235 | |||
1957 | 236 | elif args.add_archive: | ||
1958 | 237 | if self.containers_config.archive_exists(container_id, args.add_archive): | ||
1959 | 238 | print("%s already added in container." % args.add_archive) | ||
1960 | 239 | sys.exit(1) | ||
1961 | 240 | |||
1962 | 241 | self.containers_config.add_container_archive(container_id, args.add_archive) | ||
1963 | 242 | self.containers_config.update_archive_install_status(container_id, args.add_archive, 'installing') | ||
1964 | 243 | if container.configure_command('add-archive', args.add_archive) is not 0: | ||
1965 | 244 | self.containers_config.delete_container_archive(container_id, args.add_archive) | ||
1966 | 245 | sys.exit(1) | ||
1967 | 246 | |||
1968 | 247 | self.containers_config.update_archive_install_status(container_id, args.add_archive, 'installed') | ||
1969 | 248 | |||
1970 | 249 | elif args.delete_archive: | ||
1971 | 250 | if not self.containers_config.archive_exists(container_id, args.delete_archive): | ||
1972 | 251 | print("%s is not added in container." % args.delete_archive) | ||
1973 | 252 | sys.exit(1) | ||
1974 | 253 | |||
1975 | 254 | if not self.delete_archive_by_name(container_id, args.delete_archive): | ||
1976 | 255 | sys.exit(1) | ||
1977 | 256 | |||
1978 | 257 | def merge(self, args): | ||
1979 | 258 | self.containers_config.merge_container_config_files(args.file) | ||
1980 | 259 | |||
1981 | 260 | def fix_integrity(self, args): | ||
1982 | 261 | for container in self.containers_config.container_list['containerList']: | ||
1983 | 262 | if 'installStatus' not in container or container['installStatus'] != 'ready': | ||
1984 | 263 | self.destroy_container_by_id(container['id']) | ||
1985 | 264 | continue | ||
1986 | 265 | LibertineContainer(container['id']).exec_command('dpkg --configure -a') | ||
1987 | 266 | |||
1988 | 267 | for package in container['installedApps']: | ||
1989 | 268 | if package['appStatus'] != 'installed': | ||
1990 | 269 | self.remove_package_by_name(container['id'], package['packageName']) | ||
1991 | 270 | |||
1992 | 271 | if 'extraArchives' in container: | ||
1993 | 272 | for archive in container['extraArchives']: | ||
1994 | 273 | if archive['archiveStatus'] != 'installed': | ||
1995 | 274 | self.delete_archive_by_name(container['id'], archive['archiveName']) | ||
1996 | 275 | |||
1997 | 276 | def set_default(self, args): | ||
1998 | 277 | if args.clear: | ||
1999 | 278 | self.containers_config.clear_default_container_id(True) | ||
2000 | 279 | sys.exit(0) | ||
2001 | 280 | |||
2002 | 281 | container_id = self.containers_config.check_container_id(args.id) | ||
2003 | 282 | |||
2004 | 283 | self.containers_config.set_default_container_id(container_id, True) | ||
2005 | 651 | 284 | ||
2006 | 652 | 285 | ||
2007 | 653 | if __name__ == '__main__': | 286 | if __name__ == '__main__': |
2008 | @@ -657,6 +290,8 @@ | |||
2009 | 657 | print("Please do not run %s using sudo" % parser.prog) | 290 | print("Please do not run %s using sudo" % parser.prog) |
2010 | 658 | sys.exit(1) | 291 | sys.exit(1) |
2011 | 659 | 292 | ||
2012 | 293 | container_manager = LibertineContainerManager() | ||
2013 | 294 | |||
2014 | 660 | parser.add_argument('-q', '--quiet', | 295 | parser.add_argument('-q', '--quiet', |
2015 | 661 | action='store_const', dest='verbosity', const=0, | 296 | action='store_const', dest='verbosity', const=0, |
2016 | 662 | help=('do not print status updates on stdout')) | 297 | help=('do not print status updates on stdout')) |
2017 | @@ -696,7 +331,7 @@ | |||
2018 | 696 | '--password', | 331 | '--password', |
2019 | 697 | help=("Pass in the user's password when creating an LXC container. This " | 332 | help=("Pass in the user's password when creating an LXC container. This " |
2020 | 698 | "is intended for testing only and is very insecure.")) | 333 | "is intended for testing only and is very insecure.")) |
2022 | 699 | parser_create.set_defaults(func=create) | 334 | parser_create.set_defaults(func=container_manager.create) |
2023 | 700 | 335 | ||
2024 | 701 | # Handle the destroy command and its options | 336 | # Handle the destroy command and its options |
2025 | 702 | parser_destroy = subparsers.add_parser( | 337 | parser_destroy = subparsers.add_parser( |
2026 | @@ -705,7 +340,7 @@ | |||
2027 | 705 | parser_destroy.add_argument( | 340 | parser_destroy.add_argument( |
2028 | 706 | '-i', '--id', | 341 | '-i', '--id', |
2029 | 707 | help=("Container identifier. Default container is used if omitted.")) | 342 | help=("Container identifier. Default container is used if omitted.")) |
2031 | 708 | parser_destroy.set_defaults(func=destroy) | 343 | parser_destroy.set_defaults(func=container_manager.destroy) |
2032 | 709 | 344 | ||
2033 | 710 | # Handle the install-package command and its options | 345 | # Handle the install-package command and its options |
2034 | 711 | parser_install = subparsers.add_parser( | 346 | parser_install = subparsers.add_parser( |
2035 | @@ -721,7 +356,7 @@ | |||
2036 | 721 | parser_install.add_argument( | 356 | parser_install.add_argument( |
2037 | 722 | '-r', '--readline', action='store_true', | 357 | '-r', '--readline', action='store_true', |
2038 | 723 | help=("Readline mode. Use text-based frontend during debconf interactions.")) | 358 | help=("Readline mode. Use text-based frontend during debconf interactions.")) |
2040 | 724 | parser_install.set_defaults(func=install_package) | 359 | parser_install.set_defaults(func=container_manager.install_package) |
2041 | 725 | 360 | ||
2042 | 726 | # Handle the remove-package command and its options | 361 | # Handle the remove-package command and its options |
2043 | 727 | parser_remove = subparsers.add_parser( | 362 | parser_remove = subparsers.add_parser( |
2044 | @@ -737,7 +372,7 @@ | |||
2045 | 737 | parser_remove.add_argument( | 372 | parser_remove.add_argument( |
2046 | 738 | '-r', '--readline', action='store_true', | 373 | '-r', '--readline', action='store_true', |
2047 | 739 | help=("Readline mode. Use text-based frontend during debconf interactions.")) | 374 | help=("Readline mode. Use text-based frontend during debconf interactions.")) |
2049 | 740 | parser_remove.set_defaults(func=remove_package) | 375 | parser_remove.set_defaults(func=container_manager.remove_package) |
2050 | 741 | 376 | ||
2051 | 742 | # Handle the search-cache command and its options | 377 | # Handle the search-cache command and its options |
2052 | 743 | parser_search = subparsers.add_parser( | 378 | parser_search = subparsers.add_parser( |
2053 | @@ -750,7 +385,7 @@ | |||
2054 | 750 | parser_search.add_argument( | 385 | parser_search.add_argument( |
2055 | 751 | '-i', '--id', | 386 | '-i', '--id', |
2056 | 752 | help=("Container identifier. Default container is used if omitted.")) | 387 | help=("Container identifier. Default container is used if omitted.")) |
2058 | 753 | parser_search.set_defaults(func=search_cache) | 388 | parser_search.set_defaults(func=container_manager.search_cache) |
2059 | 754 | 389 | ||
2060 | 755 | # Handle the update command and its options | 390 | # Handle the update command and its options |
2061 | 756 | parser_update = subparsers.add_parser( | 391 | parser_update = subparsers.add_parser( |
2062 | @@ -759,13 +394,13 @@ | |||
2063 | 759 | parser_update.add_argument( | 394 | parser_update.add_argument( |
2064 | 760 | '-i', '--id', | 395 | '-i', '--id', |
2065 | 761 | help=("Container identifier. Default container is used if omitted.")) | 396 | help=("Container identifier. Default container is used if omitted.")) |
2067 | 762 | parser_update.set_defaults(func=update) | 397 | parser_update.set_defaults(func=container_manager.update) |
2068 | 763 | 398 | ||
2069 | 764 | # Handle the list command | 399 | # Handle the list command |
2070 | 765 | parser_list = subparsers.add_parser( | 400 | parser_list = subparsers.add_parser( |
2071 | 766 | "list", | 401 | "list", |
2072 | 767 | help=("List all Libertine containers.")) | 402 | help=("List all Libertine containers.")) |
2074 | 768 | parser_list.set_defaults(func=list) | 403 | parser_list.set_defaults(func=container_manager.list) |
2075 | 769 | 404 | ||
2076 | 770 | # Handle the list-apps command and its options | 405 | # Handle the list-apps command and its options |
2077 | 771 | parser_list_apps = subparsers.add_parser( | 406 | parser_list_apps = subparsers.add_parser( |
2078 | @@ -778,7 +413,7 @@ | |||
2079 | 778 | '-j', '--json', | 413 | '-j', '--json', |
2080 | 779 | action='store_true', | 414 | action='store_true', |
2081 | 780 | help=("use JSON output format.")) | 415 | help=("use JSON output format.")) |
2083 | 781 | parser_list_apps.set_defaults(func=list_apps) | 416 | parser_list_apps.set_defaults(func=container_manager.list_apps) |
2084 | 782 | 417 | ||
2085 | 783 | # Handle the execute command and it's options | 418 | # Handle the execute command and it's options |
2086 | 784 | parser_exec = subparsers.add_parser( | 419 | parser_exec = subparsers.add_parser( |
2087 | @@ -791,7 +426,7 @@ | |||
2088 | 791 | parser_exec.add_argument( | 426 | parser_exec.add_argument( |
2089 | 792 | '-c', '--command', | 427 | '-c', '--command', |
2090 | 793 | help=("The command to run in the specified container.")) | 428 | help=("The command to run in the specified container.")) |
2092 | 794 | parser_exec.set_defaults(func=exec) | 429 | parser_exec.set_defaults(func=container_manager.exec) |
2093 | 795 | 430 | ||
2094 | 796 | # Handle the configure command and it's options | 431 | # Handle the configure command and it's options |
2095 | 797 | parser_configure = subparsers.add_parser( | 432 | parser_configure = subparsers.add_parser( |
2096 | @@ -816,7 +451,7 @@ | |||
2097 | 816 | metavar='Archive name', | 451 | metavar='Archive name', |
2098 | 817 | help=("Deletes an existing archive (PPA) in the specified Libertine container. " | 452 | help=("Deletes an existing archive (PPA) in the specified Libertine container. " |
2099 | 818 | "Needs to be in the form of \"ppa:user/ppa-name\".")) | 453 | "Needs to be in the form of \"ppa:user/ppa-name\".")) |
2101 | 819 | parser_configure.set_defaults(func=configure) | 454 | parser_configure.set_defaults(func=container_manager.configure) |
2102 | 820 | 455 | ||
2103 | 821 | # Handle merging another ContainersConfig.json file into the main ContainersConfig.json file | 456 | # Handle merging another ContainersConfig.json file into the main ContainersConfig.json file |
2104 | 822 | parser_merge = subparsers.add_parser( | 457 | parser_merge = subparsers.add_parser( |
2105 | @@ -825,13 +460,13 @@ | |||
2106 | 825 | parser_merge.add_argument( | 460 | parser_merge.add_argument( |
2107 | 826 | '-f', '--file', | 461 | '-f', '--file', |
2108 | 827 | required=True) | 462 | required=True) |
2110 | 828 | parser_merge.set_defaults(func=merge) | 463 | parser_merge.set_defaults(func=container_manager.merge) |
2111 | 829 | 464 | ||
2112 | 830 | # Indiscriminately destroy containers, packages, and archives which are not fully installed | 465 | # Indiscriminately destroy containers, packages, and archives which are not fully installed |
2113 | 831 | parser_integrity = subparsers.add_parser( | 466 | parser_integrity = subparsers.add_parser( |
2114 | 832 | 'fix-integrity', | 467 | 'fix-integrity', |
2115 | 833 | add_help=False) | 468 | add_help=False) |
2117 | 834 | parser_integrity.set_defaults(func=fix_integrity) | 469 | parser_integrity.set_defaults(func=container_manager.fix_integrity) |
2118 | 835 | 470 | ||
2119 | 836 | # Set the default container in ContainersConfig | 471 | # Set the default container in ContainersConfig |
2120 | 837 | parser_default = subparsers.add_parser( | 472 | parser_default = subparsers.add_parser( |
2121 | @@ -844,7 +479,7 @@ | |||
2122 | 844 | parser_default.add_argument( | 479 | parser_default.add_argument( |
2123 | 845 | '-c', '--clear', action='store_true', | 480 | '-c', '--clear', action='store_true', |
2124 | 846 | help=("Clear the default container.")) | 481 | help=("Clear the default container.")) |
2126 | 847 | parser_default.set_defaults(func=set_default) | 482 | parser_default.set_defaults(func=container_manager.set_default) |
2127 | 848 | 483 | ||
2128 | 849 | # Actually parse the args | 484 | # Actually parse the args |
2129 | 850 | args = parser.parse_args() | 485 | args = parser.parse_args() |
2130 | 851 | 486 | ||
2131 | === modified file 'tools/libertine-launch' | |||
2132 | --- tools/libertine-launch 2016-05-10 20:17:44 +0000 | |||
2133 | +++ tools/libertine-launch 2016-07-07 20:14:07 +0000 | |||
2134 | @@ -18,21 +18,24 @@ | |||
2135 | 18 | 18 | ||
2136 | 19 | import argparse | 19 | import argparse |
2137 | 20 | import os | 20 | import os |
2138 | 21 | import random | ||
2139 | 22 | import string | ||
2140 | 21 | import libertine.utils | 23 | import libertine.utils |
2141 | 22 | import psutil | 24 | import psutil |
2142 | 23 | import shlex | 25 | import shlex |
2143 | 24 | import time | 26 | import time |
2144 | 27 | |||
2145 | 25 | from libertine import LibertineContainer | 28 | from libertine import LibertineContainer |
2146 | 26 | 29 | ||
2147 | 27 | 30 | ||
2148 | 28 | def get_session_socket_path(session_socket_name): | 31 | def get_session_socket_path(session_socket_name): |
2150 | 29 | unique_id = os.environ['DISPLAY'].strip(':') | 32 | unique_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(8)) |
2151 | 30 | 33 | ||
2152 | 31 | if not os.path.exists(libertine.utils.get_libertine_runtime_dir()): | 34 | if not os.path.exists(libertine.utils.get_libertine_runtime_dir()): |
2153 | 32 | os.makedirs(libertine.utils.get_libertine_runtime_dir()) | 35 | os.makedirs(libertine.utils.get_libertine_runtime_dir()) |
2154 | 33 | 36 | ||
2155 | 34 | session_socket_path = ( | 37 | session_socket_path = ( |
2157 | 35 | os.path.join(libertine.utils.get_libertine_runtime_dir(), session_socket_name + unique_id)) | 38 | os.path.join(libertine.utils.get_libertine_runtime_dir(), session_socket_name + '-' + unique_id)) |
2158 | 36 | 39 | ||
2159 | 37 | return session_socket_path | 40 | return session_socket_path |
2160 | 38 | 41 | ||
2161 | @@ -69,8 +72,8 @@ | |||
2162 | 69 | 72 | ||
2163 | 70 | while not os.path.exists(session_socket_path): | 73 | while not os.path.exists(session_socket_path): |
2164 | 71 | if retries >= 10: | 74 | if retries >= 10: |
2167 | 72 | raise RuntimeError("Timeout waiting for Libertine Dbus session bridge socket") | 75 | raise RuntimeError("Timeout waiting for Libertine Dbus session bridge socket") |
2168 | 73 | 76 | ||
2169 | 74 | print("Libertine Dbus session bridge socket is not ready. Waiting...") | 77 | print("Libertine Dbus session bridge socket is not ready. Waiting...") |
2170 | 75 | retries += 1 | 78 | retries += 1 |
2171 | 76 | time.sleep(.5) | 79 | time.sleep(.5) |
2172 | @@ -84,9 +87,6 @@ | |||
2173 | 84 | help='exec line') | 87 | help='exec line') |
2174 | 85 | args = arg_parser.parse_args() | 88 | args = arg_parser.parse_args() |
2175 | 86 | 89 | ||
2176 | 87 | if not libertine.utils.container_exists(args.container_id): | ||
2177 | 88 | raise RuntimeError("Container ID %s does not exist." % args.container_id) | ||
2178 | 89 | |||
2179 | 90 | # remove problematic environment variables | 90 | # remove problematic environment variables |
2180 | 91 | 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']: |
2181 | 92 | if e in os.environ: | 92 | if e in os.environ: |
2182 | @@ -104,7 +104,7 @@ | |||
2183 | 104 | # should detect the maliit socket, but dont know if its around or not here. | 104 | # should detect the maliit socket, but dont know if its around or not here. |
2184 | 105 | detect_session_bridge_socket(dbus_socket_path) | 105 | detect_session_bridge_socket(dbus_socket_path) |
2185 | 106 | 106 | ||
2187 | 107 | container = LibertineContainer(args.container_id) | 107 | container = LibertineContainer(args.container_id) |
2188 | 108 | 108 | ||
2189 | 109 | try: | 109 | try: |
2190 | 110 | container.launch_application(args.app_exec_line) | 110 | container.launch_application(args.app_exec_line) |
2191 | 111 | 111 | ||
2192 | === modified file 'tools/libertine-session-bridge' | |||
2193 | --- tools/libertine-session-bridge 2016-05-19 20:00:22 +0000 | |||
2194 | +++ tools/libertine-session-bridge 2016-07-07 20:14:07 +0000 | |||
2195 | @@ -170,6 +170,7 @@ | |||
2196 | 170 | except: | 170 | except: |
2197 | 171 | container_session_sock.close() | 171 | container_session_sock.close() |
2198 | 172 | container_session_sock = None | 172 | container_session_sock = None |
2199 | 173 | os.remove(session_socket_path) | ||
2200 | 173 | raise | 174 | raise |
2201 | 174 | else: | 175 | else: |
2202 | 175 | host_session_socket_path_map.update({container_session_sock:host_session_path}) | 176 | host_session_socket_path_map.update({container_session_sock:host_session_path}) |
When creating a container, I get the following error:
``` libertine- container- manager" , line 492, in <module> libertine- container- manager" , line 51, in create info.select_ container_ type_by_ kernel( ) lrp/Projects/ 2016/libertine- 1.2.2/python/ libertine/ HostInfo. py", line 25, in select_ container_ type_by_ kernel
Traceback (most recent call last):
File "tools/
args.func(args)
File "tools/
container_type = self.host_
File "/home/
if has_lxc_support():
NameError: name 'has_lxc_support' is not defined
```
Probably missing a `self`? See minor diff comments.