示例#1
0
  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()
示例#2
0
 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)
示例#3
0
    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
示例#4
0
  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
示例#5
0
    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
示例#6
0
 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)
示例#7
0
 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)