Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("file")
args = parser.parse_args()
data = open(args.file).read()
layout_position_start = data.find("Layout.create")
while (layout_position_start > 0):
layout_position = layout_position_start
comma_position = 0
end_parentheses_position = 0
if (layout_position >= 0):
count = 1
layout_position += 14
while (data[layout_position] != "," or count > 1):
if (data[layout_position] == "("):
count += 1
if (data[layout_position] == ")"):
count -= 1
layout_position += 1
comma_position = layout_position
while (count > 0):
if (data[layout_position] == "("):
count += 1
if (data[layout_position] == ")"):
count -= 1
layout_position += 1
end_parentheses_position = layout_position - 1
newData = ""
newData += data[0: layout_position_start]
newData += "Wrapper.create("
newData += data[layout_position_start + 14: comma_position]
newData += ").delegate("
newData += data[comma_position + 2:len(data)]
data = newData
layout_position_start = data.find("Layout.create")
newData = ""
import_position = data.find("import com.facebook.litho.Layout;")
if (import_position > 0):
newData += data[0: import_position]
newData += "import com.facebook.litho.Wrapper;"
newData += data[import_position + 33:len(data)]
else:
newData = data
open(args.file,'w').write(newData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment