opus-nt/scripts/api/wim.py
2019-12-26 07:20:41 +01:00

42 lines
1.2 KiB
Python

global subprocess
import subprocess
global shutil
import shutil
opus.wim = Munch()
opus.wim.index = 0
opus.wim.location = ""
def _wimPath(p = ""):
if p == "": return pJoin(opus.path.wim,str(opus.wim.index))
return pJoin(opus.path.wim,str(opus.wim.index),p)
opus.wim.path = _wimPath
def _wimExtractFiles(filePaths):
fileList = []
for filePath in filePaths:
fileList.append("-i!" +pJoin(str(opus.wim.index),filePath))
opus.main.output("extracting " +str(len(filePaths))+ " files from " +opus.wim.location+ "...")
rtn = subprocess.call(
["7z","x",opus.wim.location, #wim path
"-o" +opus.path.wim, #out path
"NONE"] #in path
+fileList+ #files
["-aos","-bso0","-bsp1","-bb1"]
)
if rtn > 0: raise Exception("wim")
opus.wim.extractFiles = _wimExtractFiles
def _wimReadyFile(inPath,outPath):
if os.path.isfile(opus.wim.path(outPath)): os.remove(opus.wim.path(outPath))
shutil.copyfile(inPath,opus.wim.path(outPath))
opus.wim.readyFile = _wimReadyFile
def _wimUpdate():
opus.main.output("adding changed files to wim...")
rtn = subprocess.call(
["wimlib-imagex","update",opus.wim.location,str(opus.wim.index),
"--command=add '" +opus.wim.path("")+ "' '\\'"]
)
opus.wim.update = _wimUpdate