def write_module_info(f, module_object): file_name = module_object.__file__ if (file_name.endswith(".pyc")): file_name = file_name[:-1] assert file_name.endswith(".py") file_content = open(file_name, "rb").read() m = hashlib_md5() m.update(file_content) print >> f, "// Module:", module_object.__name__ print >> f, "// size:", len(file_content) print >> f, "// MD5 hexdigest:", m.hexdigest() print >> f
def save_file(self, input_file=None, file_name=None): if (input_file is None): input_file = self.open_file(file_name) input_file.check_file_type(self.file_type) file_name = input_file.file_name self._cached_input_files[file_name] = input_file self.add_file_callback(file_name) if self.use_md5_sum : file_records = open(file_name).read() m = hashlib_md5(file_records) self._file_md5sums[file_name] = m else : mtime = os.path.getmtime(file_name) self._file_mtimes[file_name] = mtime return self.save_other_file_data(input_file)
def save_file(self, input_file=None, file_name=None): if input_file is None: input_file = self.open_file(file_name) input_file.check_file_type(self.file_type) file_name = input_file.file_name self._cached_input_files[file_name] = input_file self.add_file_callback(file_name) if self.use_md5_sum: file_records = open(file_name).read() m = hashlib_md5(file_records) self._file_md5sums[file_name] = m else: mtime = os.path.getmtime(file_name) self._file_mtimes[file_name] = mtime return self.save_other_file_data(input_file)
def exercise_input_pickling(): pdb_inp = pdb.pdb_input(source_info="file/name", lines=pdb_string_all_sections) s = pickle.dumps(pdb_inp, 1) l = pickle.loads(s) assert not show_diff(l.as_pdb_string(), pdb_inp.as_pdb_string()) assert l.source_info() == "pickle" for section in pdb.input_sections: assert not show_diff("\n".join(getattr(l, section)()), "\n".join( getattr(pdb_inp, section)())) s = "\n".join(l.__getinitargs__()[1]) d = hashlib_md5(s).hexdigest() if (pdb.hierarchy.atom.has_siguij()): assert d == "bf987c40cc8672e2f2324d91d6de3e2b" else: assert d == "7375e96fd52794a785284580730de20c"
def exercise_input_pickling(): pdb_inp = pdb.pdb_input(source_info="file/name", lines=pdb_string_all_sections) for p in [pickle, cPickle]: s = p.dumps(pdb_inp, 1) l = p.loads(s) assert not show_diff(l.as_pdb_string(), pdb_inp.as_pdb_string()) assert l.source_info() == "pickle" for section in pdb.input_sections: assert not show_diff( "\n".join(getattr(l, section)()), "\n".join(getattr(pdb_inp, section)())) s = "\n".join(l.__getinitargs__()[1]) d = hashlib_md5(s).hexdigest() if (pdb.hierarchy.atom.has_siguij()): assert d == "bf987c40cc8672e2f2324d91d6de3e2b" else: assert d == "7375e96fd52794a785284580730de20c"
def file_is_modified(self, file_name): if (not self.auto_reload_files): return False elif (not file_name in self._cached_input_files): return True elif self.use_md5_sum : file_records = open(file_name).read() m = hashlib_md5(file_records) old_md5sum = self._file_md5sums.get(file_name, None) if (old_md5sum is None) or (old_md5sum != m): self._file_md5sums[file_name] = m return True else : mtime = os.path.getmtime(file_name) old_mtime = self._file_mtimes.get(file_name, None) if (old_mtime is None) or (old_mtime < mtime): self._file_mtimes[file_name] = mtime return True return False
def file_is_modified(self, file_name): if not self.auto_reload_files: return False elif not file_name in self._cached_input_files: return True elif self.use_md5_sum: file_records = open(file_name).read() m = hashlib_md5(file_records) old_md5sum = self._file_md5sums.get(file_name, None) if (old_md5sum is None) or (old_md5sum != m): self._file_md5sums[file_name] = m return True else: mtime = os.path.getmtime(file_name) old_mtime = self._file_mtimes.get(file_name, None) if (old_mtime is None) or (old_mtime < mtime): self._file_mtimes[file_name] = mtime return True return False
def current_md5(self, path_prefix=None): full_path = self.full_path(path_prefix=path_prefix) if (not os.path.exists(full_path)): return None m = hashlib_md5() m.update(open(full_path, "rb").read()) return m.hexdigest()
def bool_md5(self): result = hashlib_md5() result.update(self.__getstate__()[1]) return result
def gethash(longstring): m = hashlib_md5() m.update(longstring) return "".join(["%02X"%ord(i) for i in m.digest()])
def compute_hexdigest(text): from libtbx.utils import hashlib_md5 m = hashlib_md5() m.update(text) return m.hexdigest()