Example #1
0
def create(base_directory, file_list):
    global output, error, error_msg

    if OS.is_windows():
        # We need the /cygdrive/c/Users/.../ path instead of C:\Users\...\ because
        # a backslash is a valid character in a Unix path. When the list of files
        # is passed to cpio, sbin/adbd, for example, would be included as a file
        # named 'sbin\adbd'

        stdin = "cd '%s' && pwd\n" % OS.binariesdir

        exit_code, output, error = cmd.run_command(
            [OS.bash],
            stdin_data=stdin.encode('UTF-8'),
            cwd=base_directory,
            universal_newlines=False
        )

        if exit_code != 0:
            error_msg = 'Failed to get Cygwin drive path'
            return None

        cpio_cygpath = output.decode('UTF-8').strip('\n') + '/cpio.exe'

        stdin = cpio_cygpath              \
            + ' -o -H newc << EOF\n'      \
            + '\n'.join(file_list) + '\n' \
            + 'EOF\n'

        # We cannot use "bash -c '...'" because the /cygdrive/ mountpoints are
        # created only in an interactive shell. We'll launch bash first and then
        # run cpio.
        exit_code, output, error = cmd.run_command(
            [OS.bash],
            stdin_data=stdin.encode('UTF-8'),
            cwd=base_directory,
            universal_newlines=False
        )

    else:
        # So much easier than in Windows ...
        exit_code, output, error = cmd.run_command(
            [OS.cpio, '-o', '-H', 'newc'],
            stdin_data='\n'.join(file_list).encode('UTF-8'),
            cwd=base_directory,
            universal_newlines=False
        )

    if exit_code != 0:
        error_msg = 'Failed to create cpio archive'
        return None

    return output
Example #2
0
def apply_patch(patch_file, directory):
    global output, error, error_msg

    debug.debug("Applying patch: %s in directory %s" % (patch_file, directory))

    exit_code, output, error = cmd.run_command([
        OS.patch, '--no-backup-if-mismatch', '-p', '1', '-d', directory, '-i',
        os.path.join(OS.patchdir, patch_file)
    ])

    if exit_code != 0:
        error_msg = "Failed to apply patch"
        return False
    else:
        return True
Example #3
0
def apply_patch(patch_file, directory):
    global output, error, error_msg

    debug.debug("Applying patch: %s in directory %s" % (patch_file, directory))

    exit_code, output, error = cmd.run_command(
        [OS.patch,
         '--no-backup-if-mismatch',
         '-p', '1',
         '-d', directory,
         '-i', os.path.join(OS.patchdir, patch_file)]
    )

    if exit_code != 0:
        error_msg = "Failed to apply patch"
        return False
    else:
        return True
def patch_ramdisk(directory, partition_config):
  ui = OS.ui

  global version

  if os.path.exists(os.path.join(directory, 'MSM8960_lpm.rc')):
    version = 'jb43'
  else:
    version = 'kk44'

  modify_init_rc(directory)
  modify_init_qcom_rc(directory)
  modify_fstab(directory, partition_config)
  modify_init_target_rc(directory)
  modify_MSM8960_lpm_rc(directory)

  # Samsung's init binary is pretty screwed up
  if version == 'kk44':
    init = os.path.join(directory, 'init')

    os.remove(init)
    shutil.copyfile(os.path.join(OS.ramdiskdir, 'init-kk44'), init)

    # chmod 755
    if OS.is_windows():
      chmod = os.path.join(OS.binariesdir, "chmod.exe")
      exit_status, output, error = cmd.run_command(
        [ chmod, '0755', init ]
      )

      if exit_status != 0:
        ui.command_error(output = output, error = error)
        ui.failed("Failed to chmod init (WINDOWS)")
        exit.exit(1)

    else:
      import stat
      os.chmod(init, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
                     stat.S_IRGRP |                stat.S_IXGRP |
                     stat.S_IROTH |                stat.S_IXOTH)
Example #5
0
def extract(destination, path=None, data=None):
    global output, error, error_msg

    if not path and not data:
        return False

    if path:
        f = open(path, 'rb')
        data = f.read()
        f.close()

    exit_code, output, error = cmd.run_command(
        [OS.cpio, '-i', '-d', '-m', '-v'],
        stdin_data=data,
        cwd=destination,
        universal_newlines=False
    )

    if exit_code != 0:
        return False
    else:
        return True
Example #6
0
print("Modified: " + modified)
print("")
choice = input("Is this correct? (y = yes, n = no, s = swap) ")

proceed = False
if choice == '' or choice[:1] == 'y' or choice[:1] == 'Y':
    proceed = True

elif choice[:1] == 's' or choice[:1] == 'S':
    original, modified = modified, original
    proceed = True

if not proceed:
    sys.exit(0)

exit_status, output, error = cmd.run_command(
    [diff, '-N', '-r', '-u', original, modified])

print("\n")

if len(output) == 0:
    print('The directories are identical. '
          'Did you compare the right directories?')
    sys.exit(1)

filtered = []
parentdir = os.path.realpath(os.path.join(original, '..'))
parentdir2 = os.path.realpath(os.path.join(modified, '..'))

if not os.path.samefile(parentdir, parentdir2):
    print('WARNING: The two directories do not share the '
          'same parent directory')
Example #7
0
print("")
choice = input("Is this correct? (y = yes, n = no, s = swap) ")

proceed = False
if choice == '' or choice[:1] == 'y' or choice[:1] == 'Y':
    proceed = True

elif choice[:1] == 's' or choice[:1] == 'S':
    original, modified = modified, original
    proceed = True

if not proceed:
    sys.exit(0)

exit_status, output, error = cmd.run_command(
    [diff, '-N', '-r', '-u', original, modified]
)

print("\n")

if len(output) == 0:
    print("The directories are identical. Did you compare the right directories?")
    sys.exit(1)

filtered = []
parentdir = os.path.realpath(os.path.join(original, '..'))
parentdir2 = os.path.realpath(os.path.join(modified, '..'))

if not os.path.samefile(parentdir, parentdir2):
    print("WARNING: The two directories do not share the same parent directory")