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 process_def(def_file, cpiofile, partition_config): debug.debug("Loading ramdisk definition %s" % def_file) for line in fileio.all_lines(def_file): if line.startswith("pyscript"): path = os.path.join(OS.ramdiskdir, re.search(r"^pyscript\s*=\s*\"?(.*)\"?\s*$", line).group(1)) debug.debug("Loading pyscript " + path) plugin = imp.load_source(os.path.basename(path)[:-3], os.path.join(OS.ramdiskdir, path)) plugin.patch_ramdisk(cpiofile, partition_config) return True
def process_def(def_file, cpiofile, partition_config): try: debug.debug("Loading ramdisk definition %s" % def_file) for line in fileio.all_lines(def_file): if line.startswith("pyscript"): path = re.search(r"^pyscript\s*=\s*\"?(.*)\"?\s*$", line).group(1) debug.debug("Loading pyscript " + path) plugin = plugins.ramdisks[path] common.init(cpiofile, partition_config) plugin.patch_ramdisk(cpiofile, partition_config) except Exception as e: raise RamdiskPatchError(str(e))
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 run_command(command, stdin_data=None, cwd=None, universal_newlines=True): debug.debug("Running command: " + str(command)) try: process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, universal_newlines=universal_newlines) output, error = process.communicate(input=stdin_data) exit_code = process.returncode return (exit_code, output, error) except: raise Exception("Failed to run command: \"%s\"" % ' '.join(command))
def get_info(path, device): filename = os.path.split(path)[1] for i in ['Google_Apps', 'Other', device]: for root, dirs, files in os.walk(os.path.join(OS.patchinfodir, i)): for f in files: if f.endswith(".py"): plugin = imp.load_source(os.path.basename(f)[:-3], os.path.join(root, f)) if plugin.matches(filename): try: file_info = plugin.get_file_info(filename=filename) except: file_info = plugin.get_file_info() if file_info: debug.debug("Loading patchinfo plugin: " + filename) print('Detected ' + file_info.name) return file_info return None
def run_command(command, stdin_data=None, cwd=None, universal_newlines=True): debug.debug("Running command: " + str(command)) try: process = subprocess.Popen( command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, universal_newlines=universal_newlines ) output, error = process.communicate(input=stdin_data) exit_code = process.returncode return (exit_code, output, error) except: raise Exception("Failed to run command: \"%s\"" % ' '.join(command))
def files_in_patch(patch_file): global error_msg files = [] lines = fileio.all_lines(os.path.join(OS.patchdir, patch_file)) counter = 0 while counter < len(lines): if re.search(r"^---", lines[counter]) \ and re.search(r"^\+\+\+", lines[counter + 1]) \ and re.search(r"^@", lines[counter + 2]): temp = re.search(r"^--- .*?/(.*)$", lines[counter]) debug.debug("Found in patch %s: %s" % (patch_file, temp.group(1))) files.append(temp.group(1)) counter += 3 else: counter += 1 if not files: error_msg = "Failed to read list of files in patch" return files
def process_def(def_file, directory, partition_config): debug.debug("Loading ramdisk definition %s in directory %s" % (def_file, directory)) for line in fileio.all_lines(def_file): if line.startswith("pyscript"): path = os.path.join(OS.ramdiskdir, re.search(r"^pyscript\s*=\s*\"?(.*)\"?\s*$", line).group(1)) debug.debug("Loading pyscript " + path) plugin = imp.load_source(os.path.basename(path)[:-3], os.path.join(OS.ramdiskdir, path)) plugin.patch_ramdisk(directory, partition_config) elif line.startswith("patch"): path = os.path.join(OS.ramdiskdir, re.search(r"^patch\s*=\s*\"?(.*)\"?\s*$", line).group(1)) if not patch.apply_patch(path, directory): error_msg = patch.error_msg return False return True