/usr/lib/python2.6/site-packages/pip-8.1.1-py2.6.egg/pip/commands
NameSizeModeActions
completion.py19670644editdlrm
completion.pyc25840644editdlrm
download.py48040644editdlrm
download.pyc44490644editdlrm
freeze.py27740644editdlrm
freeze.pyc32570644editdlrm
hash.py15970644editdlrm
hash.pyc25650644editdlrm
help.py9820644editdlrm
help.pyc14180644editdlrm
install.py149710644editdlrm
install.pyc102790644editdlrm
list.py74120644editdlrm
list.pyc73800644editdlrm
search.py47770644editdlrm
search.pyc54590644editdlrm
show.py58150644editdlrm
show.pyc58960644editdlrm
uninstall.py28840644editdlrm
uninstall.pyc31830644editdlrm
wheel.py75280644editdlrm
wheel.pyc64780644editdlrm
__init__.py21450644editdlrm
__init__.pyc26590644editdlrm
Edit: /usr/lib/python2.6/site-packages/pip-8.1.1-py2.6.egg/pip/commands/hash.py (1597B)
from __future__ import absolute_import import hashlib import logging import sys from pip.basecommand import Command from pip.status_codes import ERROR from pip.utils import read_chunks from pip.utils.hashes import FAVORITE_HASH, STRONG_HASHES logger = logging.getLogger(__name__) class HashCommand(Command): """ Compute a hash of a local package archive. These can be used with --hash in a requirements file to do repeatable installs. """ name = 'hash' usage = '%prog [options] ...' summary = 'Compute hashes of package archives.' def __init__(self, *args, **kw): super(HashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option( '-a', '--algorithm', dest='algorithm', choices=STRONG_HASHES, action='store', default=FAVORITE_HASH, help='The hash algorithm to use: one of %s' % ', '.join(STRONG_HASHES)) self.parser.insert_option_group(0, self.cmd_opts) def run(self, options, args): if not args: self.parser.print_usage(sys.stderr) return ERROR algorithm = options.algorithm for path in args: logger.info('%s:\n--hash=%s:%s', path, algorithm, _hash_of_file(path, algorithm)) def _hash_of_file(path, algorithm): """Return the hash digest of a file.""" with open(path, 'rb') as archive: hash = hashlib.new(algorithm) for chunk in read_chunks(archive): hash.update(chunk) return hash.hexdigest()