~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2007-10-10 00:21:57 UTC
  • mfrom: (2900 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071010002157-utci0x44m2w47wgd
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
590
590
    return s.hexdigest()
591
591
 
592
592
 
 
593
def sha_file_by_name(fname):
 
594
    """Calculate the SHA1 of a file by reading the full text"""
 
595
    s = sha.new()
 
596
    f = os.open(fname, os.O_RDONLY)
 
597
    try:
 
598
        while True:
 
599
            b = os.read(f, 1<<16)
 
600
            if not b:
 
601
                return s.hexdigest()
 
602
            s.update(b)
 
603
    finally:
 
604
        os.close(f)
 
605
 
 
606
 
593
607
def sha_strings(strings, _factory=sha.new):
594
608
    """Return the sha-1 of concatenation of strings"""
595
609
    s = _factory()