Updated path on windows

This commit is contained in:
Maximilien Rigaut 2022-06-21 20:38:52 +02:00
parent 509d013884
commit 4311692cb4
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
1 changed files with 13 additions and 14 deletions

View File

@ -11,7 +11,8 @@ class AgnosticPaths:
self.ptb = ptb
self.os = self.get_os()
self.main_path = self.get_path()
self.versions = self.get_version()
self.version = self.get_version()
self.update_path()
def get_os(self):
platform = sys.platform
@ -42,20 +43,23 @@ class AgnosticPaths:
versions = []
if self.os == 'windows':
for element in os.listdir(self.main_path):
if re.match(r"app-[\d\.]+", element):
if re.match(r"app-[\d.]+", element):
versions.append(element)
if not versions:
raise FileNotFoundError("Could not find discord version folder.")
versions.sort()
return versions[-1]
if self.os == 'linux':
elif self.os == 'linux':
from json import load
with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile:
versions = load(versionFile)
return versions['version']
else:
raise OSError("Can't find for version on your OS.")
def update_path(self):
if self.os == 'windows':
self.main_path = os.path.join(self.main_path, self.version)
def list(self, *args):
"""
@ -80,19 +84,14 @@ class AgnosticPaths:
files.append(element)
return dirs, files
def __call__(self, *args, version=None):
if version is None:
_path = os.path.join(self.main_path, *args)
elif version == "LATEST":
_path = os.path.join(self.main_path, self.latest_version, *args)
else:
_path = os.path.join(self.main_path, version, *args)
def __call__(self, *args):
_path = os.path.join(self.main_path, *args)
if not os.path.exists(_path):
raise FileNotFoundError(f"Could not find {_path}")
return _path
def __repr__(self):
return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.latest_version})"
return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.version})"
def __str__(self):
return self.main_path
@ -101,6 +100,6 @@ class AgnosticPaths:
if __name__ == '__main__':
path = AgnosticPaths("")
print(path)
print(path.versions)
print(path.version)
print(path.list_dir_files())
print(path.list())