Merge pull request #4 from idle-org/feature/version_update
Updated path on windows
This commit is contained in:
commit
cdff66dc39
|
|
@ -11,7 +11,8 @@ class AgnosticPaths:
|
||||||
self.ptb = ptb
|
self.ptb = ptb
|
||||||
self.os = self.get_os()
|
self.os = self.get_os()
|
||||||
self.main_path = self.get_path()
|
self.main_path = self.get_path()
|
||||||
self.versions = self.get_version()
|
self.version = self.get_version()
|
||||||
|
self.update_path()
|
||||||
|
|
||||||
def get_os(self):
|
def get_os(self):
|
||||||
platform = sys.platform
|
platform = sys.platform
|
||||||
|
|
@ -42,20 +43,23 @@ class AgnosticPaths:
|
||||||
versions = []
|
versions = []
|
||||||
if self.os == 'windows':
|
if self.os == 'windows':
|
||||||
for element in os.listdir(self.main_path):
|
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)
|
versions.append(element)
|
||||||
if not versions:
|
if not versions:
|
||||||
raise FileNotFoundError("Could not find discord version folder.")
|
raise FileNotFoundError("Could not find discord version folder.")
|
||||||
versions.sort()
|
versions.sort()
|
||||||
return versions[-1]
|
return versions[-1]
|
||||||
if self.os == 'linux':
|
elif self.os == 'linux':
|
||||||
from json import load
|
from json import load
|
||||||
with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile:
|
with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile:
|
||||||
versions = load(versionFile)
|
versions = load(versionFile)
|
||||||
return versions['version']
|
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):
|
def list(self, *args):
|
||||||
"""
|
"""
|
||||||
|
|
@ -80,19 +84,14 @@ class AgnosticPaths:
|
||||||
files.append(element)
|
files.append(element)
|
||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
def __call__(self, *args, version=None):
|
def __call__(self, *args):
|
||||||
if version is None:
|
_path = os.path.join(self.main_path, *args)
|
||||||
_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)
|
|
||||||
if not os.path.exists(_path):
|
if not os.path.exists(_path):
|
||||||
raise FileNotFoundError(f"Could not find {_path}")
|
raise FileNotFoundError(f"Could not find {_path}")
|
||||||
return _path
|
return _path
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
def __str__(self):
|
||||||
return self.main_path
|
return self.main_path
|
||||||
|
|
@ -101,6 +100,6 @@ class AgnosticPaths:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
path = AgnosticPaths("")
|
path = AgnosticPaths("")
|
||||||
print(path)
|
print(path)
|
||||||
print(path.versions)
|
print(path.version)
|
||||||
print(path.list_dir_files())
|
print(path.list_dir_files())
|
||||||
print(path.list())
|
print(path.list())
|
||||||
|
|
|
||||||
Reference in New Issue