Revision 739be818 lib/utils.py
b/lib/utils.py | ||
---|---|---|
1161 | 1161 |
return None |
1162 | 1162 |
|
1163 | 1163 |
|
1164 |
def SplitTime(seconds): |
|
1165 |
"""Splits time as floating point number into a tuple. |
|
1166 |
|
|
1167 |
@param seconds: Time in seconds |
|
1168 |
@type seconds: int or float |
|
1169 |
@return: Tuple containing (seconds, milliseconds) |
|
1170 |
|
|
1171 |
""" |
|
1172 |
(seconds, fraction) = divmod(seconds, 1.0) |
|
1173 |
return (int(seconds), int(round(fraction * 1000, 0))) |
|
1174 |
|
|
1175 |
|
|
1176 |
def MergeTime(timetuple): |
|
1177 |
"""Merges a tuple into time as a floating point number. |
|
1178 |
|
|
1179 |
@param timetuple: Time as tuple, (seconds, milliseconds) |
|
1180 |
@type timetuple: tuple |
|
1181 |
@return: Time as a floating point number expressed in seconds |
|
1182 |
|
|
1183 |
""" |
|
1184 |
(seconds, milliseconds) = timetuple |
|
1185 |
|
|
1186 |
assert 0 <= seconds, "Seconds must be larger than 0" |
|
1187 |
assert 0 <= milliseconds <= 999, "Milliseconds must be 0-999" |
|
1188 |
|
|
1189 |
return float(seconds) + (float(1) / 1000 * milliseconds) |
|
1190 |
|
|
1191 |
|
|
1164 | 1192 |
def LockedMethod(fn): |
1165 | 1193 |
"""Synchronized object access decorator. |
1166 | 1194 |
|
Also available in: Unified diff