|
| 1 | +#!/bin/python |
| 2 | +import os |
| 3 | +import shutil |
| 4 | +import subprocess |
| 5 | +from time import sleep |
| 6 | + |
| 7 | +os.environ['PLUGINPATH'] = 'plugin_oracle' |
| 8 | + |
| 9 | +def uget(var: str) -> str: |
| 10 | + val = os.environ.get(var) |
| 11 | + if val is None: |
| 12 | + print(f'{val}') |
| 13 | + print(f'{os.environ}') |
| 14 | + raise ValueError(f'{var} cannot be None') |
| 15 | + return val |
| 16 | + |
| 17 | +def check_appdata() -> str | None: |
| 18 | + path = uget('LOCALAPPDATA') |
| 19 | + path += os.path.sep + 'ModOrganizer' |
| 20 | + if not os.path.exists(path): |
| 21 | + return None |
| 22 | + path += os.path.sep + 'nxmhandler.ini' |
| 23 | + if not os.path.exists(path): |
| 24 | + return None |
| 25 | + with open(path, 'r') as f: |
| 26 | + for line in f: |
| 27 | + if 'executable' in line: |
| 28 | + return line[line.index('=') + 1:].rstrip() |
| 29 | + return None |
| 30 | + |
| 31 | +def remove_pycache(root: str) -> None: |
| 32 | + for dirpath, dirnames, _ in os.walk(root): |
| 33 | + if '__pycache__' in dirnames: |
| 34 | + shutil.rmtree(os.path.join(dirpath, '__pycache__'), ignore_errors=True) |
| 35 | + |
| 36 | +binpath = check_appdata() |
| 37 | +if not binpath: |
| 38 | + print('Can\'t find MO2') |
| 39 | + exit(1) |
| 40 | +path = binpath.removesuffix(r'\\ModOrganizer.exe') |
| 41 | + |
| 42 | +path += os.path.sep + 'plugins' |
| 43 | +if not os.path.exists(path): |
| 44 | + os.makedirs(path, exist_ok=True) |
| 45 | + |
| 46 | +remove_pycache(uget('PLUGINPATH')) |
| 47 | +shutil.rmtree(path + os.path.sep + uget('PLUGINPATH'), ignore_errors=True) |
| 48 | + |
| 49 | +print(shutil.copytree(uget('PLUGINPATH'), path + os.path.sep + uget('PLUGINPATH'), dirs_exist_ok=True)) |
| 50 | + |
| 51 | +sleep(3) |
| 52 | +cmd: list[str] = [binpath, 'reload-plugin', uget('PLUGINPATH')] |
| 53 | +_ = subprocess.run(cmd) |
0 commit comments