mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-08 15:58:32 +01:00
feat: implement bulk execution in python
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# windows imports #
|
# windows imports #
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
@@ -52,6 +53,15 @@ def resolve_lnk(lnk_file_path):
|
|||||||
def run_exe(path, synchronous=False):
|
def run_exe(path, synchronous=False):
|
||||||
'''Launches a given software'''
|
'''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 os.name != "nt":
|
||||||
if ".lnk" in path:
|
if ".lnk" in path:
|
||||||
subprocess.Popen(["wine64", "start", path])
|
subprocess.Popen(["wine64", "start", path])
|
||||||
@@ -62,16 +72,18 @@ def run_exe(path, synchronous=False):
|
|||||||
if synchronous:
|
if synchronous:
|
||||||
raise NotImplementedError("SYNC not yet implemented")
|
raise NotImplementedError("SYNC not yet implemented")
|
||||||
|
|
||||||
if path.endswith(".lnk"):
|
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||||
path = resolve_lnk(path)
|
|
||||||
|
|
||||||
print("Executing:", path)
|
print("Executing:", paths)
|
||||||
|
|
||||||
try:
|
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:
|
except OSError as e:
|
||||||
if "WinError 740" in str(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)
|
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
print(p.communicate())
|
print(p.communicate())
|
||||||
else:
|
else:
|
||||||
|
|||||||
16
software.py
16
software.py
@@ -53,6 +53,7 @@ class Software:
|
|||||||
self.extra_files = meta.get("extra_files")
|
self.extra_files = meta.get("extra_files")
|
||||||
self.run_exe = meta.get("run_exe")
|
self.run_exe = meta.get("run_exe")
|
||||||
self.installer = meta.get("installer")
|
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.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
||||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||||
@@ -104,6 +105,9 @@ class Software:
|
|||||||
def install(self):
|
def install(self):
|
||||||
'''Install this software from the backend'''
|
'''Install this software from the backend'''
|
||||||
|
|
||||||
|
# things to execute #
|
||||||
|
admin_run_list = []
|
||||||
|
|
||||||
print("Installing:", self.title, self.directory)
|
print("Installing:", self.title, self.directory)
|
||||||
|
|
||||||
# handle link-only software #
|
# handle link-only software #
|
||||||
@@ -139,7 +143,8 @@ class Software:
|
|||||||
print("Install dir Registry:", target_install_dir)
|
print("Install dir Registry:", target_install_dir)
|
||||||
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
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 #
|
# install dependencies #
|
||||||
if self.dependencies:
|
if self.dependencies:
|
||||||
@@ -157,12 +162,19 @@ class Software:
|
|||||||
|
|
||||||
|
|
||||||
print("Running installer:", installer_path)
|
print("Running installer:", installer_path)
|
||||||
|
if not self.installer_no_admin:
|
||||||
|
admin_run_list.append(installer_path)
|
||||||
|
else:
|
||||||
localaction.run_exe(installer_path)
|
localaction.run_exe(installer_path)
|
||||||
|
|
||||||
|
if admin_run_list:
|
||||||
|
print("admin list", admin_run_list)
|
||||||
|
localaction.run_exe(admin_run_list)
|
||||||
|
|
||||||
# install gamefiles #
|
# install gamefiles #
|
||||||
if self.extra_files:
|
if self.extra_files:
|
||||||
for src, dest in self.extra_files.items():
|
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)
|
dest_dir = os.path.expandvars(dest)
|
||||||
os.makedirs(dest_dir, exist_ok=True)
|
os.makedirs(dest_dir, exist_ok=True)
|
||||||
shutil.copy(tmp, dest_dir)
|
shutil.copy(tmp, dest_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user