def _get_current_file_info(root_directory):
  _check_isdir(root_directory)
  cached_info = _get_cached_file_info(root_directory)
  result = {}
  for filename in _list_files(root_directory):
    full_path = os.path.join(root_directory, filename)
    # Checks whether the file checksum has to be recalculated.
    update_checksum = False
    if filename in cached_info:
      cache_time = cached_info[filename]["timestamp"]
      last_modification_time = _last_modification_time(full_path)
      if cache_time < last_modification_time:
        update_checksum = True
    else:
      update_checksum = True
    # Recalculates the checksum if necessary.  Adds the file to the result.
    if update_checksum:
      last_modification_time = _last_modification_time(full_path)
      checksum_ = None
      while True:
        print(YELLOW("Recalculating checksum of '{}'".format(filename)))
        checksum_ = checksum.compute(full_path)
        last_modification_time2 = _last_modification_time(full_path)
        if last_modification_time == last_modification_time2:
          break
        else:
          last_modification_time = last_modification_time2
      result[filename] = \
          {"checksum": checksum_, "timestamp": last_modification_time}
    else:
      result[filename] = cached_info[filename]
  _save_cached_file_info(root_directory, result)
  return result
示例#2
0
文件: data.py 项目: mareksom/octosync
 def update_file(file_path):
   full_path = os.path.join(origin, file_path)
   modification_time = os.path.getmtime(full_path)
   if file_path in indexed_files \
       and indexed_files[file_path]['timestamp'] + 0.001 >= modification_time:
     # Just copy from .octosync file.
     result[file_path] = indexed_files[file_path]
   else:
     # Get file data.
     if write_info:
       if file_path in indexed_files:
         print(MAGENTA('Detected modification ({}): '.format(write_info))
               + YELLOW(file_path))
       else:
         print(MAGENTA('Detected  a  new file ({}): '.format(write_info))
               + GREEN(file_path))
     result[file_path] = {'checksum': checksum.compute(full_path),
                          'timestamp': modification_time}
示例#3
0
 def checksum(self, _data):
     if _data is not None:
         self.__checksum = checksum.compute(_data)