mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Downloader] Fix non relative data path (#1150)
This commit is contained in:
parent
ef7216722f
commit
02d7193a92
@ -5,6 +5,7 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Union, MutableMapping, Any
|
||||
|
||||
from redbot.core import data_manager
|
||||
from .log import log
|
||||
from .json_mixins import RepoJSONMixin
|
||||
|
||||
@ -191,11 +192,13 @@ class Installable(RepoJSONMixin):
|
||||
return info
|
||||
|
||||
def to_json(self):
|
||||
data_path = data_manager.cog_data_path()
|
||||
return {
|
||||
"location": self._location.relative_to(Path.cwd()).parts
|
||||
"location": self._location.relative_to(data_path).parts
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, data: dict):
|
||||
location = Path.cwd() / Path(*data["location"])
|
||||
data_path = data_manager.cog_data_path()
|
||||
location = data_path / Path(*data["location"])
|
||||
return cls(location=location)
|
||||
|
||||
@ -468,19 +468,21 @@ class Repo(RepoJSONMixin):
|
||||
)
|
||||
|
||||
def to_json(self):
|
||||
data_path = data_manager.cog_data_path()
|
||||
return {
|
||||
"url": self.url,
|
||||
"name": self.name,
|
||||
"branch": self.branch,
|
||||
"folder_path": self.folder_path.relative_to(Path.cwd()).parts,
|
||||
"folder_path": self.folder_path.relative_to(data_path).parts,
|
||||
"available_modules": [m.to_json() for m in self.available_modules]
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, data):
|
||||
data_path = data_manager.cog_data_path()
|
||||
# noinspection PyTypeChecker
|
||||
return Repo(data['name'], data['url'], data['branch'],
|
||||
Path.cwd() / Path(*data['folder_path']),
|
||||
data_path / Path(*data['folder_path']),
|
||||
tuple([Installable.from_json(m) for m in data['available_modules']]))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user