~ubuntu-branches/ubuntu/wily/system-image/wily-proposed

« back to all changes in this revision

Viewing changes to systemimage/channel.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2013-09-06 18:34:29 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130906183429-mwrrv52ooot0n3ut
Tags: 1.5-0ubuntu1
* New upstream release.
  - `system-image-cli --info` prints additional information:
     + last update time (i.e. the mtime of `/etc/system-image/channel.ini`
       falling back to the mtime of `/etc/ubuntu-build`).
     + version details for ubuntu, the device, and any custom version, if the
       `/etc/system-image/channel.ini` file contains these details.
  - `system-image-cli --dry-run -c <bad-channel>` no longer produces a
     traceback.  You get "Already up-to-date", but use `-v` for more info.
  - D-Bus API method `UpdateAvailableStatus` field `last_update_date`
    has changes its format.  It's still ISO 8601, but with a space
    instead of a 'T' separating the date from the time.
  - LP: #1221841 - Support the new channels.json file format with
    backward compatibility (for now) with the old format.
  - LP: #1215959 - New D-Bus .Info() method returns data similar to
    `system-image-cli --info`

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from systemimage.helpers import Bag
26
26
 
27
27
 
 
28
def _parse_device_mappings(device_mapping):
 
29
    devices = {}
 
30
    # e.g. keys: nexus7, nexus4
 
31
    for device_name, mapping_1 in device_mapping.items():
 
32
        # Most of the keys at this level (e.g. index) have flat values,
 
33
        # however the keyring key is itself a mapping.
 
34
        keyring = mapping_1.pop('keyring', None)
 
35
        if keyring is not None:
 
36
            mapping_1['keyring'] = Bag(**keyring)
 
37
        # e.g. nexus7 -> {index, keyring}
 
38
        devices[device_name] = Bag(**mapping_1)
 
39
    return Bag(**devices)
 
40
 
 
41
 
28
42
class Channels(Bag):
29
43
    @classmethod
30
44
    def from_json(cls, data):
31
45
        mapping = json.loads(data)
32
46
        channels = {}
33
 
        # e.g. keys: daily, stable
34
 
        for channel_name, device_mapping in mapping.items():
35
 
            devices = {}
36
 
            # e.g. keys: nexus7, nexus4
37
 
            for device_name, detail_mapping in device_mapping.items():
38
 
                # Most of the keys at this level (e.g. index) have flat
39
 
                # values, however the keyring key is itself a mapping.
40
 
                keyring = detail_mapping.pop('keyring', None)
41
 
                if keyring is not None:
42
 
                    detail_mapping['keyring'] = Bag(**keyring)
43
 
                # e.g. nexus7 -> {index, keyring}
44
 
                devices[device_name] = Bag(**detail_mapping)
45
 
            # e.g. daily -> {nexus7, nexus4}
46
 
            channels[channel_name] = Bag(**devices)
 
47
        # LP: #1221841 introduced a new channels.json format which introduced
 
48
        # a new level between the channel name and the device name.  This
 
49
        # extra level can include optional 'alias' and 'hidden' keys, and must
 
50
        # include a 'devices' key.  Until LP: #1221843 we must support both
 
51
        # formats, so to figure out which we're looking at, see if there's a
 
52
        # 'devices' key under the channel name.  We'll just assume there won't
 
53
        # be a device called 'device'.
 
54
        for channel_name, mapping_1 in mapping.items():
 
55
            if 'devices' in mapping_1:
 
56
                # New style.
 
57
                hidden = mapping_1.pop('hidden', None)
 
58
                if hidden is None:
 
59
                    hidden = False
 
60
                else:
 
61
                    assert hidden in (True, False), (
 
62
                        "Unexpected value for 'hidden': {}".format(hidden))
 
63
                mapping_1['hidden'] = hidden
 
64
                device_mapping = mapping_1.pop('devices')
 
65
                mapping_1['devices'] = _parse_device_mappings(device_mapping)
 
66
                channels[channel_name] = Bag(**mapping_1)
 
67
            else:
 
68
                # For better forward compatibility, even old style
 
69
                # channel.json files get a 'devices' level.
 
70
                device_mapping = _parse_device_mappings(mapping_1)
 
71
                channels[channel_name] = Bag(devices=device_mapping)
47
72
        return cls(**channels)