(old_file, new_file, temp_path)
return rebuilt_bsdiff_path
Compute a BSDIFF patch, uncompressing the bzip2 part.

  Args:
    old_file: the old APK file
    new_file: the new APK file
    temp_path: the directory to use for the process

  Returns:
    the path of the patch generated

  Raises:
    Exception: if there is a problem calling the binaries needed in the process
Compute a BSDIFF patch, uncompressing the bzip2 part.
Compute a BSDIFF patch uncompressing the bzip2 part .
def bsdiff(old_file, new_file, temp_path):
  """Compute a BSDIFF patch, uncompressing the bzip2 part.

  Args:
    old_file: the old APK file
    new_file: the new APK file
    temp_path: the directory to use for the process

  Returns:
    the path of the patch generated

  Raises:
    Exception: if there is a problem calling the binaries needed in the process
  """

  # Oddities:
  # Bsdiff forces bzip2 compression, which starts after byte 32. Bzip2 isn't
  # necessarily the best choice in all cases, and isn't necessarily what Google
  # Play uses, so it has to be uncompressed.

  # bsdiff paths
  bsdiff_patch_path = os.path.join(temp_path, 'patch.bsdiff')
  raw_bsdiff_path = os.path.join(temp_path, 'patch.raw_bsdiff')
  bzipped_bsdiff_path = raw_bsdiff_path + '.bz2'
  bsdiff_header_path = os.path.join(temp_path, 'patch.raw_bsdiff_header')
  cleanup(raw_bsdiff_path, bzipped_bsdiff_path, bsdiff_header_path)

  # Create the bsdiff of the two APKs
  run_command(
      [bsdiff_path, old_file, new_file, bsdiff_patch_path])

  # Strip the first 32 bytes the bsdiff file, which is a bsdiff-specific header.
  bsdiff_header = open(bsdiff_header_path, 'w')
  run_command(
      [head_path, '-c', '32', bsdiff_patch_path],
      stdout=bsdiff_header)
  bsdiff_header.flush()
  bsdiff_header.close()

  # Take the remainder of the file to gain an uncompressed copy.
  bzipped_bsdiff_patch = open(bzipped_bsdiff_path, 'w')
  run_command(
      [tail_path, '-c', '+33', bsdiff_patch_path],
      stdout=bzipped_bsdiff_patch)
  bzipped_bsdiff_patch.flush()
  bzipped_bsdiff_patch.close()
  run_command([bunzip2_path, '-d', '-q', bzipped_bsdiff_path])

  # Prepend the 32 bytes of bsdiff header back onto the uncompressed file.
  rebuilt_bsdiff_path = raw_bsdiff_path + '.rebuilt'
  if os.path.exists(rebuilt_bsdiff_path): os.remove(rebuilt_bsdiff_path)
  rebuilt_bsdiff = open(rebuilt_bsdiff_path, 'w')
  run_command(
      ['cat', bsdiff_header_path, raw_bsdiff_path],
      stdout=rebuilt_bsdiff)
  rebuilt_bsdiff.flush()
  rebuilt_bsdiff.close()

  # Clean up.
  cleanup(raw_bsdiff_path, bsdiff_header_path, bzipped_bsdiff_path)

  return rebuilt_bsdiff_path
def bsdiff ( old_file , new_file , temp_path ) : # Oddities: # Bsdiff forces bzip2 compression, which starts after byte 32. Bzip2 isn't # necessarily the best choice in all cases, and isn't necessarily what Google # Play uses, so it has to be uncompressed. # bsdiff paths bsdiff_patch_path = os . path . join ( temp_path , 'patch.bsdiff' ) raw_bsdiff_path = os . path . join ( temp_path , 'patch.raw_bsdiff' ) bzipped_bsdiff_path = raw_bsdiff_path + '.bz2' bsdiff_header_path = os . path . join ( temp_path , 'patch.raw_bsdiff_header' ) cleanup ( raw_bsdiff_path , bzipped_bsdiff_path , bsdiff_header_path ) # Create the bsdiff of the two APKs run_command ( [ bsdiff_path , old_file , new_file , bsdiff_patch_path ] ) # Strip the first 32 bytes the bsdiff file, which is a bsdiff-specific header. bsdiff_header = open ( bsdiff_header_path , 'w' ) run_command ( [ head_path , '-c' , '32' , bsdiff_patch_path ] , stdout = bsdiff_header ) bsdiff_header . flush ( ) bsdiff_header . close ( ) # Take the remainder of the file to gain an uncompressed copy. bzipped_bsdiff_patch = open ( bzipped_bsdiff_path , 'w' ) run_command ( [ tail_path , '-c' , '+33' , bsdiff_patch_path ] , stdout = bzipped_bsdiff_patch ) bzipped_bsdiff_patch . flush ( ) bzipped_bsdiff_patch . close ( ) run_command ( [ bunzip2_path , '-d' , '-q' , bzipped_bsdiff_path ] ) # Prepend the 32 bytes of bsdiff header back onto the uncompressed file. rebuilt_bsdiff_path = raw_bsdiff_path + '.rebuilt' if os . path . exists ( rebuilt_bsdiff_path ) : os . remove ( rebuilt_bsdiff_path ) rebuilt_bsdiff = open ( rebuilt_bsdiff_path , 'w' ) run_command ( [ 'cat' , bsdiff_header_path , raw_bsdiff_path ] , stdout = rebuilt_bsdiff ) rebuilt_bsdiff . flush ( ) rebuilt_bsdiff . close ( ) # Clean up. cleanup ( raw_bsdiff_path , bsdiff_header_path , bzipped_bsdiff_path ) return rebuilt_bsdiff_path