/scripts/md5check.py

https://bitbucket.org/lindenlab/viewer-beta/ · Python · 56 lines · 26 code · 4 blank · 26 comment · 6 complexity · 1f7e71bd47f0b222d78fd5f0c17e3aca MD5 · raw file

  1. #!/usr/bin/env python
  2. """\
  3. @file md5check.py
  4. @brief Replacement for message template compatibility verifier.
  5. $LicenseInfo:firstyear=2010&license=viewerlgpl$
  6. Second Life Viewer Source Code
  7. Copyright (C) 2010-2011, Linden Research, Inc.
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation;
  11. version 2.1 of the License only.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  20. $/LicenseInfo$
  21. """
  22. import sys
  23. import hashlib
  24. if len(sys.argv) != 3:
  25. print """Usage: %s --create|<hash-digest> <file>
  26. Creates an md5sum hash digest of the specified file content
  27. and compares it with the given hash digest.
  28. If --create is used instead of a hash digest, it will simply
  29. print out the hash digest of specified file content.
  30. """ % sys.argv[0]
  31. sys.exit(1)
  32. if sys.argv[2] == '-':
  33. fh = sys.stdin
  34. filename = "<stdin>"
  35. else:
  36. filename = sys.argv[2]
  37. fh = open(filename)
  38. hexdigest = hashlib.md5(fh.read()).hexdigest()
  39. if sys.argv[1] == '--create':
  40. print hexdigest
  41. elif hexdigest == sys.argv[1]:
  42. print "md5sum check passed:", filename
  43. else:
  44. print "md5sum check FAILED:", filename
  45. sys.exit(1)