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

« back to all changes in this revision

Viewing changes to systemimage/helpers.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:
21
21
    'as_object',
22
22
    'as_timedelta',
23
23
    'atomic',
 
24
    'last_update_date',
24
25
    'makedirs',
25
26
    'safe_remove',
26
27
    'temporary_directory',
 
28
    'version_detail',
27
29
    ]
28
30
 
29
31
 
179
181
        os.makedirs(dir, exist_ok=True)
180
182
    except (FileExistsError, PermissionError):
181
183
        pass
 
184
 
 
185
 
 
186
def last_update_date():
 
187
    """Return the last update date.
 
188
 
 
189
    Taken from the mtime of /etc/system-image/channel.ini first, with fallback
 
190
    to /etc/ubuntu-build if that file doesn't exist.
 
191
    """
 
192
    # Avoid circular imports.
 
193
    from systemimage.config import config
 
194
    channel_ini = os.path.join(
 
195
        os.path.dirname(config.config_file), 'channel.ini')
 
196
    ubuntu_build = config.system.build_file
 
197
    for path in (channel_ini, ubuntu_build):
 
198
        try:
 
199
            # Local time, since we can't know the timezone.
 
200
            timestamp = datetime.fromtimestamp(os.stat(path).st_mtime)
 
201
            # Seconds resolution.
 
202
            timestamp = timestamp.replace(microsecond=0)
 
203
            return str(timestamp)
 
204
        except FileNotFoundError:
 
205
            pass
 
206
    else:
 
207
        return 'Unknown'
 
208
 
 
209
 
 
210
def version_detail():
 
211
    """Return a dictionary of the version details."""
 
212
    # Avoid circular imports.
 
213
    from systemimage.config import config
 
214
    version_details = getattr(config.service, 'version_detail', None)
 
215
    if version_details is None:
 
216
        return {}
 
217
    details = {}
 
218
    if version_details is not None:
 
219
        for item in version_details.strip().split(','):
 
220
            name, equals, version = item.partition('=')
 
221
            if equals != '=':
 
222
                continue
 
223
            details[name] = version
 
224
    return details