opus-nt/scripts/api/wim.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-12-26 06:20:41 +00:00
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+ "...")
2019-12-27 04:36:43 +00:00
for filePath in filePaths:
rtn = subprocess.call(
["wimlib-imagex","extract",
opus.wim.location,str(opus.wim.index),
filePath,
"--dest-dir=" +opus.wim.path(""),"--preserve-dir-structure"]
)
2019-12-26 06:20:41 +00:00
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