|
from src.ui import create_ui |
|
|
|
import os |
|
import subprocess |
|
import urllib.request |
|
import tarfile |
|
|
|
def install_minizinc(): |
|
install_path = "/home/user/minizinc" |
|
if os.path.exists(os.path.join(install_path, "bin", "minizinc")): |
|
print("β
MiniZinc already installed.") |
|
return |
|
|
|
print("β¬οΈ Downloading MiniZinc...") |
|
url = "https://github.com/MiniZinc/MiniZincIDE/releases/download/2.9.0/MiniZincIDE-2.9.0-bundle-linux-x86_64.tgz" |
|
bundle_path = "/tmp/minizinc.tgz" |
|
|
|
urllib.request.urlretrieve(url, bundle_path) |
|
|
|
print("π¦ Extracting MiniZinc...") |
|
os.makedirs(install_path, exist_ok=True) |
|
with tarfile.open(bundle_path, "r:gz") as tar: |
|
tar.extractall(path=install_path, members=_strip_top_level(tar)) |
|
|
|
print("β
MiniZinc installed.") |
|
|
|
def _strip_top_level(tar): |
|
|
|
top_level = tar.getmembers()[0].name.split('/')[0] |
|
for member in tar.getmembers(): |
|
member.path = '/'.join(member.path.split('/')[1:]) |
|
yield member |
|
|
|
|
|
install_minizinc() |
|
os.environ["PATH"] = f"/home/user/minizinc/bin:{os.environ['PATH']}" |
|
|
|
|
|
try: |
|
version = subprocess.check_output(["minizinc", "--version"], text=True) |
|
print("π§ MiniZinc version:", version.strip()) |
|
except Exception as e: |
|
print("β MiniZinc install failed:", e) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo = create_ui() |
|
demo.queue().launch() |