1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6'''Count number of occurrences of a given message ID.''' 7 8from grit import grd_reader 9from grit.tool import interface 10 11 12class CountMessage(interface.Tool): 13 '''Count the number of times a given message ID is used.''' 14 15 def __init__(self): 16 pass 17 18 def ShortDescription(self): 19 return 'Count the number of times a given message ID is used.' 20 21 def Run(self, opts, args): 22 self.SetOptions(opts) 23 24 id = args[0] 25 res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose) 26 res_tree.OnlyTheseTranslations([]) 27 res_tree.RunGatherers() 28 29 count = 0 30 for c in res_tree.UberClique().AllCliques(): 31 if c.GetId() == id: 32 count += 1 33 34 print "There are %d occurrences of message %s." % (count, id) 35 36