-
Notifications
You must be signed in to change notification settings - Fork 1
/
syncutils.py
116 lines (103 loc) · 3.17 KB
/
syncutils.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Thanks to @Vexed01 on GitHub for this code (https://github.com/Vexed01/Vex-Cogs)!
# Copy the utils from https://github.com/AAA3A-AAA3A/AAA3A_utils to each cog in this repo.
import datetime
import json
import os
import shutil
from pathlib import Path
import git
from git import Repo
# git -C %USERPROFILE%\Documents\GitHub\AAA3A_utils rev-list HEAD --count AAA3A_utils
VERSION = 6.6
if VERSION is None:
utils_repo_clone_location = Path(os.environ["USERPROFILE"] + "\\Documents\\GitHub\\AAA3A_utils_clone_for_sync")
utils_repo = Repo.clone_from(
"https://github.com/AAA3A-AAA3A/AAA3A_utils.git", utils_repo_clone_location
)
utils_location = utils_repo_clone_location / "AAA3A_utils"
commit = utils_repo.head.commit
README_MD_TEXT = """## My utils
Hello there! If you're contributing or taking a look, everything in this folder
is synced from a master repo at https://github.com/AAA3A-AAA3A/AAA3A_utils by GitHub Actions -
so it's probably best to look/edit there.
---
Last sync at: {time}
Commit: [`{commit}`](https://github.com/AAA3A-AAA3A/AAA3A_utils/commit/{commit})
"""
readme = README_MD_TEXT.format(
time=datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z"),
commit=commit,
)
with open(utils_location / "README.md", "w") as fp:
fp.write(readme)
with open(utils_location / "commit.json", "w") as fp:
fp.write(json.dumps({"latest_commit": str(commit)}))
else:
destination = Path(os.environ["USERPROFILE"] + "\\Documents\\GitHub\\AAA3A_utils\\AAA3A_utils")
with open(destination / "__version__.py", "w") as fp:
fp.write(f"__version__ = {VERSION}\n")
all_cogs = [
"AcronymGame",
"AntiNuke",
"AutoTraceback",
"Calculator",
"ClearChannel",
"CmdChannel",
"CodeSnippets",
"CommandsButtons",
"ConsoleLogs",
"CtxVar",
"Dashboard",
"Dev",
"DevUtils",
"DiscordEdit",
"DiscordModals",
"DiscordSearch",
"Draw",
"DropdownsTexts",
"EditFile",
"EmbedUtils",
"ExportChannel",
"GetDocs",
"GetLoc",
"GistsHandler",
"GuildStats",
"Ip",
"LinkQuoter",
"LintCodes",
"Medicat",
"MemberPrefix",
"MemoryGame",
"Minecraft",
"PresenceChart",
"ReactToCommand",
"Recipes",
"Reminders",
"RolesButtons",
"RunCode",
"Seen",
"SimpleSanction",
"Snipe",
"SplitOrStealGame",
"Sudo",
"TempRoles",
"TicketTool",
"TransferChannel",
"UrlButtons",
"ViewPermissions",
"Webhook",
]
cog_folders = [cog.lower() for cog in all_cogs]
for cog in cog_folders:
destination = Path(os.environ["USERPROFILE"] + "\\Documents\\GitHub\\AAA3A-cogs") / cog / "AAA3A_utils"
if destination.exists():
shutil.rmtree(destination)
if VERSION is None:
shutil.copytree(utils_location, destination)
else:
destination = Path(os.environ["USERPROFILE"] + "\\Documents\\GitHub\\AAA3A-cogs") / cog
with open(destination / "utils_version.json", "w") as fp:
fp.write(json.dumps({"needed_utils_version": VERSION}))
if VERSION is None:
utils_repo.close()
git.rmtree(utils_repo_clone_location)