def _write_file(file, path, index): if not hasattr(file, 'getDownloadableFile'): return # getting the file to push there file = file.getDownloadableFile() if file is None: return # let's get the data data = file.get_data() if data == '': return None if index == path: raise IOError('Cannot use the same name than the index file') # if the MD5 is equal, we don't do anything if os.path.exists(path): if file_hash(path, index) == string_hash(data): return try: write_content(path, data, index) except AlreadyLocked: raise ConflictError('%s is locked' % path)
def test_file_hash(self): open(self.target, 'w').write('ok') hash = locker.file_hash(self.target) self.assertEquals(hash, '444bcb3a3fcf8389296c49467f27e1d6')