Revision 74d988b0 snf-common/synnefo/lib/utils.py

b/snf-common/synnefo/lib/utils.py
33 33

  
34 34
import datetime
35 35

  
36

  
36 37
def split_time(value):
37
  """Splits time as floating point number into a tuple.
38
    """Splits time as floating point number into a tuple.
38 39

  
39
  @param value: Time in seconds
40
  @type value: int or float
41
  @return: Tuple containing (seconds, microseconds)
40
    @param value: Time in seconds
41
    @type value: int or float
42
    @return: Tuple containing (seconds, microseconds)
42 43

  
43
  """
44
  (seconds, microseconds) = divmod(int(value * 1000000), 1000000)
44
    """
45
    (seconds, microseconds) = divmod(int(value * 1000000), 1000000)
45 46

  
46
  assert 0 <= seconds, \
47
    "Seconds must be larger than or equal to 0, but are %s" % seconds
48
  assert 0 <= microseconds <= 999999, \
49
    "Microseconds must be 0-999999, but are %s" % microseconds
47
    assert 0 <= seconds, \
48
        "Seconds must be larger than or equal to 0, but are %s" % seconds
49
    assert 0 <= microseconds <= 999999, \
50
        "Microseconds must be 0-999999, but are %s" % microseconds
50 51

  
51
  return (int(seconds), int(microseconds))
52
    return (int(seconds), int(microseconds))
52 53

  
53 54

  
54 55
def merge_time(timetuple):
55
  """Merges a tuple into a datetime object
56
    """Merges a tuple into a datetime object
56 57

  
57
  @param timetuple: Time as tuple, (seconds, microseconds)
58
  @type timetuple: tuple
59
  @return: Time as a datetime object
58
    @param timetuple: Time as tuple, (seconds, microseconds)
59
    @type timetuple: tuple
60
    @return: Time as a datetime object
60 61

  
61
  """
62
  (seconds, microseconds) = timetuple
62
    """
63
    (seconds, microseconds) = timetuple
63 64

  
64
  assert 0 <= seconds, \
65
    "Seconds must be larger than or equal to 0, but are %s" % seconds
66
  assert 0 <= microseconds <= 999999, \
67
    "Microseconds must be 0-999999, but are %s" % microseconds
65
    assert 0 <= seconds, \
66
        "Seconds must be larger than or equal to 0, but are %s" % seconds
67
    assert 0 <= microseconds <= 999999, \
68
        "Microseconds must be 0-999999, but are %s" % microseconds
68 69

  
69
  t1 = float(seconds) + (float(microseconds) * 0.000001)
70
  return datetime.datetime.fromtimestamp(t1)
70
    t1 = float(seconds) + (float(microseconds) * 0.000001)
71
    return datetime.datetime.fromtimestamp(t1)
71 72

  
72 73

  
73 74
def case_unique(iterable):
......
85 86
        return list(set(iterable) - set(icase))
86 87

  
87 88
    return []
88

  

Also available in: Unified diff