PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/md5check.py

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