Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def sha1(src, size=16*1024, skip_revert_times=False):
    log.debug('Generating a sha1 hash for %r', src)
    h = hashlib.new('sha1')
    stat_src = os.stat(src)
    f = open(src, "rb")
    try:
        chunk = f.read(size)
        while chunk: # EOF condition
            h.update(chunk)
            chunk = f.read(size)
    except Exception, e:
        log.error('Could not generate hash %r. Error was %r', src, e)
        raise
    else:
        # Put the source time back to how it was. @@@ is this a good idea?
        if not skip_revert_times:
            try:
                set_time(
                    src, 
                    stat_src.st_atime, 
                    stat_src.st_mtime,
                )
            except Exception, e:
                log.error(
                    'Could not reset the modification time on %r. Error was %r', 
                    src,
                    e,
                )
        return h.hexdigest()
    finally:
        f.close()
        


src/a/r/Archiver-0.2.2/archiver/api.py   Archiver(Download)
from sqlalchemy.sql import func
 
from archiver.helper import sha1, set_time
 
log = logging.getLogger(__name__)
            else:
                if not hash_str:
                    hash_str = sha1(os.path.join(base_path, source_path), skip_revert_times=skip_revert_times)
                store_dir = os.path.join(self.store_path, hash_str[0:4])
                if not os.path.exists(store_dir):