Update checksum based on file.
325332
def update_checksum(self, progress_callback=None, chunk_size=None,
                        checksum_kwargs=None, **kwargs):
        """"""
        self.checksum = self.storage(**kwargs).checksum(
            progress_callback=progress_callback, chunk_size=chunk_size,
            **(checksum_kwargs or {}))
1330178
def if_file_changed(file, &block)
      if_string_changed(file, Digest::SHA256.file(file).hexdigest.to_s, &block)
    end
1077790
def __validate_and_fix_path(path, check_file=False, check_dir=False):
    """"""
    # pylint: disable=superfluous-parens
    if path is None:
        return path
    else:
        if not (os.path.isfile(path) if check_file else False) \
                and not (os.path.isdir(path) if check_dir else False):
            raise SystemExit('Path `%s` does not exist' % path)
        if not os.path.isabs(path):
            path = os.path.abspath(os.path.join(os.path.abspath(os.curdir), path))

    return path
354315
def valid_checksum(file, hash_file):
    
    bits = 4096
    # calc md5 hash
    hash_md5 = hashlib.md5()
    with open(file, "rb") as f:
        for chunk in iter(lambda: f.read(bits), b""):
            hash_md5.update(chunk)
    # locate hash signature for file, validate
    with open(hash_file) as c:
        for line in c.readlines():
            if line.strip():
                check_list = line.split()
                if file == check_list[1]:
                    if check_list[0] == hash_md5.hexdigest():
                        return True
    return False
209085
public void setChecksum(final String checksum) {
        if (checksum == null && this.checksum == null) {
            return;
        } else if (checksum == null) {
            removeChild(this.checksum);
            this.checksum = null;
        } else if (this.checksum == null) {
            this.checksum = new KeyValueNode<String>(CommonConstants.CS_CHECKSUM_TITLE, checksum);
            appendChild(this.checksum, false);
        } else {
            this.checksum.setValue(checksum);
        }
    }
577330
def add_checksum(self, csum):
        
        for csum_tmp in self.checksums:
            if csum_tmp.target == csum.target:
                self.checksums.remove(csum_tmp)
                break
        self.checksums.append(csum)
1080172
def checksum(self, chunk_size=None, progress_callback=None, **kwargs):
        """"""
        fp = self.open(mode='rb')
        try:
            value = self._compute_checksum(
                fp, size=self._size, chunk_size=None,
                progress_callback=progress_callback)
        except StorageError:
            raise
        finally:
            fp.close()
        return value
1104701
def LoadCheckFromFile(file_path, check_id, overwrite_if_exists=True):
  """"""
  configs = LoadConfigsFromFile(file_path)
  conf = configs.get(check_id)
  check = Check(**conf)
  check.Validate()
  CheckRegistry.RegisterCheck(
      check,
      source="file:%s" % file_path,
      overwrite_if_exists=overwrite_if_exists)
  logging.debug("Loaded check %s from %s", check.check_id, file_path)
  return check
170489
function _checksums(dir) {
  const checksums = {};

  glob.sync(resolve(dir, '**/!(*.pack.+(s[ac]ss|js))'), { mark: true }).forEach((file) => {
    if (Utils.endsWith(file, '/')) { return; }

    const relativePath = relative(dir, file);
    checksums[relativePath] = Utils.checksum(file);
  });

  return checksums;
}
701898
def parse_checksum_file(self, file):
        
        checksums = dict()
        file_path = '/'.join((self.rawdir, file))
        with open(file_path, 'rt') as tsvfile:
            reader = csv.reader(tsvfile, delimiter=' ')
            for row in reader:
                (checksum, whitespace, file_name) = row
                checksums[checksum] = file_name

        return checksums
1290704
def parse_checksums(checksums_string):
    """"""
    checksums_list = []
    for line in checksums_string.split('\n'):
        try:
            # skip empty lines
            if line == '':
                continue

            checksum, filename = line.split()
            # strip leading ./
            if filename.startswith('./'):
                filename = filename[2:]
            checksums_list.append({'checksum': checksum, 'file': filename})
        except ValueError:
            logging.debug('Skipping over unexpected checksum line %r', line)
            continue

    return checksums_list
954245
def compute_checksum(line):
    """"""
    return sum((int(c) if c.isdigit() else c == '-') for c in line[0:68]) % 10
669432
def new_checksum(self):
        """"""
        if self.context.is_file(self.filename):
            friendly_name = format_path(self.filename)
            logger.debug("Calculating SHA1 of %s ..", friendly_name)
            context = hashlib.sha1()
            context.update(self.context.read_file(self.filename))
            checksum = context.hexdigest()
            logger.debug("The SHA1 digest of %s is %s.", friendly_name, checksum)
            return checksum
447184
def update_stampfile_hook(self, dependencies):  # suppress(no-self-use)
        """"""
        hashes = {d: _sha1_for_file(d) for d in dependencies
                  if os.path.exists(d)}
        with open(self._stamp_file_hashes_path, "wb") as hashes_file:
            hashes_file.write(json.dumps(hashes).encode("utf-8"))
347165
def _get_sizes_checksums(checksums_path):
  """"""
  checksums = {}
  for line in _read_file(checksums_path).split('\n'):
    if not line:
      continue
    # URL might have spaces inside, but size and checksum will not.
    url, size, checksum = line.rsplit(' ', 2)
    checksums[url] = (int(size), checksum)
  return checksums
906790
def checksum(fpath, hasher=None, asbytes=False):
    """"""
    def blockiter(fpath, blocksize=0x1000):
        with open(fpath, "rb") as afile:
            block = afile.read(blocksize)
            while len(block) > 0:
                yield block
                block = afile.read(blocksize)
    hasher = hasher or hashlib.md5()
    for block in blockiter(fpath):
        hasher.update(block)
    return (hasher.digest() if asbytes else hasher.hexdigest())
571608
function maybeAddChecksumNode(path, nodeType, callback) {
    fsUtils.isPathUnsynced(fs, path, function(err, unsynced) {
      if(err) {
        return callback(err);
      }

      if(unsynced) {
        return callback();
      }

      getChecksum(fs, path, function(err, checksum) {
        if(err) {
          return callback(err);
        }
        // If we shouldn't add the checksum stamp or
        // the node does not exist (cannot add a stamp)
        // immediately add the checksum
        if(!stampNode || checksum === "") {
          return addChecksumNode(path, nodeType, checksum, callback);
        }

        // Stamp the node with the checksum
        fsUtils.setChecksum(fs, path, checksum, function(err) {
          if(err) {
            return callback(err);
          }

          addChecksumNode(path, nodeType, checksum, callback);
        });
      });
    });
  }