check_tid_log.py 2.68 KB
Newer Older
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#!/usr/bin/python
##############################################################################
#
# Copyright (c) 2008 Nexedi SARL and Contributors. All Rights Reserved.
#                    Vincent Pelletier <vincent@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

# Checks the sanity of a tidstorage TID log provided via stdin.
# Exit status:
#  0 Success
#  1 Failure
# Error is displayed on stderr.
# On success, final tid values for each storage is displayed on stdout.

import sys
content = {}
last_timestamp = None

line = sys.stdin.readline()
while line != '':
  split_line = line.split(' ', 2)
  assert len(split_line) == 3, repr(split_line)
  line_timestamp, line_type, line_dict = split_line
  line_timestamp = float(line_timestamp)
  assert line_type in ('f', 'd'), repr(line_type)
  if last_timestamp is None:
    last_timestamp = line_timestamp
  else:
    assert last_timestamp < line_timestamp, '%r < %r' % (last_timestamp, line_timestamp)
  line_dict = eval(line_dict, None)
  assert isinstance(line_dict, dict), type(line_dict)
  assert len(line_dict), repr(line_dict)
  if line_type == 'd':
    for key, value in line_dict.iteritems():
      if key in content:
        assert content[key] < value, '%r < %r' % (content[key], value)
      content[key] = value
  elif line_type == 'f':
    for key, value in content.iteritems():
      assert key in line_dict, repr(key)
      assert value <= line_dict[key], '%r <= %r' % (value, line_dict[key])
    content = line_dict
  line = sys.stdin.readline()

key_list = content.keys()
key_list.sort()
for key in key_list:
  print '%r %r' % (key, content[key])