elytra_client/add_methods.py

36 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Script to add all missing methods to the REST client"""
import re
# Read the generated methods file
with open("generated_methods.py", "r") as f:
generated_content = f.read()
# Extract the Python code from markdown backticks
match = re.search(r"```python\n(.*?)\n```", generated_content, re.DOTALL)
if not match:
print("ERROR: Could not find Python code block in generated_methods.py")
exit(1)
methods_code = match.group(1)
# Read the current client file
with open("elytra_client/rest_api/client.py", "r") as f:
client_content = f.read()
# Find the position of "def close(self)" method
close_pos = client_content.find(" def close(self) -> None:")
if close_pos == -1:
print("ERROR: Could not find 'def close' method in client.py")
exit(1)
# Insert the new methods before the close() method
new_client_content = client_content[:close_pos] + methods_code + "\n\n" + client_content[close_pos:]
# Write back to the client file
with open("elytra_client/rest_api/client.py", "w") as f:
f.write(new_client_content)
print(f"Successfully added {methods_code.count('def ')} new methods to the client")
print("Client file updated successfully")