mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
fix patch tool for utf-8 encode
This commit is contained in:
parent
2a90b21d35
commit
edf3f0d226
@ -44,12 +44,15 @@ for root, apply_dirs, files in os.walk('.'):
|
|||||||
target_file = os.path.join(base_path, rel_path, file)
|
target_file = os.path.join(base_path, rel_path, file)
|
||||||
print(f"Processing file: {src_file}")
|
print(f"Processing file: {src_file}")
|
||||||
if os.path.exists(target_file):
|
if os.path.exists(target_file):
|
||||||
diff_command = ["git", "diff", "--no-index", target_file, src_file]
|
diff_command = ["git", "diff",
|
||||||
|
"--no-index", target_file, src_file]
|
||||||
result = subprocess.run(diff_command, stdout=subprocess.PIPE)
|
result = subprocess.run(diff_command, stdout=subprocess.PIPE)
|
||||||
if result.stdout:
|
if result.stdout:
|
||||||
diff_output = result.stdout.decode()
|
# 确保使用UTF-8编码解码stdout
|
||||||
|
diff_output = result.stdout.decode('utf-8')
|
||||||
print(diff_output)
|
print(diff_output)
|
||||||
with open("/tmp/base/changes.patch", "a") as patch_file:
|
# 使用UTF-8编码打开文件进行写入
|
||||||
|
with open("/tmp/base/changes.patch", "a", encoding='utf-8') as patch_file:
|
||||||
patch_file.write(diff_output)
|
patch_file.write(diff_output)
|
||||||
else:
|
else:
|
||||||
print(f"No base file, skipped: {target_file}")
|
print(f"No base file, skipped: {target_file}")
|
||||||
@ -61,7 +64,7 @@ if not os.path.exists("/tmp/base/changes.patch"):
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
# read the patch
|
# read the patch
|
||||||
with open("/tmp/base/changes.patch") as patch_file:
|
with open("/tmp/base/changes.patch", encoding='utf-8') as patch_file:
|
||||||
patch_data = patch_file.read()
|
patch_data = patch_file.read()
|
||||||
|
|
||||||
# split the patch into a list of patches
|
# split the patch into a list of patches
|
||||||
@ -116,7 +119,7 @@ for patch in patches:
|
|||||||
for dir in search_dirs:
|
for dir in search_dirs:
|
||||||
file_name = os.path.basename(from_file)
|
file_name = os.path.basename(from_file)
|
||||||
# find file
|
# find file
|
||||||
#if is_found:
|
# if is_found:
|
||||||
# break
|
# break
|
||||||
|
|
||||||
for root, apply_dirs, files in os.walk(dir):
|
for root, apply_dirs, files in os.walk(dir):
|
||||||
@ -133,11 +136,12 @@ for patch in patches:
|
|||||||
print(f"Applying patch: {patch}")
|
print(f"Applying patch: {patch}")
|
||||||
# Strip the trailing whitespace for each line
|
# Strip the trailing whitespace for each line
|
||||||
lines = [line for line in patch.split('\n')]
|
lines = [line for line in patch.split('\n')]
|
||||||
with open("/tmp/base/temp.patch", 'w') as f:
|
with open("/tmp/base/temp.patch", 'w', encoding='utf-8') as f:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
f.write(line + '\n')
|
f.write(line + '\n')
|
||||||
apply_patch_command = ["git", "apply", "/tmp/base/temp.patch"]
|
apply_patch_command = ["git", "apply", "/tmp/base/temp.patch"]
|
||||||
result = subprocess.run(apply_patch_command, stdout=subprocess.PIPE, cwd=main_repo_path)
|
result = subprocess.run(
|
||||||
|
apply_patch_command, stdout=subprocess.PIPE, cwd=main_repo_path)
|
||||||
# check the result
|
# check the result
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
fail_count += 1
|
fail_count += 1
|
||||||
@ -146,7 +150,8 @@ for patch in patches:
|
|||||||
else:
|
else:
|
||||||
success_count += 1
|
success_count += 1
|
||||||
success_list.append(apply_file)
|
success_list.append(apply_file)
|
||||||
print("\033[92mSuccessfully applied patch\033[0m", apply_file)
|
print(
|
||||||
|
"\033[92mSuccessfully applied patch\033[0m", apply_file)
|
||||||
break
|
break
|
||||||
|
|
||||||
print("\n\n===========================================\n\n")
|
print("\n\n===========================================\n\n")
|
||||||
@ -162,12 +167,15 @@ if fail_count > 0:
|
|||||||
print(file)
|
print(file)
|
||||||
|
|
||||||
# setup remote url
|
# setup remote url
|
||||||
repo_url = input("Please enter your remote repository URL (default: '{}'): ".format(default_repo_url)) or default_repo_url
|
repo_url = input("Please enter your remote repository URL (default: '{}'): ".format(
|
||||||
subprocess.run(["git", "remote", "set-url", "origin", repo_url], cwd = main_repo_path)
|
default_repo_url)) or default_repo_url
|
||||||
|
subprocess.run(["git", "remote", "set-url", "origin",
|
||||||
|
repo_url], cwd=main_repo_path)
|
||||||
|
|
||||||
# setup commit message
|
# setup commit message
|
||||||
commit_msg = input("Please enter your commit message (default: 'Apply patches'): ") or "Apply patches"
|
commit_msg = input(
|
||||||
subprocess.run(["git", "commit", "-a" ,"-m", commit_msg], cwd=main_repo_path)
|
"Please enter your commit message (default: 'Apply patches'): ") or "Apply patches"
|
||||||
|
subprocess.run(["git", "commit", "-a", "-m", commit_msg], cwd=main_repo_path)
|
||||||
|
|
||||||
# confirm push
|
# confirm push
|
||||||
confirm = input("Are you sure you want to push to the repository ([Y]/N)? ")
|
confirm = input("Are you sure you want to push to the repository ([Y]/N)? ")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user