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
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)
def add_file(self, filename, name=None, perms=None): if name is None: name = filename # If file exists, delete it self.remove(name) member = CpioEntryNew() member.magic = MAGIC_NEW # Make sure we get some inode number if it's zero member.ino = os.stat(filename).st_ino if member.ino == 0: while True: member.ino -= 1 if member.ino not in self.inodemap: break if member.ino not in self.inodemap: # Make sure we only get the file contents once per inode self.inodemap[member.ino] = [member] with open(filename, 'rb') as f: member.content = f.read() member.filesize = len(member.content) else: self.inodemap[member.ino].append(member) member.content = b'' member.filesize = 0 fstat = os.stat(filename) if perms is not None: member.mode = stat.S_IFMT(fstat.st_mode) member.mode |= perms else: member.mode = os.stat(filename).st_mode member.uid = fstat.st_uid member.gid = fstat.st_gid if member.nlink == 0: if os.path.isdir(filename): member.nlink = 2 else: # Assume hard links don't exist if Python can't get nlink value member.nlink = 1 else: member.nlink = fstat.st_nlink member.mtime = os.path.getmtime(filename) if OS.is_windows(): member.dev_maj = 0 member.dev_min = 0 member.rdev_maj = 0 member.rdev_min = 0 else: member.dev_maj = os.major(fstat.st_dev) member.dev_min = os.minor(fstat.st_dev) member.rdev_maj = os.major(fstat.st_rdev) member.rdev_min = os.minor(fstat.st_rdev) member.name = name member.namesize = len(name) + 1 member.chksum = 0 self.members.append(member)
def unix_path(path): # Windows sucks if OS.is_windows(): return path.replace('\\', '/') else: return path