Advertisement
Dyrcona

patches4movius.py

Sep 2nd, 2022
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from string import Template
  4. from sys import argv
  5.  
  6. PATCHROOT = "~/CWMARS/files/patches/rel_3_7_3/"
  7.  
  8. t1 = Template("""patch -p1 < ${patchfile}""");
  9.  
  10. t2 = Template("""[ ! -d ${destdir} ] && mkdir -p ${destdir}
  11. patch -p1 -o ${destfile} < ${patchfile}""");
  12.  
  13. with open(argv[1], "r") as f:
  14.     while True:
  15.         line = f.readline()
  16.         if not line:
  17.             break
  18.         input = line.strip()
  19.         patchpath = PATCHROOT + input
  20.         destfile = input.removesuffix(".patch")
  21.         destdir = None
  22.         if "bootstrap" in destfile:
  23.             destfile = destfile.replace("bootstrap", "bootstrap_cons")
  24.             destdir = destfile[0:destfile.rfind("/")]
  25.         elif "templates" in destfile:
  26.             destfile = destfile.replace("templates", "templates_cons")
  27.             destdir = destfile[0:destfile.rfind("/")]
  28.         if destdir == None:
  29.             print(t1.substitute(patchfile=patchpath))
  30.         else:
  31.             print(t2.substitute(patchfile=patchpath,destdir=destdir,destfile=destfile))
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement