Skip to content

Instantly share code, notes, and snippets.

@passy
Created November 30, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passy/ee9efe4ef85aa73f3f61bd317ae1dbe4 to your computer and use it in GitHub Desktop.
Save passy/ee9efe4ef85aa73f3f61bd317ae1dbe4 to your computer and use it in GitHub Desktop.
#!/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