~libertine-team/libertine/trunk

« back to all changes in this revision

Viewing changes to python/libertine/ContainersConfig.py

  • Committer: Bileto Bot
  • Date: 2016-09-14 14:45:48 UTC
  • mfrom: (161.1.2 libertine.1.4.1-release)
  • Revision ID: ci-train-bot@canonical.com-20160914144548-ajgnaxcmfq3bwpxp
* Refactor the libertine-session-bus to be a class, so we will be on the
  same process and we can actually test LSB more then just running it and
  checking exit code.
* Add a get_logger function to the libertine utils. This function will get
  the logger __libertiner_logger__ which will only be setup once, with one
  handler.
* Switch libertine-lxc-manager to be a DBus service and activate it on demand
  via DBus. (LP: #1591350)
* Add check for special LIBERTINE_JENKAAS_TESTING environment variable for
  the smoke testing harness.
* Bump version to 1.4.1.
* Return user to homepage when container has been destroyed from under them.
  (LP: #1604015)
* Introduce a method in ContainersConfig to refresh the database depending 
  on an md5 checksum.
* Creating the first container moves user to ContainersView screen.
  (LP: #1615697)
* Inject a ContainersConfig instance when creating containers.
* Fix crash in ContainersConfig when getting host arch by using HostInfo
  object.
* Create a signal to indicate that container creation has begun.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import libertine.utils
18
18
import os
19
19
import sys
 
20
from hashlib import md5
 
21
from libertine.HostInfo import HostInfo
20
22
 
21
23
 
22
24
def read_container_config_file():
41
43
        fcntl.lockf(fd, fcntl.LOCK_UN)
42
44
 
43
45
 
 
46
def container_config_hash():
 
47
    checksum = md5()
 
48
    container_config_file = libertine.utils.get_libertine_database_file_path()
 
49
    if (os.path.exists(container_config_file) and os.path.getsize(container_config_file) != 0):
 
50
        with open(container_config_file, "rb") as f:
 
51
            for chunk in iter(lambda: f.read(128 * checksum.block_size), b""):
 
52
                checksum.update(chunk)
 
53
    return checksum.hexdigest()
 
54
 
 
55
 
44
56
class ContainersConfig(object):
45
57
 
46
58
    def __init__(self):
47
 
        self.container_list = read_container_config_file()
 
59
        self.checksum = None
 
60
        self.refresh_database()
48
61
 
49
62
        if "defaultContainer" in self.container_list:
50
63
            self.default_container_id = self.container_list['defaultContainer']
144
157
    """
145
158
    Miscellaneous ContainersConfig.json operations
146
159
    """
 
160
    def refresh_database(self):
 
161
        checksum = container_config_hash()
 
162
        if checksum != self.checksum:
 
163
            self.container_list = read_container_config_file()
 
164
            self.checksum = checksum
 
165
 
147
166
    def _find_duplicate_container_entry(self, container_list, container_id):
148
167
        for container in container_list['containerList']:
149
168
            if container['id'] == container_id:
243
262
        return self._test_key_value_exists(container_id, 'id')
244
263
 
245
264
    def update_container_multiarch_support(self, container_id, multiarch):
246
 
        if multiarch == 'enabled' and libertine.utils.get_host_architecture() == 'i386':
 
265
        if multiarch == 'enabled' and HostInfo().get_host_architecture() == 'i386':
247
266
            multiarch = 'disabled'
248
267
 
249
268
        self._set_value_by_key(container_id, 'multiarch', multiarch)