~graphite-dev/graphite/1.1

« back to all changes in this revision

Viewing changes to whisper/whisper.py

  • Committer: Chris Davis
  • Date: 2011-08-08 03:32:25 UTC
  • mfrom: (337.5.115 trunk)
  • Revision ID: chrismd@gmail.com-20110808033225-oncjaxk2pvd6651m
cherrypicking trunk revs 450-460

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
debug = startBlock = endBlock = lambda *a,**k: None
58
58
 
 
59
UnitMultipliers = {
 
60
  's' : 1,
 
61
  'm' : 60,
 
62
  'h' : 60 * 60,
 
63
  'd' : 60 * 60 * 24,
 
64
  'y' : 60 * 60 * 24 * 365,
 
65
}
 
66
 
 
67
 
 
68
def parseRetentionDef(retentionDef):
 
69
  (precision, points) = retentionDef.strip().split(':')
 
70
 
 
71
  if precision.isdigit():
 
72
    precisionUnit = 's'
 
73
    precision = int(precision)
 
74
  else:
 
75
    precisionUnit = precision[-1]
 
76
    precision = int( precision[:-1] )
 
77
 
 
78
  if points.isdigit():
 
79
    pointsUnit = None
 
80
    points = int(points)
 
81
  else:
 
82
    pointsUnit = points[-1]
 
83
    points = int( points[:-1] )
 
84
 
 
85
  if precisionUnit not in UnitMultipliers:
 
86
    raise ValueError("Invalid unit: '%s'" % precisionUnit)
 
87
 
 
88
  if pointsUnit not in UnitMultipliers and pointsUnit is not None:
 
89
    raise ValueError("Invalid unit: '%s'" % pointsUnit)
 
90
 
 
91
  precision = precision * UnitMultipliers[precisionUnit]
 
92
 
 
93
  if pointsUnit:
 
94
    points = points * UnitMultipliers[pointsUnit] / precision
 
95
 
 
96
  return (precision, points)
 
97
 
59
98
 
60
99
class WhisperException(Exception):
61
100
    """Base class for whisper exceptions."""