forked from XRPLF/xrpl-py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
migration.py
298 lines (257 loc) · 10.9 KB
/
migration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import os
ripple_docker: str = "rippleci/rippled:2.2.0-b3"
xahau_docker: str = "xahauci/xahaud:2024.9.11"
def replace_in_poetry(file_path, new_authors):
"""Replace occurrences of 'xrpl' with 'xahau', 'xrp' with 'xah', and add new authors in pyproject.md."""
try:
with open(file_path, "r") as file:
content = file.read()
# Replace the text
new_content = (
content.replace(
"https://github.com/XRPLF/xrpl-py", "https://github.com/Xahau/xahau-py"
)
.replace("xrpl", "xahau")
.replace("xrp", "xah")
.replace("XRP ledger", "Xahau Ledger")
)
# Find the authors section
authors_start = new_content.find("authors = [") + len("authors = [")
authors_end = new_content.find("]", authors_start)
# Create a list of existing authors
existing_authors = new_content[authors_start:authors_end].strip()
existing_authors_list = [
author.strip().strip('"')
for author in existing_authors.split(",")
if author.strip()
]
# Combine existing and new authors
combined_authors = existing_authors_list + [
author.strip() for author in new_authors
]
# Format the combined authors list for output
new_authors_list_str = ",\n ".join(
f'"{author}"' for author in combined_authors
)
# Replace the entire authors section with the new list
new_content = (
new_content[:authors_start]
+ "\n "
+ new_authors_list_str
+ "\n]"
+ new_content[authors_end + 1 :]
)
# Write the changes back to the file
with open(file_path, "w") as file:
file.write(new_content)
print(f"Updated: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def replace_in_readme(file_path):
"""Replace occurrences of 'from xrpl' with 'from xahau' in README.md."""
try:
with open(file_path, "r") as file:
content = file.read()
# Replace the text
new_content = (
content.replace("from xrpl", "from xahau")
.replace("xrpl-py", "xahau-py")
.replace("xrpl.", "xahau.")
.replace("xrpl-announce", "xahau-announce")
.replace("xrpl-keypairs", "xahau-keypairs")
.replace("XRP Ledger", "Xahau Ledger")
.replace("https://s.altnet.rippletest.net:51234", "https://xahau-test.net")
)
# Write the changes back to the file
with open(file_path, "w") as file:
file.write(new_content)
print(f"Updated: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def replace_in_contrib(file_path):
"""Replace occurrences of 'from xrpl' with 'from xahau' in CONTRIBUTING.md."""
try:
with open(file_path, "r") as file:
content = file.read()
# Replace the text
new_content = (
content.replace("from xrpl", "from xahau")
.replace("flake8 xrpl", "flake8 xahau")
.replace("xrpl-announce", "xahau-announce")
.replace("../xrpl", "../xahau")
.replace("xrpllabsofficial/xrpld:1.12.0", ripple_docker)
.replace(ripple_docker, xahau_docker)
.replace("/opt/ripple/bin/rippled", "/opt/xahau/bin/xahaud")
.replace("/opt/ripple/etc/rippled.cfg", "/opt/xahau/etc/xahaud.cfg")
.replace("ripple", "xahau")
.replace("rippled", "xahaud")
.replace("RIPPLED", "XAHAUD")
.replace("[validators_file]", "# [validators_file]")
.replace("validators.txt", "# validators.txt")
.replace("xrpl-py", "xahau-py")
)
# Write the changes back to the file
with open(file_path, "w") as file:
file.write(new_content)
print(f"Updated: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def replace_in_github(file_path):
try:
with open(file_path, "r") as file:
content = file.read()
# Replace the text
new_content = (
content.replace("[xahau]", "[main, xahau]")
.replace("flake8 xrpl", "flake8 xahau")
.replace("reexport xrpl", "reexport xahau")
.replace("xrpl/", "xahau/")
.replace("source xrpl", "source xahau")
)
# Write the changes back to the file
with open(file_path, "w") as file:
file.write(new_content)
print(f"Updated: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def replace_in_file(file_path):
"""Replace occurrences of 'from xrpl' with 'from xahau' in the given file."""
try:
with open(file_path, "r") as file:
content = file.read()
# Replace the text
new_content = (
content.replace("from xrpl", "from xahau")
.replace("import xrpl", "import xahau")
.replace("xrpl.utils", "xahau.utils")
.replace("xrpl.models.", "xahau.models.")
.replace("xrpl.core.", "xahau.core.")
.replace("flake8 xrpl", "flake8 xahau")
.replace("xrpl-announce", "xahau-announce")
.replace("../xrpl", "../xahau")
.replace("xrpllabsofficial/xrpld:1.12.0", "xahaulabsofficial/xahaud:1.12.0")
.replace("xrpl-py", "xahau-py")
.replace("https://s.altnet.rippletest.net:51234", "https://xahau-test.net")
.replace("https://xrplcluster.com/", "https://xahau.network")
.replace(
'_TEST_FAUCET_URL: Final[str] = "https://faucet.altnet.rippletest.net/accounts"',
'_TEST_FAUCET_URL: Final[str] = "https://xahau-test.net/accounts"',
)
.replace(
'_DEV_FAUCET_URL: Final[str] = "https://faucet.devnet.rippletest.net/accounts"',
'_DEV_FAUCET_URL: Final[str] = "https://xahau-test.net/accounts"',
)
.replace(
'if "altnet" in url or "testnet" in url:',
'if "xahau-test" in url or "testnet" in url:',
)
.replace(
"https://s.devnet.rippletest.net:51234",
"https://xahau-test.net",
)
.replace(
"wss://s.altnet.rippletest.net:51233",
"wss://xahau-test.net",
)
.replace(
"wss://s.devnet.rippletest.net",
"wss://xahau-test.net",
)
.replace(
"https://testnet.xrpl-labs.com",
"https://xahau-test.net",
)
.replace(
"wss://testnet.xrpl-labs.com",
"wss://xahau-test.net",
)
.replace(
"faucet.devnet.rippletest.net",
"xahau-test.net",
)
.replace(
"wss://xahau-test.net:51233",
"wss://xahau-test.net",
)
.replace(
"_DEFAULT_API_VERSION: Final[int] = 2",
"_DEFAULT_API_VERSION: Final[int] = 1",
)
.replace('"xrpl.', '"xahau.')
.replace("XRP", "XAH")
.replace("xrp_to_drops", "xah_to_drops")
.replace("drops_to_xrp", "drops_to_xah")
.replace("xrp_conversions", "xah_conversions")
# .replace("XAHLModelException", "XRPLModelException")
.replace("XRPLModelException", "XAHLModelException")
.replace("xahau.models.currencies.xrp", "xahau.models.currencies.xah")
.replace('"xrp"', '"xah"')
.replace(
"0000000000000000000000005852500000000000",
"0000000000000000000000005841480000000000",
)
.replace(
"def test_does_account_exist_throws_for_invalid_account",
"def _test_does_account_exist_throws_for_invalid_account",
)
.replace(
"def test_run_faucet_tests",
"def _test_run_faucet_tests",
)
# DA: This Wont Work Need to Delete The Test Files
# .replace("TestAccountDelete", "NoTestAccountDelete")
# .replace("TestAMM", "NoTestAMM")
# .replace("TestClawback", "NoTestClawback")
# .replace("TestDeleteOracle", "NoTestDeleteOracle")
# .replace("TestDID", "NoTestDID")
# .replace("TestSetOracle", "NoTestSetOracle")
# .replace("TestXChain", "NoTestXChain")
# .replace("TestFeature", "NoTestFeature")
)
# Write the changes back to the file
with open(file_path, "w") as file:
file.write(new_content)
print(f"Updated: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def search_and_replace_in_folders(folder_paths):
"""Search for Python files in the given list of folders and replace text."""
for folder_path in folder_paths:
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith(".py") or file.endswith(".json"):
file_path = os.path.join(root, file)
replace_in_file(file_path)
def rename_folder(old_folder_name, new_folder_name):
"""Rename the specified folder."""
if os.path.exists(old_folder_name):
os.rename(old_folder_name, new_folder_name)
print(f"Renamed folder: {old_folder_name} to {new_folder_name}")
else:
print(f"Folder {old_folder_name} does not exist.")
def delete_file(old_file_name):
"""Delete the specified file."""
if os.path.exists(old_file_name):
os.remove(old_file_name)
print(f"Deleted file: {old_file_name}")
else:
print(f"File {old_file_name} does not exist.")
if __name__ == "__main__":
rename_folder("xrpl", "xahau")
rename_folder(".ci-config/rippled.cfg", ".ci-config/xahaud.cfg")
rename_folder("xahau/utils/xrp_conversions.py", "xahau/utils/xah_conversions.py")
rename_folder("xahau/models/currencies/xrp.py", "xahau/models/currencies/xah.py")
folder_list = ["snippets", "tests", "tools", "xahau"]
search_and_replace_in_folders(folder_list)
replace_in_contrib("CONTRIBUTING.md")
replace_in_contrib(".github/workflows/integration_test.yml")
replace_in_contrib(".ci-config/xahaud.cfg")
replace_in_github(".github/workflows/integration_test.yml")
replace_in_github(".github/workflows/unit_test.yml")
replace_in_github(".pre-commit-config.yaml")
# replace_in_poetry(
# "pyproject.toml",
# ["Denis Angell <denis@xrpl-labs.com>", "Tequ <tequ@xrplf.com>"],
# )
replace_in_readme("README.md")
delete_file(".github/workflows/snippet_test.yml")