def _sources_hash(self, paths): """Generate SHA1 digest from the content of all files under the given paths.""" sha = hashlib.sha1() for relative_filename, filename in self._walk_paths(paths): with open(filename, "rb") as fd: sha.update(Compatibility.to_bytes(relative_filename)) sha.update(fd.read()) return sha.hexdigest()
def write(self, filename): chroot = self._env.chroot().dup() chroot.zip(filename + '~') with open(filename, "wb") as pexfile: pexfile.write(Compatibility.to_bytes('%s\n' % self._identity.hashbang())) with open(filename + '~', 'rb') as pexfile_zip: pexfile.write(pexfile_zip.read()) chroot.delete() os.unlink(filename + '~') chmod_plus_x(filename)
def _sources_hash(self, paths): """Generate SHA1 digest from the content of all files under the given paths.""" sha = hashlib.sha1() for relative_filename, filename in self._walk_paths(paths): with open(filename, "rb") as fd: sha.update(Compatibility.to_bytes(relative_filename)) sha.update(fd.read()) return sha
def _sources_hash(self, sha, paths): """Update a SHA1 digest with the content of all files under the given paths. :returns: The number of files found under the given paths. """ num_files = 0 for relative_filename, filename in self._walk_paths(paths): with open(filename, "rb") as fd: sha.update(Compatibility.to_bytes(relative_filename)) sha.update(fd.read()) num_files += 1 return num_files
def _sources_hash(self, sha, paths): """Update a SHA1 digest with the content of all files under the given paths. :returns: The files found under the given paths. """ files = [] for relative_filename, filename in self._walk_paths(paths): with open(filename, "rb") as fd: sha.update(Compatibility.to_bytes(relative_filename)) sha.update(fd.read()) files.append(filename) return files
def build(self, filename): self.freeze() try: os.unlink(filename + '~') self._logger.warn('Previous binary unexpectedly exists, cleaning: %s' % (filename + '~')) except OSError: # The expectation is that the file does not exist, so continue pass with open(filename + '~', 'ab') as pexfile: assert os.path.getsize(pexfile.name) == 0 # TODO(wickman) Make this tunable pexfile.write(Compatibility.to_bytes('%s\n' % PythonIdentity.get().hashbang())) self._chroot.zip(filename + '~', mode='a') if os.path.exists(filename): os.unlink(filename) os.rename(filename + '~', filename) chmod_plus_x(filename)
def build(self, filename): self.freeze() try: os.unlink(filename + '~') print('WARNING: Previous binary unexpectedly exists, cleaning: %s' % (filename + '~')) except OSError: # The expectation is that the file does not exist, so continue pass with open(filename + '~', 'ab') as pexfile: assert os.path.getsize(pexfile.name) == 0 # TODO(wickman) Make this tunable pexfile.write(Compatibility.to_bytes('%s\n' % PythonIdentity.get().hashbang())) self._chroot.zip(filename + '~', mode='a') if os.path.exists(filename): os.unlink(filename) os.rename(filename + '~', filename) chmod_plus_x(filename)