From d071755d844979b91f91b5adf601c0995dda23cc Mon Sep 17 00:00:00 2001 From: Fierelier Date: Fri, 27 Dec 2019 02:37:35 +0100 Subject: [PATCH] milestone 2 --- scripts/api/tweak.py | 58 ++++++++++++++++++++++++++++++++++++++++++++ scripts/main.py | 38 +++++------------------------ 2 files changed, 64 insertions(+), 32 deletions(-) diff --git a/scripts/api/tweak.py b/scripts/api/tweak.py index 6256111..fe7df81 100644 --- a/scripts/api/tweak.py +++ b/scripts/api/tweak.py @@ -1 +1,59 @@ opus.tweak = Munch() +opus.tweak.apply = Munch() +def _tweakApplyReg(tag,rtgName,rtgFile): + opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName,1) + opus.reg.mount(opus.wim.path(rtgFile)) + for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): + for tweak in tweaks: + ftweak = os.path.join(tweakRoot,tweak) + if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue + opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG")) + + opus.reg.unmount() +opus.tweak.apply.reg = _tweakApplyReg + +def _tweakApplyWim(tag): + opus.main.output("\n>> [" +tag+ "] applying tweaks: wim",1) + for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): + for tweak in tweaks: + ftweak = os.path.join(tweakRoot,tweak) + if not os.path.isdir(pJoin(ftweak,"wim")): continue + opus.main.output("> applying: " +tweak,1) + for root,dirs,files in os.walk(pJoin(ftweak,"wim")): + for dir in dirs: + fdir = os.path.join(root,dir) + nfdir = fdir.replace(pJoin(ftweak,"wim"),opus.wim.path()) + if not os.path.isdir(nfdir): + opus.main.output("creating directory: " +nfdir,2) + os.makedirs(nfdir) + + for file in files: + ffile = os.path.join(root,file) + nffile = ffile.replace(pJoin(ftweak,"wim"),opus.wim.path()) + opus.main.output("adding file: " +nffile,2) + if os.path.isdir(nffile): os.remove(nffile) + shutil.copyfile(ffile,nffile) +opus.tweak.apply.wim = _tweakApplyWim + +def _tweakApplyIso(tag): + opus.main.output("\n>> [" +tag+ "] applying tweaks: iso",1) + for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): + for tweak in tweaks: + ftweak = os.path.join(tweakRoot,tweak) + if not os.path.isdir(pJoin(ftweak,"iso")): continue + opus.main.output("> applying: " +tweak,1) + for root,dirs,files in os.walk(pJoin(ftweak,"iso")): + for dir in dirs: + fdir = os.path.join(root,dir) + nfdir = fdir.replace(pJoin(ftweak,"iso"),opus.path.target) + if not os.path.isdir(nfdir): + opus.main.output("creating directory: " +nfdir,2) + os.makedirs(nfdir) + + for file in files: + ffile = os.path.join(root,file) + nffile = ffile.replace(pJoin(ftweak,"iso"),opus.path.target) + opus.main.output("adding file: " +nffile,2) + if os.path.isdir(nffile): os.remove(nffile) + shutil.copyfile(ffile,nffile) +opus.tweak.apply.iso = _tweakApplyIso \ No newline at end of file diff --git a/scripts/main.py b/scripts/main.py index b941b5c..6e20616 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -23,7 +23,7 @@ opus.path.api = pJoin(opus.path.main,"scripts","api") opus.path.tweaks = pJoin(opus.path.main,"tweaks") opus.path.temp = pJoin(opus.path.main,"tmp") opus.path.wim = pJoin(opus.path.temp,"wim") -opus.path.target = sys.argv[1] +opus.path.target = os.path.realpath(sys.argv[1]) opus.verbosity = 2 with open(pJoin(opus.path.main,"scripts","api","main.py")) as script: @@ -79,38 +79,12 @@ opus.os = opus.detect.os(opus.wim.path()) for tag in opus.os.tags: if not os.path.isdir(pJoin(opus.path.tweaks,tag)): continue - - rtgName = "SOFTWARE" - rtgFile = pJoin("Windows","System32","config","SOFTWARE") - opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1) - opus.reg.mount(opus.wim.path(rtgFile)) - for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): - for tweak in tweaks: - ftweak = os.path.join(tweakRoot,tweak) - if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue - opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG")) - - rtgName = "SYSTEM" - rtgFile = pJoin("Windows","System32","config","SYSTEM") - opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1) - opus.reg.mount(opus.wim.path(rtgFile)) - for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): - for tweak in tweaks: - ftweak = os.path.join(tweakRoot,tweak) - if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue - opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG")) - - rtgName = "NTUSER" - rtgFile = pJoin("Users","Default","NTUSER.DAT") - opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1) - opus.reg.mount(opus.wim.path(rtgFile)) - for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)): - for tweak in tweaks: - ftweak = os.path.join(tweakRoot,tweak) - if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue - opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG")) + opus.tweak.apply.reg(tag,"SOFTWARE",pJoin("Windows","System32","config","SOFTWARE")) + opus.tweak.apply.reg(tag,"SYSTEM",pJoin("Windows","System32","config","SYSTEM")) + opus.tweak.apply.reg(tag,"NTUSER",pJoin("Users","Default","NTUSER.DAT")) + opus.tweak.apply.wim(tag) + opus.tweak.apply.iso(tag) opus.main.output("\nif you'd like to make manual changes, please do so now. press enter to finalize or ctrl+c to cancel.") input() -opus.reg.unmount() opus.wim.update() \ No newline at end of file