forked from GTNewHorizons/DreamAssemblerXXL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_mod.py
executable file
·73 lines (56 loc) · 1.61 KB
/
add_mod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import sys
import click
from github import Github
from github.Repository import Repository
from gtnh.exceptions import RepoNotFoundException
from gtnh.mod_info import ModInfo
from gtnh.utils import (
get_latest_release,
get_license,
get_maven,
get_mod_asset,
get_token,
load_gtnh_manifest,
sort_and_write_modpack,
)
@click.command()
@click.argument("name")
def add_mod(name: str) -> None:
print(f"Trying to add {name}")
new_repo = get_repo(name)
gtnh = load_gtnh_manifest()
if gtnh.has_github_mod(new_repo.name):
print(f"Mod already added {name}")
sys.exit()
new_mod = new_mod_from_repo(new_repo)
gtnh.github_mods.append(new_mod)
sort_and_write_modpack(gtnh)
print("Success!")
def get_repo(name: str) -> Repository:
g = Github(get_token())
o = g.get_organization("GTNewHorizons")
try:
return o.get_repo(name)
except Exception:
raise RepoNotFoundException(f"Repo not Found {name}")
def new_mod_from_repo(repo: Repository) -> ModInfo:
license = get_license(repo)
repo_url = repo.html_url
latest_release = get_latest_release(repo)
version = latest_release.tag_name
asset = get_mod_asset(latest_release)
maven = get_maven(repo.name)
return ModInfo(
name=repo.name,
repo_url=repo_url,
license=license,
version=version,
browser_download_url=asset.browser_download_url,
download_url=asset.url,
tagged_at=asset.created_at,
filename=asset.name,
maven=maven,
)
if __name__ == "__main__":
add_mod()