|
| 1 | +import os |
| 2 | +import tarfile |
1 | 3 | from pathlib import Path |
2 | 4 |
|
3 | | -from git.repo import Repo |
| 5 | +import git |
| 6 | +import wget |
4 | 7 | from od_compiler.util.compiler_logger import compile_logger |
5 | 8 |
|
6 | 9 |
|
7 | | -def updateOD(od_repo_path: Path, clean: int = False) -> None: |
| 10 | +def updateOD(od_path: Path, clean: int = False) -> None: |
8 | 11 | """ |
9 | 12 | Update the OpenDream repository if it exists. If it doesn't, clone a fresh copy. |
10 | 13 | """ |
11 | | - if clean: |
12 | | - from shutil import rmtree |
13 | | - |
14 | | - rmtree(od_repo_path) |
15 | | - |
16 | | - if Path.exists(od_repo_path): |
17 | | - od = Repo(od_repo_path) |
18 | | - od.remote().fetch() |
19 | | - # We reset HEAD to the upstream commit as a faster and more reliable way to stay up to date |
20 | | - od.head.reset(commit="origin/master", working_tree=True) |
21 | | - else: |
22 | | - compile_logger.info("Repo not found. Cloning from GitHub.") |
23 | | - od = Repo.clone_from( |
24 | | - url="https://github.com/OpenDreamProject/OpenDream.git", |
25 | | - to_path=od_repo_path, |
26 | | - multi_options=["--depth 1", "--recurse-submodules", "--shallow-submodules"], |
27 | | - ) |
28 | | - |
29 | | - compile_logger.info(f"The OpenDream repo is at: {od.head.commit.hexsha}") |
30 | | - updateSubmodules(od_repo=od) |
31 | 14 |
|
| 15 | + compiler_path = od_path / "compiler.tar.gz" |
| 16 | + server_path = od_path / "server.tar.gz" |
| 17 | + tag_path = od_path / "tag" |
32 | 18 |
|
33 | | -def updateSubmodules(od_repo: Repo) -> None: |
34 | | - """ |
35 | | - Recursively update and initialize submodules |
| 19 | + if clean: |
| 20 | + from shutil import rmtree |
36 | 21 |
|
37 | | - od_repo: OpenDream repository with the submodules |
38 | | - """ |
39 | | - for submodule in od_repo.submodules: |
40 | | - submodule.update(init=True, recursive=True) |
41 | | - compile_logger.info(f"{submodule.name} is at: {submodule.hexsha}") |
| 22 | + rmtree(od_path) |
| 23 | + |
| 24 | + if not Path.exists(od_path): |
| 25 | + os.mkdir(od_path) |
| 26 | + remote_heads = git.cmd.Git().ls_remote("https://github.com/OpenDreamProject/OpenDream/", heads=True) |
| 27 | + tag_path.touch(exist_ok=True) |
| 28 | + with open(str(tag_path), "r+") as tag: |
| 29 | + if tag.readline() == remote_heads: |
| 30 | + compile_logger.info("OpenDream is already up to date.") |
| 31 | + return |
| 32 | + else: |
| 33 | + tag.seek(0) |
| 34 | + tag.write(remote_heads) |
| 35 | + |
| 36 | + if compiler_path.exists(): |
| 37 | + os.remove(compiler_path) |
| 38 | + if server_path.exists(): |
| 39 | + os.remove(server_path) |
| 40 | + wget.download( |
| 41 | + "https://github.com/OpenDreamProject/OpenDream/releases/download/latest/DMCompiler_linux-x64.tar.gz", |
| 42 | + str(compiler_path), |
| 43 | + ) |
| 44 | + wget.download( |
| 45 | + "https://github.com/OpenDreamProject/OpenDream/releases/download/latest/OpenDreamServer_linux-x64.tar.gz", |
| 46 | + str(server_path), |
| 47 | + ) |
| 48 | + |
| 49 | + with tarfile.open(str(compiler_path), "r:gz") as tar: |
| 50 | + tar.extractall(path=od_path) |
| 51 | + with tarfile.open(str(server_path), "r:gz") as tar: |
| 52 | + tar.extractall(path=od_path) |
| 53 | + compile_logger.info(f"The OpenDream repo is at: {remote_heads}") |
0 commit comments