mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-05 22:51:34 +01:00
feat: implement bulk execution in python
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
# windows imports #
|
||||
if os.name == "nt":
|
||||
@@ -52,6 +53,15 @@ def resolve_lnk(lnk_file_path):
|
||||
def run_exe(path, synchronous=False):
|
||||
'''Launches a given software'''
|
||||
|
||||
if type(path) == str:
|
||||
paths = [path]
|
||||
else:
|
||||
paths = path
|
||||
|
||||
# sanity check path is list #
|
||||
if not type(path) == list:
|
||||
raise AssertionError("ERROR: run_exe could not build a list of paths")
|
||||
|
||||
if os.name != "nt":
|
||||
if ".lnk" in path:
|
||||
subprocess.Popen(["wine64", "start", path])
|
||||
@@ -62,16 +72,18 @@ def run_exe(path, synchronous=False):
|
||||
if synchronous:
|
||||
raise NotImplementedError("SYNC not yet implemented")
|
||||
|
||||
if path.endswith(".lnk"):
|
||||
path = resolve_lnk(path)
|
||||
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||
|
||||
print("Executing:", path)
|
||||
print("Executing:", paths)
|
||||
|
||||
try:
|
||||
subprocess.Popen(path, cwd=os.path.dirname(path))
|
||||
if paths[0].endswith(".reg"):
|
||||
raise OSError("WinError 740")
|
||||
subprocess.Popen(path, cwd=os.path.dirname(paths[0])) # TODO fix this BS
|
||||
except OSError as e:
|
||||
if "WinError 740" in str(e):
|
||||
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File", "windows_run_as_admin.ps1", path],
|
||||
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File",
|
||||
"windows_run_as_admin.ps1", json.dumps(paths)],
|
||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
print(p.communicate())
|
||||
else:
|
||||
@@ -87,4 +99,4 @@ def uninstall_registry_file(registry_file):
|
||||
|
||||
def uninstall_extra_files(extra_file_list, path):
|
||||
'''Uninstall all extra game data'''
|
||||
pass
|
||||
pass
|
||||
18
software.py
18
software.py
@@ -53,6 +53,7 @@ class Software:
|
||||
self.extra_files = meta.get("extra_files")
|
||||
self.run_exe = meta.get("run_exe")
|
||||
self.installer = meta.get("installer")
|
||||
self.installer_no_admin = meta.get("installer_no_admin")
|
||||
|
||||
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||
@@ -104,6 +105,9 @@ class Software:
|
||||
def install(self):
|
||||
'''Install this software from the backend'''
|
||||
|
||||
# things to execute #
|
||||
admin_run_list = []
|
||||
|
||||
print("Installing:", self.title, self.directory)
|
||||
|
||||
# handle link-only software #
|
||||
@@ -139,7 +143,8 @@ class Software:
|
||||
print("Install dir Registry:", target_install_dir)
|
||||
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
||||
|
||||
localaction.install_registry_file(path)
|
||||
admin_run_list.append(path)
|
||||
# localaction.install_registry_file(path)
|
||||
|
||||
# install dependencies #
|
||||
if self.dependencies:
|
||||
@@ -157,12 +162,19 @@ class Software:
|
||||
|
||||
|
||||
print("Running installer:", installer_path)
|
||||
localaction.run_exe(installer_path)
|
||||
if not self.installer_no_admin:
|
||||
admin_run_list.append(installer_path)
|
||||
else:
|
||||
localaction.run_exe(installer_path)
|
||||
|
||||
if admin_run_list:
|
||||
print("admin list", admin_run_list)
|
||||
localaction.run_exe(admin_run_list)
|
||||
|
||||
# install gamefiles #
|
||||
if self.extra_files:
|
||||
for src, dest in self.extra_files.items():
|
||||
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir)
|
||||
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir, wait=True)
|
||||
dest_dir = os.path.expandvars(dest)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
shutil.copy(tmp, dest_dir)
|
||||
|
||||
Reference in New Issue
Block a user