30 lines
822 B
Python
30 lines
822 B
Python
import os
|
|
import subprocess
|
|
|
|
import lib.sources as sources
|
|
|
|
|
|
def autopatch():
|
|
if not os.path.exists("patches"):
|
|
return
|
|
|
|
target_dir = os.getcwd() + "/target"
|
|
source_dir = sources.sources_dir_name()
|
|
patches_tag_file = f"{target_dir}/patches.tag"
|
|
|
|
patches_dir = os.getcwd() + "/patches"
|
|
patches = os.listdir(patches_dir)
|
|
patches.sort()
|
|
|
|
os.chdir(source_dir)
|
|
if not os.path.exists(patches_tag_file):
|
|
open(patches_tag_file, "+w").close()
|
|
for i in patches:
|
|
with open(patches_tag_file, "r") as file:
|
|
if i + "\n" in file.readlines():
|
|
continue
|
|
with open(f"{patches_dir}/{i}", "r") as file:
|
|
subprocess.run(["patch", "-p1"], stdin=file)
|
|
with open(patches_tag_file, "+a") as file:
|
|
file.write(i + "\n")
|