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

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

        def md5sum(f, block_size=2 ** 20):
    md5 = hashlib.md5()
    # check if file was moved/deleted before opening
    if not os.path.isfile(f):

    file_size = os.stat(f).st_size

    if pbar_enabled and file_size > 0:
        widgets = [Bar(left="[", right="]", marker="#"), ' ', ETA()]
        # set maxval to the total size of the file, this is 
        # so progressbar can calc the eta/percentage completed of hash check
        bar = ProgressBar(widgets=widgets, maxval=file_size).start()
    else: bar = None

        with open(f, "rb") as fp:
            bytes_read = 0
            while True:
                # check if file has moved/deleted during md5 creation
                if not os.path.isfile(f):
                data = fp.read(block_size)
                if not data:
                bytes_read += len(data)

                if bar is not None: bar.update(bytes_read)

    except IOError:
        # another failsafe in case open() throws error

    if bar is not None: bar.finish()

src/a/r/archivedb-0.2.3/archivedb/monitor.py   archivedb(Download)
import archivedb.config as config
import archivedb.sql as sql
from archivedb.common import md5sum, split_path
from archivedb.logger import log_traceback
    if not data: # file is new
        log.info("generating checksum for {0} ...".format(filename))
        md5 = md5sum(full_path)
        # md5sum returns None if file was moved/deleted
        if md5:
            log.info("generating checksum for {0} ...".format(filename))
            md5 = md5sum(full_path)
            if md5:
                log.info("updating {0} in the database.".format(filename))