Skip to content

Commit 7deafd8

Browse files
authored
Add initial source files
1 parent 98ac44f commit 7deafd8

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

isobot-data-migration-assistant.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Imports
2+
import os
3+
import shutil
4+
import time
5+
6+
# Variables and Configuration
7+
class Configuration:
8+
home_dir = os.path.expanduser('~')
9+
wdir = os.getcwd()
10+
database_files = (
11+
"automod.json",
12+
"currency.json",
13+
"embeds.json",
14+
"isocard.json",
15+
"isocard_transaction_history.json",
16+
"isocard_transactions.json",
17+
"items.json",
18+
"levels.json",
19+
"presence.json",
20+
"serverconfig.json",
21+
"serververification.json",
22+
"user_data.json",
23+
"warnings.json",
24+
"weather.json",
25+
"isobank/accounts.json",
26+
"isobank/auth.json"
27+
)
28+
config_files = (
29+
"commands.json",
30+
"settings.json",
31+
"shop.json",
32+
"words.json"
33+
)
34+
log_files = (
35+
"currency.log",
36+
"error-log.txt",
37+
"info-log.txt",
38+
"isocard_transactions.log",
39+
"startup-log.txt"
40+
)
41+
42+
print("Welcome to the isobot migration assistant!")
43+
print("This migration assistant will migrate all your isobot client")
44+
print("data from their legacy paths to the new isobot data directory.")
45+
print("\nMigration Process Information:")
46+
print(f" Old Data Path: {Configuration.wdir}")
47+
print(f" New Data Path: {Configuration.home_dir}/.isobot")
48+
print(f"\nDISCLAIMER: This migration assistant will delete ALL of your data from the legacy directory")
49+
print("but, your data WILL be copied to the new data directory. This process is NOT reversible")
50+
print("once completed.")
51+
prompt = input("\nAre you sure you want to continue? (y/n): ")
52+
53+
if prompt.lower() != "y":
54+
raise SystemExit("[!] Migration process cancelled. Aborting isobot migration assistant...")
55+
else:
56+
print("[!] Migration process started. Please wait...\n")
57+
print("---------------------------------")
58+
59+
# Check whether the runtime working directory is the isobot directory or not
60+
print("[1] [Check: 1/2] Checking runtime working directory for required files...")
61+
identification_dirs = ("web", "api", "framework", "discord", "cogs", "utils")
62+
for directory in identification_dirs:
63+
if not os.path.isdir(directory):
64+
raise SystemExit("[!] Either this isobot client is broken, or this is not the correct isobot directory. Aborting migration assistant...")
65+
time.sleep(0.5)
66+
67+
# Check whether legacy paths exist
68+
print(f"[2] [Check: 2/2] Checking whether legacy paths exist in {Configuration.wdir}...")
69+
if not os.path.isdir("config") and not os.path.isdir("database") and not os.path.isdir("logs"):
70+
raise SystemExit("[!] Legacy data paths do not exist in this client. Aborting migration assistant...")
71+
time.sleep(0.5)
72+
73+
# Transfer all files from legacy directory to new system data directory
74+
print("[3] [Migrate: 1/3] Migrating all database files from database directory...")
75+
for _file in Configuration.database_files:
76+
print(f" MGR: {Configuration.wdir}/database/{_file} -> {Configuration.home_dir}/.isobot/database/{_file}")
77+
shutil.copyfile(f"database/{_file}", f"{Configuration.home_dir}/.isobot/database/{_file}")
78+
time.sleep(0.5)
79+
print("[4] [Migrate: 2/3] Migrating all config files from config directory...")
80+
for _file in Configuration.config_files:
81+
print(f" MGR: {Configuration.wdir}/config/{_file} -> {Configuration.home_dir}/.isobot/config/{_file}")
82+
shutil.copyfile(f"config/{_file}", f"{Configuration.home_dir}/.isobot/config/{_file}")
83+
time.sleep(0.5)
84+
print("[5] [Migrate: 3/3] Migrating all log files from logs directory...")
85+
for _file in Configuration.log_files:
86+
print(f" MGR: {Configuration.wdir}/logs/{_file} -> {Configuration.home_dir}/.isobot/logs/{_file}")
87+
shutil.copyfile(f"logs/{_file}", f"{Configuration.home_dir}/.isobot/logs/{_file}")
88+
time.sleep(0.5)
89+
90+
# Delete all files from legacy directory
91+
print("[6] [Cleanup: 1/3] Deleting all database files from legacy directory...")
92+
for _file in Configuration.database_files:
93+
print(f" DEL: database/{_file}")
94+
os.remove(f"database/{_file}")
95+
time.sleep(0.5)
96+
print("[7] [Cleanup: 2/3] Deleting all config files from legacy directory...")
97+
for _file in Configuration.config_files:
98+
print(f" DEL: config/{_file}")
99+
os.remove(f"config/{_file}")
100+
time.sleep(0.5)
101+
print("[8] [Cleanup: 3/3] Deleting all log files from legacy directory...")
102+
for _file in Configuration.log_files:
103+
print(f" DEL: logs/{_file}")
104+
os.remove(f"logs/{_file}")
105+
time.sleep(0.5)
106+
107+
print("[✅] Migration process successfully completed. All of your data is now migrated to the new isobot data directory.")
108+
input("Press enter or any key to exit.")

0 commit comments

Comments
 (0)