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