def run(self, args): if "files" not in self.config: return for modify_config in self.config["files"]: file_path = self.translate_string(modify_config["file_path"]) if not os.path.isabs(file_path): file_path = os.path.join(self.runner.project_root_path, file_path) source = SourceFile(file_path) source.open() operation = modify_config["operation"] words = None if "words" in modify_config: words = modify_config["words"] words = self.translate_string(words) if "words_file" in modify_config: words_file_path = self.translate_string(modify_config["words_file"]) if not os.path.isabs(words_file_path): words_file_path = os.path.join(self.runner.pack_resource_path, words_file_path) fp = open(words_file_path) words = fp.read() fp.close() words = self.translate_string(words) if operation == "insert": source.insert(modify_config["keys"], words) elif operation == "insert_before": source.insert_before(modify_config["keys"], words) elif operation == "replace": olds = modify_config["olds"] for i in range(len(olds)): olds[i] = self.translate_string(olds[i]) news = modify_config["news"] for i in range(len(news)): news[i] = self.translate_string(news[i]) source.replace(olds, news) elif operation == "search_replace": source.search_replace(modify_config["froms"], modify_config["tos"], words) elif operation == "search_replace_to_end": source.search_replace_to_end(modify_config["froms"], modify_config["tos"], words) elif operation == "remove": source.remove(modify_config["froms"], modify_config["tos"]) source.save()
def replace_scheme_data(self, scheme_file_path, target_name, xcode_project_name=None, scheme_name=None): print("===>replace scheme data in %s to %s,%s,%s" % ( scheme_file_path, target_name, xcode_project_name, scheme_name)) source = SourceFile(scheme_file_path) source.open() if target_name: source.search_replace(["BuildAction", "BuildableName", '"'], ['"'], target_name + ".app") source.search_replace(["TestAction", "BuildableName", '"'], ['"'], target_name + ".app") source.search_replace(["LaunchAction", "BuildableName", '"'], ['"'], target_name + ".app") source.search_replace(["ProfileAction", "BuildableName", '"'], ['"'], target_name + ".app") if xcode_project_name: source.search_replace(["BuildAction", "ReferencedContainer", '"'], ['"'], "container:" + xcode_project_name) source.search_replace(["TestAction", "ReferencedContainer", '"'], ['"'], "container:" + xcode_project_name) source.search_replace(["LaunchAction", "ReferencedContainer", '"'], ['"'], "container:" + xcode_project_name) source.search_replace(["ProfileAction", "ReferencedContainer", '"'], ['"'], "container:" + xcode_project_name) if scheme_name: source.search_replace(["BuildAction", "BlueprintName", '"'], ['"'], scheme_name) source.search_replace(["LaunchAction", "BlueprintName", '"'], ['"'], scheme_name) source.search_replace(["TestAction", "BlueprintName", '"'], ['"'], scheme_name) source.search_replace(["ProfileAction", "BlueprintName", '"'], ['"'], scheme_name) source.save()