| Index: grit/format/check_dups.py
|
| diff --git a/grit/format/check_dups.py b/grit/format/check_dups.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0ecc0b4af2217630d4984bab8e75f092d67e7d46
|
| --- /dev/null
|
| +++ b/grit/format/check_dups.py
|
| @@ -0,0 +1,45 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""Check for duplicate resource in multiple pack files."""
|
| +
|
| +import os
|
| +import sys
|
| +
|
| +if __name__ == '__main__':
|
| + sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
|
| +
|
| +from grit.format.data_pack import DataPack
|
| +
|
| +class ResourceDuplicateException(Exception):
|
| + pass
|
| +
|
| +
|
| +def CheckDupResource(resource_filenames):
|
| + resources = {}
|
| + for filename in resource_filenames:
|
| + pack = DataPack.ReadDataPack(filename)
|
| + for (resource_id, data) in pack.resources.iteritems():
|
| + if resource_id in resources:
|
| + details = resources[resource_id]
|
| + raise ResourceDuplicateException(
|
| + "Duplicate resource with id %s in %s (size %d) and %s (size %d)" %
|
| + (resource_id, details['filename'],
|
| + details['size'], filename, len(data)))
|
| + resources[resource_id] = {
|
| + 'filename': filename,
|
| + 'size': len(data)
|
| + }
|
| +
|
| +
|
| +def main():
|
| + if len(sys.argv) < 2:
|
| + print "There must be at least two pak files as input."
|
| + return
|
| + CheckDupResource(sys.argv[1:])
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + main()
|
|
|