mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 04:08:56 -05:00
[Downloader] Fixed issue with patch notes not showing (#726)
Fixes #725
This commit is contained in:
parent
bb4a036573
commit
d80a660e95
@ -13,6 +13,7 @@ from functools import partial
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from time import time
|
from time import time
|
||||||
from importlib.util import find_spec
|
from importlib.util import find_spec
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
NUM_THREADS = 4
|
NUM_THREADS = 4
|
||||||
REPO_NONEX = 0x1
|
REPO_NONEX = 0x1
|
||||||
@ -46,8 +47,8 @@ class Downloader:
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.disclaimer_accepted = False
|
self.disclaimer_accepted = False
|
||||||
self.path = "data/downloader/"
|
self.path = os.path.join("data", "downloader")
|
||||||
self.file_path = "data/downloader/repos.json"
|
self.file_path = os.path.join(self.path, "repos.json")
|
||||||
# {name:{url,cog1:{installed},cog1:{installed}}}
|
# {name:{url,cog1:{installed},cog1:{installed}}}
|
||||||
self.repos = dataIO.load_json(self.file_path)
|
self.repos = dataIO.load_json(self.file_path)
|
||||||
self.executor = ThreadPoolExecutor(NUM_THREADS)
|
self.executor = ThreadPoolExecutor(NUM_THREADS)
|
||||||
@ -317,7 +318,7 @@ class Downloader:
|
|||||||
await self.bot.say("Ok then, you can reload cogs with"
|
await self.bot.say("Ok then, you can reload cogs with"
|
||||||
" `{}reload <cog_name>`".format(ctx.prefix))
|
" `{}reload <cog_name>`".format(ctx.prefix))
|
||||||
elif answer.content.lower().strip() == "yes":
|
elif answer.content.lower().strip() == "yes":
|
||||||
registry = dataIO.load_json("data/red/cogs.json")
|
registry = dataIO.load_json(os.path.join("data", "red", "cogs.json"))
|
||||||
update_list = []
|
update_list = []
|
||||||
fail_list = []
|
fail_list = []
|
||||||
for repo, cog, _ in installed_updated_cogs:
|
for repo, cog, _ in installed_updated_cogs:
|
||||||
@ -344,9 +345,8 @@ class Downloader:
|
|||||||
|
|
||||||
def patch_notes_handler(self, repo_cog_hash_pairs):
|
def patch_notes_handler(self, repo_cog_hash_pairs):
|
||||||
for repo, cog, oldhash in repo_cog_hash_pairs:
|
for repo, cog, oldhash in repo_cog_hash_pairs:
|
||||||
pathsplit = self.repos[repo][cog]['file'].split('/')
|
repo_path = os.path.join('data', 'downloader', repo)
|
||||||
repo_path = os.path.join(*pathsplit[:-2])
|
cogfile = os.path.join(cog, cog + ".py")
|
||||||
cogfile = os.path.join(*pathsplit[-2:])
|
|
||||||
cmd = ["git", "-C", repo_path, "log", "--relative-date",
|
cmd = ["git", "-C", repo_path, "log", "--relative-date",
|
||||||
"--reverse", oldhash + '..', cogfile
|
"--reverse", oldhash + '..', cogfile
|
||||||
]
|
]
|
||||||
@ -449,7 +449,7 @@ class Downloader:
|
|||||||
else:
|
else:
|
||||||
reqs_failed = True
|
reqs_failed = True
|
||||||
|
|
||||||
to_path = os.path.join("cogs/", cog + ".py")
|
to_path = os.path.join("cogs", cog + ".py")
|
||||||
|
|
||||||
print("Copying {}...".format(cog))
|
print("Copying {}...".format(cog))
|
||||||
shutil.copy(path, to_path)
|
shutil.copy(path, to_path)
|
||||||
@ -457,7 +457,7 @@ class Downloader:
|
|||||||
if os.path.exists(cog_data_path):
|
if os.path.exists(cog_data_path):
|
||||||
print("Copying {}'s data folder...".format(cog))
|
print("Copying {}'s data folder...".format(cog))
|
||||||
distutils.dir_util.copy_tree(cog_data_path,
|
distutils.dir_util.copy_tree(cog_data_path,
|
||||||
os.path.join('data/', cog))
|
os.path.join('data', cog))
|
||||||
self.repos[repo_name][cog]['INSTALLED'] = True
|
self.repos[repo_name][cog]['INSTALLED'] = True
|
||||||
self.save_repos()
|
self.save_repos()
|
||||||
if not reqs_failed:
|
if not reqs_failed:
|
||||||
@ -520,8 +520,24 @@ class Downloader:
|
|||||||
return bool(find_spec(name))
|
return bool(find_spec(name))
|
||||||
|
|
||||||
def _do_first_run(self):
|
def _do_first_run(self):
|
||||||
invalid = []
|
|
||||||
save = False
|
save = False
|
||||||
|
repos_copy = deepcopy(self.repos)
|
||||||
|
|
||||||
|
# Issue 725
|
||||||
|
for repo in repos_copy:
|
||||||
|
for cog in repos_copy[repo]:
|
||||||
|
cog_data = repos_copy[repo][cog]
|
||||||
|
if isinstance(cog_data, str): # ... url field
|
||||||
|
continue
|
||||||
|
for k, v in cog_data.items():
|
||||||
|
if k in ("file", "folder"):
|
||||||
|
repos_copy[repo][cog][k] = os.path.normpath(cog_data[k])
|
||||||
|
|
||||||
|
if self.repos != repos_copy:
|
||||||
|
self.repos = repos_copy
|
||||||
|
save = True
|
||||||
|
|
||||||
|
invalid = []
|
||||||
|
|
||||||
for repo in self.repos:
|
for repo in self.repos:
|
||||||
broken = 'url' in self.repos[repo] and len(self.repos[repo]) == 1
|
broken = 'url' in self.repos[repo] and len(self.repos[repo]) == 1
|
||||||
@ -580,20 +596,20 @@ class Downloader:
|
|||||||
if "@" in url: # Specific branch
|
if "@" in url: # Specific branch
|
||||||
url, branch = url.rsplit("@", maxsplit=1)
|
url, branch = url.rsplit("@", maxsplit=1)
|
||||||
if branch is None:
|
if branch is None:
|
||||||
p = run(["git", "clone", url, dd + name])
|
p = run(["git", "clone", url, folder])
|
||||||
else:
|
else:
|
||||||
p = run(["git", "clone", "-b", branch, url, dd + name])
|
p = run(["git", "clone", "-b", branch, url, folder])
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise CloningError()
|
raise CloningError()
|
||||||
self.populate_list(name)
|
self.populate_list(name)
|
||||||
return name, REPO_CLONE, None
|
return name, REPO_CLONE, None
|
||||||
else:
|
else:
|
||||||
rpbcmd = ["git", "-C", dd + name, "rev-parse", "--abbrev-ref", "HEAD"]
|
rpbcmd = ["git", "-C", folder, "rev-parse", "--abbrev-ref", "HEAD"]
|
||||||
p = run(rpbcmd, stdout=PIPE)
|
p = run(rpbcmd, stdout=PIPE)
|
||||||
branch = p.stdout.decode().strip()
|
branch = p.stdout.decode().strip()
|
||||||
|
|
||||||
rpcmd = ["git", "-C", dd + name, "rev-parse", branch]
|
rpcmd = ["git", "-C", folder, "rev-parse", branch]
|
||||||
p = run(["git", "-C", dd + name, "reset", "--hard",
|
p = run(["git", "-C", folder, "reset", "--hard",
|
||||||
"origin/%s" % branch, "-q"])
|
"origin/%s" % branch, "-q"])
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise UpdateError("Error resetting to origin/%s" % branch)
|
raise UpdateError("Error resetting to origin/%s" % branch)
|
||||||
@ -601,7 +617,7 @@ class Downloader:
|
|||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise UpdateError("Unable to determine old commit hash")
|
raise UpdateError("Unable to determine old commit hash")
|
||||||
oldhash = p.stdout.decode().strip()
|
oldhash = p.stdout.decode().strip()
|
||||||
p = run(["git", "-C", dd + name, "pull", "-q", "--ff-only"])
|
p = run(["git", "-C", folder, "pull", "-q", "--ff-only"])
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise UpdateError("Error pulling updates")
|
raise UpdateError("Error pulling updates")
|
||||||
p = run(rpcmd, stdout=PIPE)
|
p = run(rpcmd, stdout=PIPE)
|
||||||
@ -614,7 +630,7 @@ class Downloader:
|
|||||||
self.populate_list(name)
|
self.populate_list(name)
|
||||||
self.save_repos()
|
self.save_repos()
|
||||||
ret = {}
|
ret = {}
|
||||||
cmd = ['git', '-C', dd + name, 'diff', '--no-commit-id',
|
cmd = ['git', '-C', folder, 'diff', '--no-commit-id',
|
||||||
'--name-status', oldhash, newhash]
|
'--name-status', oldhash, newhash]
|
||||||
p = run(cmd, stdout=PIPE)
|
p = run(cmd, stdout=PIPE)
|
||||||
|
|
||||||
@ -658,13 +674,13 @@ class Downloader:
|
|||||||
|
|
||||||
|
|
||||||
def check_folders():
|
def check_folders():
|
||||||
if not os.path.exists("data/downloader"):
|
if not os.path.exists(os.path.join("data", "downloader")):
|
||||||
print('Making repo downloads folder...')
|
print('Making repo downloads folder...')
|
||||||
os.mkdir('data/downloader')
|
os.mkdir(os.path.join("data", "downloader"))
|
||||||
|
|
||||||
|
|
||||||
def check_files():
|
def check_files():
|
||||||
f = "data/downloader/repos.json"
|
f = os.path.join("data", "downloader", "repos.json")
|
||||||
if not dataIO.is_valid_json(f):
|
if not dataIO.is_valid_json(f):
|
||||||
print("Creating default data/downloader/repos.json")
|
print("Creating default data/downloader/repos.json")
|
||||||
dataIO.save_json(f, {})
|
dataIO.save_json(f, {})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user