tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
 
from autotest_lib.client.common_lib import error
 
 
def get_datetime_float(host):
    """
    Returns host's system time in seconds since epoch.
 
    @param host: an Autotest host object.
    @returns a float, timestamp since epoch in <seconds>.<nanoseconds>.
 
    @raises TestError: if error reading datetime or converting its value
                       from string to float.
    """
    r = host.run('date +%s.%N')
    if r.exit_status > 0:
        err = ('Error reading datetime from capturer (%r): %r' %
               (r.exit_status, r.stderr))
        raise error.TestError(err)
    try:
        return float(r.stdout)
    except ValueError as e:
        raise error.TestError('Error converting datetime string: %r', e)