~larryprice/libertine/python-i18n

« back to all changes in this revision

Viewing changes to python/libertine/LxcContainer.py

  • Committer: Larry Price
  • Date: 2017-03-23 19:23:20 UTC
  • Revision ID: larry.price@canonical.com-20170323192320-upi3h8wxp04z9y5n
moving gettext fetch to utils

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
import tempfile
24
24
 
25
 
import gettext
26
 
gettext.textdomain('libertine')
27
 
_ = gettext.gettext
28
 
 
29
25
from .Libertine import BaseContainer
30
26
from . import utils, HostInfo
31
27
 
73
69
                for line in fd:
74
70
                    print(line.lstrip())
75
71
        except Exception as ex:
76
 
            utils.get_logger().error(_("Could not open LXC log file: {logfile}").format(logfile=ex))
 
72
            utils.get_logger().error(utils._("Could not open LXC log file: {logfile}").format(logfile=ex))
77
73
 
78
74
 
79
75
def get_logfile(container):
94
90
 
95
91
    if container.state == 'STOPPED':
96
92
        if not container.start():
97
 
            utils.get_logger().error(_("Container failed to start."))
 
93
            utils.get_logger().error(utils._("Container failed to start."))
98
94
            return False
99
95
    elif container.state == 'FROZEN':
100
96
        if not container.unfreeze():
101
 
            utils.get_logger().error(_("Container failed to unfreeze."))
 
97
            utils.get_logger().error(utils._("Container failed to unfreeze."))
102
98
            return False
103
99
 
104
100
    if not container.wait("RUNNING", 10):
105
 
        utils.get_logger().error(_("Container failed to enter the RUNNING state."))
 
101
        utils.get_logger().error(utils._("Container failed to enter the RUNNING state."))
106
102
        return False
107
103
 
108
104
    if not container.get_ips(timeout=30):
109
105
        lxc_stop(container)
110
 
        utils.get_logger().error(_("Not able to connect to the network."))
 
106
        utils.get_logger().error(utils._("Not able to connect to the network."))
111
107
        return False
112
108
 
113
109
    return True
120
116
    if freeze_on_stop:
121
117
        container.freeze()
122
118
        if not container.wait("FROZEN", 10):
123
 
            utils.get_logger().error(_("Container failed to enter the FROZEN state."))
 
119
            utils.get_logger().error(utils._("Container failed to enter the FROZEN state."))
124
120
            return False
125
121
    else:
126
122
        container.stop()
127
123
        if not container.wait("STOPPED", 10):
128
 
            utils.get_logger().error(_("Container failed to enter the STOPPED state."))
 
124
            utils.get_logger().error(utils._("Container failed to enter the STOPPED state."))
129
125
            return False
130
126
 
131
127
    return True
250
246
 
251
247
    def restart_container(self):
252
248
        if self.container.state != 'FROZEN':
253
 
            utils.get_logger().warning(_("Container '{container_id}' is not frozen. Cannot restart.").format(container_id=self.container_id))
 
249
            utils.get_logger().warning(utils._("Container '{container_id}' is not frozen. Cannot restart.").format(container_id=self.container_id))
254
250
            return False
255
251
 
256
252
        if not (lxc_stop(self.container) and lxc_start(self.container)):
276
272
            return False
277
273
 
278
274
        if self.container.state == 'RUNNING' and not force:
279
 
            utils.get_logger().error(_("Canceling destruction due to running container. Use --force to override."))
 
275
            utils.get_logger().error(utils._("Canceling destruction due to running container. Use --force to override."))
280
276
            return False
281
277
 
282
278
        if not lxc_stop(self.container):
283
 
            utils.get_logger().error(_("Failed to force container to stop. Canceling destruction."))
 
279
            utils.get_logger().error(utils._("Failed to force container to stop. Canceling destruction."))
284
280
            return False
285
281
 
286
282
        self.container.destroy()
326
322
                                         {"dist": "ubuntu",
327
323
                                          "release": self.installed_release,
328
324
                                          "arch": self.architecture}):
329
 
                utils.get_logger().error(_("Failed to create container"))
 
325
                utils.get_logger().error(utils._("Failed to create container"))
330
326
                _dump_lxc_log(lxc_logfile)
331
327
                return False
332
328
 
333
329
        self.create_libertine_config()
334
330
 
335
 
        utils.get_logger().info(_("starting container ..."))
 
331
        utils.get_logger().info(utils._("starting container ..."))
336
332
        if not self.start_container():
337
333
            self.destroy_libertine_container()
338
334
            return False
344
340
                str(user_id), crypt.crypt(password), str(username)))
345
341
 
346
342
        if multiarch and self.architecture == 'amd64':
347
 
            utils.get_logger().info(_("Adding i386 multiarch support..."))
 
343
            utils.get_logger().info(utils._("Adding i386 multiarch support..."))
348
344
            self.run_in_container("dpkg --add-architecture i386")
349
345
 
350
 
        utils.get_logger().info(_("Updating the contents of the container after creation..."))
 
346
        utils.get_logger().info(utils._("Updating the contents of the container after creation..."))
351
347
        self.update_packages()
352
348
 
353
349
        for package in self.default_packages:
354
350
            if not self.install_package(package, update_cache=False):
355
 
                utils.get_logger().error(_("Failure installing '{package_name}' during container creation").format(package_name=package))
 
351
                utils.get_logger().error(utils._("Failure installing '{package_name}' during container creation").format(package_name=package))
356
352
                self.destroy_libertine_container()
357
353
                return False
358
354
 
359
355
        super().create_libertine_container()
360
356
 
361
 
        utils.get_logger().info(_("stopping container ..."))
 
357
        utils.get_logger().info(utils._("stopping container ..."))
362
358
        self.stop_container()
363
359
 
364
360
        return True