mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
wip: implement dependencies & install
This commit is contained in:
90
software.py
90
software.py
@@ -1,56 +1,92 @@
|
||||
import yaml
|
||||
import os
|
||||
import localaction
|
||||
import zipfile
|
||||
|
||||
class Software:
|
||||
|
||||
def __init__(self, directory, backend):
|
||||
def __init__(self, meta_file, backend):
|
||||
|
||||
if os.path.isfile(directory) and directory.endswith("meta.yaml"):
|
||||
directory = os.path.dirname(directory)
|
||||
|
||||
self.directory = directory
|
||||
self._load_from_yaml()
|
||||
self.meta_file = meta_file
|
||||
self.directory = os.path.dirname(meta_file)
|
||||
self.backend = backend
|
||||
self.cache_dir = os.path.join("cache", self.directory)
|
||||
self._load_from_yaml()
|
||||
|
||||
def _load_from_yaml(self):
|
||||
|
||||
fullpath = os.path.join(self.directory, "meta.yaml")
|
||||
self.info_file = fullpath
|
||||
with open(fullpath) as f:
|
||||
meta = yaml.safe_load(f)
|
||||
content = self.backend.get(self.meta_file, self.cache_dir, return_content=True)
|
||||
|
||||
self.title = meta.get("title")
|
||||
self.genre = meta.get("genre")
|
||||
self.description = meta.get("description")
|
||||
self.dependencies = meta.get("dependencies")
|
||||
self.link_only = meta.get("link_only")
|
||||
self.link = meta.get("link")
|
||||
self.extra_files = meta.get("extra_files")
|
||||
meta = yaml.safe_load(content)
|
||||
self.title = meta.get("title")
|
||||
self.genre = meta.get("genre")
|
||||
self.description = meta.get("description")
|
||||
self.dependencies = meta.get("dependencies")
|
||||
self.link_only = meta.get("link_only")
|
||||
self.link = meta.get("link")
|
||||
self.extra_files = meta.get("extra_files")
|
||||
self.run_exe = meta.get("run_exe")
|
||||
self.installer = meta.get("installer")
|
||||
|
||||
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||
|
||||
self.reg_files = self.backend.list(os.path.join(self.directory, "registry_files"), fullpaths=True)
|
||||
|
||||
self.pictures = [os.path.join(self.directory, "pictures", p) for p in
|
||||
os.listdir(os.path.join(self.directory, "pictures"))]
|
||||
|
||||
def get_thumbnail(self):
|
||||
'''Return the thumbnail for this software'''
|
||||
|
||||
if not self.pictures:
|
||||
return None
|
||||
|
||||
return self.pictures[0]
|
||||
|
||||
def _extract_to_target(self, cache_src, target):
|
||||
'''Extract a cached, downloaded zip to the target location'''
|
||||
|
||||
software_path = os.path.join(target, self.title)
|
||||
os.makedirs(software_path, exist_ok=True)
|
||||
|
||||
with zipfile.ZipFile(cache_src, 'r') as zip_ref:
|
||||
zip_ref.extractall(software_path)
|
||||
|
||||
def install(self):
|
||||
'''Install this software from the backend'''
|
||||
|
||||
local_file = self.backend.get_exe_or_data():
|
||||
print("Installing:", self.title, self.directory)
|
||||
|
||||
path = os.path.join(self.directory, "main_dir")
|
||||
remote_file = self.backend.list(path, fullpaths=True)[0]
|
||||
local_file = self.backend.get(remote_file, self.cache_dir)
|
||||
|
||||
# execute or unpack #
|
||||
if local_file.endswith(".exe"):
|
||||
localaction.run_exe(local_file)
|
||||
elif local_file.endswith(".zip"):
|
||||
_extract_to_target(INSTALL_DIR)
|
||||
self._extract_to_target(local_file, self.backend.install_dir)
|
||||
|
||||
# download registry
|
||||
# install registry
|
||||
# TODO dependencies #
|
||||
# download gamefiles
|
||||
# install gamefiles
|
||||
|
||||
# download & install registry files #
|
||||
for rf in self.reg_files:
|
||||
path = self.backend.get(rf, cache_dir=self.cache_dir)
|
||||
localaction.install_registry_file(path)
|
||||
|
||||
# install dependencies #
|
||||
if self.dependencies:
|
||||
avail_software = self.backend.find_all_metadata()
|
||||
for s in avail_software:
|
||||
if s.title in self.dependencies:
|
||||
s.install()
|
||||
|
||||
# run installer if set #
|
||||
if self.installer:
|
||||
installer_path = os.path.join(self.backend.install_dir, self.title, self.installer)
|
||||
print("Running installer:", installer_path)
|
||||
localaction.run_exe(installer_path)
|
||||
|
||||
# TODO download & install gamefiles #
|
||||
|
||||
def run(self):
|
||||
'''Run the configured exe for this software'''
|
||||
if self.run_exe:
|
||||
localaction.run_exe(os.path.join(self.backend.install_dir, self.title, self.run_exe))
|
||||
Reference in New Issue
Block a user