Spaces:
Running
Running
| """ | |
| Imperial Rclone Installer & Path Resolver | |
| rclone ๋ฐ์ด๋๋ฆฌ๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ๊ฑฐ๋ ๋ค์ด๋ก๋ํฉ๋๋ค. | |
| """ | |
| import os | |
| import sys | |
| import platform | |
| import subprocess | |
| # Windows: %USERPROFILE%\.rclone\rclone.exe / ๊ธฐํ: ~/.rclone/rclone | |
| if platform.system() == "Windows": | |
| RCLONE_EXE = os.path.join(os.path.expanduser("~"), ".rclone", "rclone.exe") | |
| else: | |
| RCLONE_EXE = os.path.join(os.path.expanduser("~"), ".rclone", "rclone") | |
| def _rclone_in_path() -> str | None: | |
| """PATH์์ rclone ์คํ ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ฐํํฉ๋๋ค.""" | |
| try: | |
| result = subprocess.run( | |
| ["where" if platform.system() == "Windows" else "which", "rclone"], | |
| capture_output=True, text=True, timeout=5, | |
| encoding='utf-8', errors='replace' | |
| ) | |
| if result.returncode == 0: | |
| return result.stdout.strip().splitlines()[0] | |
| except Exception: | |
| pass | |
| return None | |
| def _ensure_boto3() -> bool: | |
| """boto3๊ฐ ์ค์น๋ผ ์๋์ง ํ์ธํ๊ณ , ์์ผ๋ฉด ์๋ ์ค์นํฉ๋๋ค.""" | |
| try: | |
| import boto3 | |
| return True | |
| except ImportError: | |
| pass | |
| print("[Imperial Setup] boto3 ๋ฏธ์ค์น ๊ฐ์ง โ R2 ์ง์ ์ ์์ ์ํด ์๋ ์ค์นํฉ๋๋ค...") | |
| try: | |
| result = subprocess.run( | |
| [sys.executable, "-m", "pip", "install", "boto3", "--quiet"], | |
| capture_output=True, text=True, timeout=120, | |
| encoding='utf-8', errors='replace' | |
| ) | |
| if result.returncode == 0: | |
| print("[Imperial Setup] boto3 ์ค์น ์๋ฃ โ") | |
| return True | |
| else: | |
| print(f"[Imperial Setup] boto3 ์ค์น ์คํจ: {result.stderr.strip()}") | |
| return False | |
| except Exception as e: | |
| print(f"[Imperial Setup] boto3 ์๋ ์ค์น ์ค ์ค๋ฅ: {e}") | |
| return False | |
| def check_and_install_rclone() -> bool: | |
| """ | |
| rclone์ด ์ฌ์ฉ ๊ฐ๋ฅํ์ง ํ์ธํฉ๋๋ค. | |
| - PATH์ ์์ผ๋ฉด RCLONE_EXE๋ฅผ ํด๋น ๊ฒฝ๋ก๋ก ์ ๋ฐ์ดํธํฉ๋๋ค. | |
| - ~/.rclone/ ์ ์์ผ๋ฉด ๊ทธ๊ฒ์ ์ฌ์ฉํฉ๋๋ค. | |
| - ์์ผ๋ฉด ๊ฒฝ๊ณ ์ถ๋ ฅ ํ boto3 ํด๋ฐฑ์ ์ํด boto3 ์๋ ์ค์น๋ฅผ ์๋ํฉ๋๋ค. | |
| ๋ฐํ๊ฐ: rclone ์ฌ์ฉ ๊ฐ๋ฅ ์ฌ๋ถ (bool) | |
| """ | |
| global RCLONE_EXE | |
| # boto3๋ ํญ์ ๋ณด์ฅ (rclone ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ R2 ํด๋ฐฑ์ฉ์ผ๋ก ํ์) | |
| _ensure_boto3() | |
| # 1. PATH ์ฐ์ ํ์ | |
| path_exe = _rclone_in_path() | |
| if path_exe and os.path.exists(path_exe): | |
| RCLONE_EXE = path_exe | |
| print(f"[Rclone] PATH์์ ๋ฐ๊ฒฌ: {RCLONE_EXE}") | |
| return True | |
| # 2. ~/.rclone/ ํ์ | |
| if os.path.exists(RCLONE_EXE): | |
| print(f"[Rclone] ๋ก์ปฌ ์ค์น ํ์ธ: {RCLONE_EXE}") | |
| return True | |
| # 3. ์์ โ boto3 ํด๋ฐฑ์ผ๋ก R2๋ ๊ณ์ ์ฌ์ฉ ๊ฐ๋ฅ | |
| print("[Rclone] rclone ๋ฏธ์ค์น โ R2๋ boto3๋ก ์ง์ ์ ์ํฉ๋๋ค. Google Drive ๋๊ธฐํ๋ง ๋นํ์ฑํ๋ฉ๋๋ค.") | |
| return False | |